All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nitorcreations.willow.metrics.HeapMemoryMetric Maven / Gradle / Ivy

The newest version!
package com.nitorcreations.willow.metrics;

import static com.nitorcreations.willow.metrics.MetricUtils.median;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.inject.Named;

import com.nitorcreations.willow.messages.JmxMessage;
import com.nitorcreations.willow.messages.metrics.MetricConfig;


@Named("/heap")
public class HeapMemoryMetric extends FullMessageMultiseriesMetric {
  private static final String categoryPrefix = "category_jmx_";

  @Override
  protected void addValue(Map> values, List preceeding, long stepTime, int stepLen, MetricConfig conf) {
    HashMap> data = new HashMap<>();
    for (JmxMessage next : preceeding) {
      String childName = "";
      for (String nextTag : next.tags) {
        if (nextTag.startsWith(categoryPrefix)) {
          childName = nextTag.substring(categoryPrefix.length());
          break;
        }
      }
      List nextData = data.get(childName);
      if (nextData == null) {
        nextData = new ArrayList();
        data.put(childName, nextData);
      }
      nextData.add(next.getHeapMemory());
    }
    for (Entry> next : data.entrySet()) {
      SeriesData result = values.get(next.getKey());
      if (result == null) {
        result = new SeriesData<>();
        result.key = next.getKey();
        values.put(next.getKey(), result);
      }
      Point nextPoint = new Point<>();
      nextPoint.x = stepTime;
      nextPoint.y = median(next.getValue());
      result.values.add(nextPoint);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy