Java Code Examples for io.prometheus.client.SummaryMetricFamily#addMetric()

The following examples show how to use io.prometheus.client.SummaryMetricFamily#addMetric() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JVMResourceCollector.java    From feast with Apache License 2.0 6 votes vote down vote up
@Override
public List<MetricFamilySamples> collect() {
  List<MetricFamilySamples> samples = new ArrayList<>();

  samples.add(
      new GaugeMetricFamily(
          "feast_core_max_memory_bytes",
          "Max amount of memory the Java virtual machine will attempt to use",
          runtime.maxMemory()));
  samples.add(
      new GaugeMetricFamily(
          "feast_core_total_memory_bytes",
          "Total amount of memory in the Java virtual machine",
          runtime.totalMemory()));
  samples.add(
      new GaugeMetricFamily(
          "feast_core_free_memory_bytes",
          "Total amount of free memory in the Java virtual machine",
          runtime.freeMemory()));

  SummaryMetricFamily gcMetricFamily =
      new SummaryMetricFamily(
          "feast_core_gc_collection_seconds",
          "Time spent in a given JVM garbage collector in seconds",
          Collections.singletonList("gc"));
  for (final GarbageCollectorMXBean gc : garbageCollectors) {
    gcMetricFamily.addMetric(
        Collections.singletonList(gc.getName()),
        gc.getCollectionCount(),
        gc.getCollectionTime() / MILLISECONDS_PER_SECOND);
  }
  samples.add(gcMetricFamily);

  return samples;
}
 
Example 2
Source File: GarbageCollectorExports.java    From client_java with Apache License 2.0 5 votes vote down vote up
public List<MetricFamilySamples> collect() {
  SummaryMetricFamily gcCollection = new SummaryMetricFamily(
      "jvm_gc_collection_seconds",
      "Time spent in a given JVM garbage collector in seconds.",
      Collections.singletonList("gc"));
  for (final GarbageCollectorMXBean gc : garbageCollectors) {
      gcCollection.addMetric(
          Collections.singletonList(gc.getName()),
          gc.getCollectionCount(),
          gc.getCollectionTime() / MILLISECONDS_PER_SECOND);
  }
  List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
  mfs.add(gcCollection);
  return mfs;
}
 
Example 3
Source File: CacheMetricsCollector.java    From client_java with Apache License 2.0 4 votes vote down vote up
@Override
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
    List<String> labelNames = Arrays.asList("cache");

    CounterMetricFamily cacheHitTotal = new CounterMetricFamily("guava_cache_hit_total",
            "Cache hit totals", labelNames);
    mfs.add(cacheHitTotal);

    CounterMetricFamily cacheMissTotal = new CounterMetricFamily("guava_cache_miss_total",
            "Cache miss totals", labelNames);
    mfs.add(cacheMissTotal);

    CounterMetricFamily cacheRequestsTotal = new CounterMetricFamily("guava_cache_requests_total",
            "Cache request totals, hits + misses", labelNames);
    mfs.add(cacheRequestsTotal);

    CounterMetricFamily cacheEvictionTotal = new CounterMetricFamily("guava_cache_eviction_total",
            "Cache eviction totals, doesn't include manually removed entries", labelNames);
    mfs.add(cacheEvictionTotal);

    CounterMetricFamily cacheLoadFailure = new CounterMetricFamily("guava_cache_load_failure_total",
            "Cache load failures", labelNames);
    mfs.add(cacheLoadFailure);

    CounterMetricFamily cacheLoadTotal = new CounterMetricFamily("guava_cache_loads_total",
            "Cache loads: both success and failures", labelNames);
    mfs.add(cacheLoadTotal);

    GaugeMetricFamily cacheSize = new GaugeMetricFamily("guava_cache_size",
            "Cache size", labelNames);
    mfs.add(cacheSize);

    SummaryMetricFamily cacheLoadSummary = new SummaryMetricFamily("guava_cache_load_duration_seconds",
            "Cache load duration: both success and failures", labelNames);
    mfs.add(cacheLoadSummary);

    for(Map.Entry<String, Cache> c: children.entrySet()) {
        List<String> cacheName = Arrays.asList(c.getKey());
        CacheStats stats = c.getValue().stats();

        cacheHitTotal.addMetric(cacheName, stats.hitCount());
        cacheMissTotal.addMetric(cacheName, stats.missCount());
        cacheRequestsTotal.addMetric(cacheName, stats.requestCount());
        cacheEvictionTotal.addMetric(cacheName, stats.evictionCount());
        cacheSize.addMetric(cacheName, c.getValue().size());

        if(c.getValue() instanceof LoadingCache) {
            cacheLoadFailure.addMetric(cacheName, stats.loadExceptionCount());
            cacheLoadTotal.addMetric(cacheName, stats.loadCount());

            cacheLoadSummary.addMetric(cacheName, stats.loadCount(), stats.totalLoadTime() / Collector.NANOSECONDS_PER_SECOND);
        }
    }
    return mfs;
}
 
Example 4
Source File: CacheMetricsCollector.java    From client_java with Apache License 2.0 4 votes vote down vote up
@Override
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
    List<String> labelNames = Arrays.asList("cache");

    CounterMetricFamily cacheHitTotal = new CounterMetricFamily("caffeine_cache_hit_total",
            "Cache hit totals", labelNames);
    mfs.add(cacheHitTotal);

    CounterMetricFamily cacheMissTotal = new CounterMetricFamily("caffeine_cache_miss_total",
            "Cache miss totals", labelNames);
    mfs.add(cacheMissTotal);

    CounterMetricFamily cacheRequestsTotal = new CounterMetricFamily("caffeine_cache_requests_total",
            "Cache request totals, hits + misses", labelNames);
    mfs.add(cacheRequestsTotal);

    CounterMetricFamily cacheEvictionTotal = new CounterMetricFamily("caffeine_cache_eviction_total",
            "Cache eviction totals, doesn't include manually removed entries", labelNames);
    mfs.add(cacheEvictionTotal);

    GaugeMetricFamily cacheEvictionWeight = new GaugeMetricFamily("caffeine_cache_eviction_weight",
            "Cache eviction weight", labelNames);
    mfs.add(cacheEvictionWeight);

    CounterMetricFamily cacheLoadFailure = new CounterMetricFamily("caffeine_cache_load_failure_total",
            "Cache load failures", labelNames);
    mfs.add(cacheLoadFailure);

    CounterMetricFamily cacheLoadTotal = new CounterMetricFamily("caffeine_cache_loads_total",
            "Cache loads: both success and failures", labelNames);
    mfs.add(cacheLoadTotal);

    GaugeMetricFamily cacheSize = new GaugeMetricFamily("caffeine_cache_estimated_size",
            "Estimated cache size", labelNames);
    mfs.add(cacheSize);

    SummaryMetricFamily cacheLoadSummary = new SummaryMetricFamily("caffeine_cache_load_duration_seconds",
            "Cache load duration: both success and failures", labelNames);
    mfs.add(cacheLoadSummary);

    for(Map.Entry<String, Cache> c: children.entrySet()) {
        List<String> cacheName = Arrays.asList(c.getKey());
        CacheStats stats = c.getValue().stats();

        try{
            cacheEvictionWeight.addMetric(cacheName, stats.evictionWeight());
        } catch (Exception e) {
            // EvictionWeight metric is unavailable, newer version of Caffeine is needed.
        }

        cacheHitTotal.addMetric(cacheName, stats.hitCount());
        cacheMissTotal.addMetric(cacheName, stats.missCount());
        cacheRequestsTotal.addMetric(cacheName, stats.requestCount());
        cacheEvictionTotal.addMetric(cacheName, stats.evictionCount());
        cacheSize.addMetric(cacheName, c.getValue().estimatedSize());

        if(c.getValue() instanceof LoadingCache) {
            cacheLoadFailure.addMetric(cacheName, stats.loadFailureCount());
            cacheLoadTotal.addMetric(cacheName, stats.loadCount());

            cacheLoadSummary.addMetric(cacheName, stats.loadCount(), stats.totalLoadTime() / Collector.NANOSECONDS_PER_SECOND);
        }
    }
    return mfs;
}