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;
}
}));
}
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);
}
});
}
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));
}
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;
}
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;
}
Aggregations