use of com.sun.messaging.jmq.util.MetricCounters in project openmq by eclipse-ee4j.
the class MetricManager method depositTotals.
/**
* Used by connections that are going away to deposit their totals, so they won't be lost.
*/
public synchronized void depositTotals(String service, MetricCounters counters) {
MetricCounters mc = (MetricCounters) deadTotalsByService.get(service);
if (mc == null) {
mc = new MetricCounters();
deadTotalsByService.put(service, mc);
}
mc.update(counters);
}
use of com.sun.messaging.jmq.util.MetricCounters in project openmq by eclipse-ee4j.
the class MetricManager method getMetricCounters.
/**
* Get the metric counters for the specified service. If serviceName is null then do it for all services
*/
public synchronized MetricCounters getMetricCounters(String serviceName) {
ConnectionManager cm = Globals.getConnectionManager();
MetricCounters totals = new MetricCounters();
// Add counters for connections that no longer exist
if (serviceName == null) {
// Sum values for all services
Enumeration e;
for (e = deadTotalsByService.elements(); e.hasMoreElements(); ) {
totals.update((MetricCounters) e.nextElement());
}
} else {
// Sum values for just the specified service
MetricCounters deadTotals = (MetricCounters) deadTotalsByService.get(serviceName);
if (deadTotals != null) {
totals.update((MetricCounters) deadTotalsByService.get(serviceName));
}
}
// Sum totals for all active connections for this service
// We synchronize since connections may be comming and going
int n = 0;
synchronized (cm) {
Collection connections = cm.values();
Iterator itr = connections.iterator();
while (itr.hasNext()) {
Connection con = (Connection) itr.next();
Service svc = con.getService();
// See if connection belongs to the service
if (serviceName == null || serviceName.equals(svc.getName())) {
if (con instanceof IMQConnection) {
totals.update(((IMQConnection) con).getMetricCounters());
} else {
// XXX handle other counters
}
n++;
}
}
}
// Get thread information
ServiceManager sm = Globals.getServiceManager();
Service svc = null;
Iterator iter = null;
if (serviceName == null) {
Set s = sm.getAllActiveServices();
if (s != null) {
iter = s.iterator();
}
} else {
Vector v = new Vector(1);
v.add(serviceName);
iter = v.iterator();
}
while (iter != null && iter.hasNext()) {
svc = sm.getService((String) iter.next());
if (svc instanceof IMQService) {
totals.threadsActive += ((IMQService) svc).getActiveThreadpool();
totals.threadsHighWater += ((IMQService) svc).getMaxThreadpool();
totals.threadsLowWater += ((IMQService) svc).getMinThreadpool();
}
}
Runtime rt = Runtime.getRuntime();
totals.totalMemory = rt.totalMemory();
totals.freeMemory = rt.freeMemory();
totals.nConnections = n;
totals.timeStamp = System.currentTimeMillis();
return totals;
}
use of com.sun.messaging.jmq.util.MetricCounters in project openmq by eclipse-ee4j.
the class MetricManager method getMetrics.
/**
* Gather performance data for all connections in a broker, compute dervied numbers, and return in one convenience class
*/
public synchronized MetricData getMetrics() {
MetricData md = new MetricData();
Runtime rt = Runtime.getRuntime();
long currentTime = System.currentTimeMillis();
// long elapsedSecs = (currentTime - lastSampleTime) / 1000;
float elapsedSecs = (currentTime - lastSampleTime) / (float) 1000;
MetricCounters totals = getMetricCounters(null);
// Copy values into MetricData
md.timestamp = currentTime;
md.totalMemory = rt.totalMemory();
md.freeMemory = rt.freeMemory();
md.nConnections = totals.nConnections;
// Totals are straight copies
md.setTotals(totals);
// Rates must be computed
md.rates.messagesIn = (long) ((totals.messagesIn - lastSample.messagesIn) / elapsedSecs);
md.rates.messageBytesIn = (long) ((totals.messageBytesIn - lastSample.messageBytesIn) / elapsedSecs);
md.rates.packetsIn = (long) ((totals.packetsIn - lastSample.packetsIn) / elapsedSecs);
md.rates.packetBytesIn = (long) ((totals.packetBytesIn - lastSample.packetBytesIn) / elapsedSecs);
md.rates.messagesOut = (long) ((totals.messagesOut - lastSample.messagesOut) / elapsedSecs);
md.rates.messageBytesOut = (long) ((totals.messageBytesOut - lastSample.messageBytesOut) / elapsedSecs);
md.rates.packetsOut = (long) ((totals.packetsOut - lastSample.packetsOut) / elapsedSecs);
md.rates.packetBytesOut = (long) ((totals.packetBytesOut - lastSample.packetBytesOut) / elapsedSecs);
lastSampleTime = currentTime;
lastSample = totals;
return md;
}
use of com.sun.messaging.jmq.util.MetricCounters in project openmq by eclipse-ee4j.
the class ServiceManagerMonitor method getMetricsForAllServices.
private MetricCounters getMetricsForAllServices() {
MetricManager mm = Globals.getMetricManager();
MetricCounters mc = null;
mc = mm.getMetricCounters(null);
return (mc);
}
use of com.sun.messaging.jmq.util.MetricCounters in project openmq by eclipse-ee4j.
the class ServiceMonitor method getPktBytesOut.
public Long getPktBytesOut() {
ServiceInfo si = ServiceUtil.getServiceInfo(service);
MetricCounters metrics = si.metrics;
if (metrics != null) {
return (Long.valueOf(metrics.packetBytesOut));
} else {
return (Long.valueOf(-1));
}
}
Aggregations