Search in sources :

Example 41 with Gauge

use of com.codahale.metrics.Gauge in project jstorm by alibaba.

the class SupervisorManger method registerSupervisorMetrics.

private void registerSupervisorMetrics() {
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.CPU_USED_RATIO, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        @Override
        public Double getValue() {
            return JStormUtils.getTotalCpuUsage();
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.DISK_USAGE, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        @Override
        public Double getValue() {
            return JStormUtils.getDiskUsage();
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.MEMORY_USAGE, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        @Override
        public Double getValue() {
            return JStormUtils.getTotalMemUsage();
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.NETRECVSPEED, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        Long lastRecvCount = LinuxResource.getNetRevSendCount().getFirst();

        Long lastCalTime = System.currentTimeMillis();

        @Override
        public Double getValue() {
            Long nowRecvCount = LinuxResource.getNetRevSendCount().getFirst();
            Long nowCalTime = System.currentTimeMillis();
            long deltaValue = nowRecvCount - lastRecvCount;
            long deltaTime = nowCalTime - lastCalTime;
            lastRecvCount = nowRecvCount;
            lastCalTime = nowCalTime;
            double ret = 0.0;
            if (deltaTime > 0) {
                ret = deltaValue / (double) deltaTime * 1000d;
            }
            return ret;
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.NETSENDSPEED, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        Long lastSendCount = LinuxResource.getNetRevSendCount().getSecond();

        Long lastCalTime = System.currentTimeMillis();

        @Override
        public Double getValue() {
            Long nowSendCount = LinuxResource.getNetRevSendCount().getSecond();
            Long nowCalTime = System.currentTimeMillis();
            long deltaValue = nowSendCount - lastSendCount;
            long deltaTime = nowCalTime - lastCalTime;
            lastSendCount = nowSendCount;
            lastCalTime = nowCalTime;
            double ret = 0.0;
            if (deltaTime > 0) {
                ret = deltaValue / (double) deltaTime * 1000d;
            }
            return ret;
        }
    }));
}
Also used : AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) Gauge(com.codahale.metrics.Gauge)

Example 42 with Gauge

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

the class KafkaJournal method setupKafkaLogMetrics.

private void setupKafkaLogMetrics(final MetricRegistry metricRegistry) {
    metricRegistry.register(name(KafkaJournal.class, "size"), (Gauge<Long>) kafkaLog::size);
    metricRegistry.register(name(KafkaJournal.class, "logEndOffset"), (Gauge<Long>) kafkaLog::logEndOffset);
    metricRegistry.register(name(KafkaJournal.class, "numberOfSegments"), (Gauge<Integer>) kafkaLog::numberOfSegments);
    metricRegistry.register(name(KafkaJournal.class, "unflushedMessages"), (Gauge<Long>) kafkaLog::unflushedMessages);
    metricRegistry.register(name(KafkaJournal.class, "recoveryPoint"), (Gauge<Long>) kafkaLog::recoveryPoint);
    metricRegistry.register(name(KafkaJournal.class, "lastFlushTime"), (Gauge<Long>) kafkaLog::lastFlushTime);
    // must not be a lambda, because the serialization cannot determine the proper Metric type :(
    metricRegistry.register(GlobalMetricNames.JOURNAL_OLDEST_SEGMENT, (Gauge<Date>) new Gauge<Date>() {

        @Override
        public Date getValue() {
            long oldestSegment = Long.MAX_VALUE;
            for (final LogSegment segment : KafkaJournal.this.getSegments()) {
                oldestSegment = Math.min(oldestSegment, segment.created());
            }
            return new Date(oldestSegment);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LogSegment(kafka.log.LogSegment) AtomicLong(java.util.concurrent.atomic.AtomicLong) Date(java.util.Date) Gauge(com.codahale.metrics.Gauge)

Example 43 with Gauge

use of com.codahale.metrics.Gauge in project spring-boot by spring-projects.

the class MetricRegistryMetricReader method findOne.

@Override
public Metric<?> findOne(String metricName) {
    String name = this.names.get(metricName);
    if (name == null) {
        return null;
    }
    com.codahale.metrics.Metric metric = this.registry.getMetrics().get(name);
    if (metric == null) {
        return null;
    }
    if (metric instanceof Counter) {
        Counter counter = (Counter) metric;
        return new Metric<Number>(metricName, counter.getCount());
    }
    if (metric instanceof Gauge) {
        Object value = ((Gauge<?>) metric).getValue();
        if (value instanceof Number) {
            return new Metric<>(metricName, (Number) value);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Ignoring gauge '" + name + "' (" + metric + ") as its value is not a Number");
        }
        return null;
    }
    if (metric instanceof Sampling) {
        if (metricName.contains(".snapshot.")) {
            Number value = getMetric(((Sampling) metric).getSnapshot(), metricName);
            if (metric instanceof Timer) {
                // convert back to MILLISEC
                value = TimeUnit.MILLISECONDS.convert(value.longValue(), TimeUnit.NANOSECONDS);
            }
            return new Metric<>(metricName, value);
        }
    }
    return new Metric<>(metricName, getMetric(metric, metricName));
}
Also used : Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Metric(org.springframework.boot.actuate.metrics.Metric) Sampling(com.codahale.metrics.Sampling) Gauge(com.codahale.metrics.Gauge)

Example 44 with Gauge

use of com.codahale.metrics.Gauge in project pinpoint by naver.

the class MetricMonitorValues method getLongGauge.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Gauge<Long> getLongGauge(final Map<String, Gauge> gauges, String key) {
    if (gauges == null) {
        throw new NullPointerException("gauges must not be null");
    }
    if (key == null) {
        throw new NullPointerException("key must not be null");
    }
    final Gauge gauge = gauges.get(key);
    if (gauge == null) {
        LOGGER.warn("key:{} not found", key);
        return LONG_ZERO;
    }
    // Is there better way to check type of value?
    Object value = gauge.getValue();
    if (value instanceof Long) {
        return gauge;
    }
    LOGGER.warn("invalid gauge type. key:{} gauge:{}", key, gauge);
    return LONG_ZERO;
}
Also used : Gauge(com.codahale.metrics.Gauge)

Example 45 with Gauge

use of com.codahale.metrics.Gauge in project pinpoint by naver.

the class MetricMonitorValues method getDoubleGauge.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Gauge<Double> getDoubleGauge(final Map<String, Gauge> gauges, String key) {
    if (gauges == null) {
        throw new NullPointerException("gauges must not be null");
    }
    if (key == null) {
        throw new NullPointerException("key must not be null");
    }
    final Gauge gauge = gauges.get(key);
    if (gauge == null) {
        LOGGER.warn("key:{} not found", key);
        return DOUBLE_ZERO;
    }
    // Is there better way to check type of value?
    Object value = gauge.getValue();
    if (value instanceof Double) {
        return gauge;
    }
    LOGGER.warn("invalid gauge type. key:{} gauge:{}", key, gauge);
    return DOUBLE_ZERO;
}
Also used : Gauge(com.codahale.metrics.Gauge)

Aggregations

Gauge (com.codahale.metrics.Gauge)64 Test (org.junit.Test)43 Counter (com.codahale.metrics.Counter)10 MetricRegistry (com.codahale.metrics.MetricRegistry)9 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 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 ValueList (org.collectd.api.ValueList)2 Assertion (org.opensaml.saml.saml2.core.Assertion)2