Пример #1
0
 /** Creates a new instance of JvmMetrics */
 private JvmMetrics(String processName, String sessionId, String recordName) {
   MetricsContext context = MetricsUtil.getContext("jvm");
   metrics = MetricsUtil.createRecord(context, recordName);
   metrics.setTag("processName", processName);
   metrics.setTag("sessionId", sessionId);
   context.registerUpdater(this);
 }
Пример #2
0
 private void doThreadUpdates() {
   ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
   long threadIds[] = threadMXBean.getAllThreadIds();
   ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, 0);
   int threadsNew = 0;
   int threadsRunnable = 0;
   int threadsBlocked = 0;
   int threadsWaiting = 0;
   int threadsTimedWaiting = 0;
   int threadsTerminated = 0;
   for (ThreadInfo threadInfo : threadInfos) {
     // threadInfo is null if the thread is not alive or doesn't exist
     if (threadInfo == null) continue;
     Thread.State state = threadInfo.getThreadState();
     if (state == NEW) {
       threadsNew++;
     } else if (state == RUNNABLE) {
       threadsRunnable++;
     } else if (state == BLOCKED) {
       threadsBlocked++;
     } else if (state == WAITING) {
       threadsWaiting++;
     } else if (state == TIMED_WAITING) {
       threadsTimedWaiting++;
     } else if (state == TERMINATED) {
       threadsTerminated++;
     }
   }
   metrics.setMetric("threadsNew", threadsNew);
   metrics.setMetric("threadsRunnable", threadsRunnable);
   metrics.setMetric("threadsBlocked", threadsBlocked);
   metrics.setMetric("threadsWaiting", threadsWaiting);
   metrics.setMetric("threadsTimedWaiting", threadsTimedWaiting);
   metrics.setMetric("threadsTerminated", threadsTerminated);
 }
Пример #3
0
 private void doMemoryUpdates() {
   MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
   MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
   MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
   metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed() / M);
   metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted() / M);
   metrics.setMetric("memHeapUsedM", memHeap.getUsed() / M);
   metrics.setMetric("memHeapCommittedM", memHeap.getCommitted() / M);
 }
Пример #4
0
 private void doGarbageCollectionUpdates() {
   List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
   long count = 0;
   long timeMillis = 0;
   for (GarbageCollectorMXBean gcBean : gcBeans) {
     count += gcBean.getCollectionCount();
     timeMillis += gcBean.getCollectionTime();
   }
   metrics.incrMetric("gcCount", (int) (count - gcCount));
   metrics.incrMetric("gcTimeMillis", (int) (timeMillis - gcTimeMillis));
   gcCount = count;
   gcTimeMillis = timeMillis;
 }
Пример #5
0
 private void doEventCountUpdates() {
   long newFatal = EventCounter.getFatal();
   long newError = EventCounter.getError();
   long newWarn = EventCounter.getWarn();
   long newInfo = EventCounter.getInfo();
   metrics.incrMetric("logFatal", (int) (newFatal - fatalCount));
   metrics.incrMetric("logError", (int) (newError - errorCount));
   metrics.incrMetric("logWarn", (int) (newWarn - warnCount));
   metrics.incrMetric("logInfo", (int) (newInfo - infoCount));
   fatalCount = newFatal;
   errorCount = newError;
   warnCount = newWarn;
   infoCount = newInfo;
 }
Пример #6
0
 /** This will be called periodically (with the period being configuration dependent). */
 public void doUpdates(MetricsContext context) {
   doMemoryUpdates();
   doGarbageCollectionUpdates();
   doThreadUpdates();
   doEventCountUpdates();
   metrics.update();
 }