Search in sources :

Example 26 with Gauge

use of com.codahale.metrics.Gauge in project graylog2-server by Graylog2.

the class ThroughputCounter method gauges.

public Map<String, Gauge<Long>> gauges() {
    Map<String, Gauge<Long>> gauges = Maps.newHashMap();
    final TrafficCounter tc = this.getTrafficCounter();
    gauges.put("read_bytes_1sec", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return tc.getLastReadBytes();
        }
    });
    gauges.put("written_bytes_1sec", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return tc.getLastWrittenBytes();
        }
    });
    gauges.put("read_bytes_total", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return tc.getCumulativeReadBytes();
        }
    });
    gauges.put("written_bytes_total", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return tc.getCumulativeWrittenBytes();
        }
    });
    return gauges;
}
Also used : TrafficCounter(org.jboss.netty.handler.traffic.TrafficCounter) Gauge(com.codahale.metrics.Gauge)

Example 27 with Gauge

use of com.codahale.metrics.Gauge in project graylog2-server by Graylog2.

the class ThroughputResource method total.

@GET
@Timed
@RequiresPermissions(RestPermissions.THROUGHPUT_READ)
@ApiOperation(value = "Current throughput of this node in messages per second")
@Produces(MediaType.APPLICATION_JSON)
public Throughput total() {
    final SortedMap<String, Gauge> gauges = metricRegistry.getGauges(MetricUtils.filterSingleMetric(GlobalMetricNames.OUTPUT_THROUGHPUT_RATE));
    final Gauge gauge = Iterables.getOnlyElement(gauges.values(), null);
    if (gauge == null || !(gauge.getValue() instanceof Number)) {
        return Throughput.create(0);
    } else {
        return Throughput.create(((Number) gauge.getValue()).longValue());
    }
}
Also used : Gauge(com.codahale.metrics.Gauge) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with Gauge

use of com.codahale.metrics.Gauge in project graylog2-server by Graylog2.

the class MetricUtilsTest method safelyRegister.

@Test
public void safelyRegister() {
    final MetricRegistry metricRegistry = new MetricRegistry();
    final Gauge<Long> longGauge = new Gauge<Long>() {

        @Override
        public Long getValue() {
            return 0L;
        }
    };
    final Gauge<Long> newGauge = MetricUtils.safelyRegister(metricRegistry, "somename", longGauge);
    assertSame("metric objects are identical", longGauge, newGauge);
    try {
        MetricUtils.safelyRegister(metricRegistry, "somename", longGauge);
    } catch (Exception e) {
        fail("Should not have thrown: " + e.getMessage());
    }
    try {
        //noinspection unused
        final Counter somename = MetricUtils.safelyRegister(metricRegistry, "somename", new Counter());
    } catch (Exception e) {
        assertTrue("Registering a metric with a different metric type fails on using it", e instanceof ClassCastException);
    }
}
Also used : Counter(com.codahale.metrics.Counter) MetricRegistry(com.codahale.metrics.MetricRegistry) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 29 with Gauge

use of com.codahale.metrics.Gauge in project beam by apache.

the class WithMetricsSupport method aggregatorMetricToGauges.

private Function<Map.Entry<String, Metric>, Map<String, Gauge>> aggregatorMetricToGauges() {
    return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() {

        @Override
        public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) {
            final NamedAggregators agg = ((AggregatorMetric) entry.getValue()).getNamedAggregators();
            final String parentName = entry.getKey();
            final Map<String, Gauge> gaugeMap = Maps.transformEntries(agg.renderAll(), toGauge());
            final Map<String, Gauge> fullNameGaugeMap = Maps.newLinkedHashMap();
            for (Map.Entry<String, Gauge> gaugeEntry : gaugeMap.entrySet()) {
                fullNameGaugeMap.put(parentName + "." + gaugeEntry.getKey(), gaugeEntry.getValue());
            }
            return Maps.filterValues(fullNameGaugeMap, Predicates.notNull());
        }
    };
}
Also used : Function(com.google.common.base.Function) Metric(com.codahale.metrics.Metric) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) NamedAggregators(org.apache.beam.runners.spark.aggregators.NamedAggregators) Gauge(com.codahale.metrics.Gauge)

Example 30 with Gauge

use of com.codahale.metrics.Gauge in project lucene-solr by apache.

the class RequestHandlersTest method testInitCount.

@Test
public void testInitCount() {
    String registry = h.getCore().getCoreMetricManager().getRegistryName();
    SolrMetricManager manager = h.getCoreContainer().getMetricManager();
    Gauge<Number> g = (Gauge<Number>) manager.registry(registry).getMetrics().get("QUERY.mock.initCount");
    assertEquals("Incorrect init count", 1, g.getValue().intValue());
}
Also used : SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Aggregations

Gauge (com.codahale.metrics.Gauge)57 Test (org.junit.Test)38 Counter (com.codahale.metrics.Counter)10 Meter (com.codahale.metrics.Meter)8 Metric (com.codahale.metrics.Metric)8 Timer (com.codahale.metrics.Timer)7 SortedMap (java.util.SortedMap)7 Histogram (com.codahale.metrics.Histogram)6 MetricRegistry (com.codahale.metrics.MetricRegistry)6 Map (java.util.Map)6 Matchers.anyString (org.mockito.Matchers.anyString)3 Snapshot (com.codahale.metrics.Snapshot)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 Semaphore (java.util.concurrent.Semaphore)2 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)2 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)2 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 MetricSet (com.codahale.metrics.MetricSet)1