blob: fd98ffe848f7659fc0f496446f7e6e520c7b3bc1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.metrics.simple.jdisc;
import java.util.HashMap;
import java.util.Map;
import com.yahoo.jdisc.Metric.Context;
import com.yahoo.jdisc.application.MetricConsumer;
import com.yahoo.metrics.simple.Identifier;
import com.yahoo.metrics.simple.Measurement;
import com.yahoo.metrics.simple.Point;
import com.yahoo.metrics.simple.MetricReceiver;
import com.yahoo.metrics.simple.Sample;
import com.yahoo.metrics.simple.UntypedMetric.AssumedType;
/**
* The single user facing part of the JDisc interfaces of simple metrics.
*
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
*/
public class SimpleMetricConsumer implements MetricConsumer {
private final MetricReceiver receiver;
public SimpleMetricConsumer(MetricReceiver receiver) {
this.receiver = receiver;
}
@Override
public void set(String key, Number val, Context ctx) {
receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.GAUGE));
}
@Override
public void add(String key, Number val, Context ctx) {
receiver.update(new Sample(new Measurement(val), new Identifier(key, getSimpleCoordinate(ctx)), AssumedType.COUNTER));
}
private Point getSimpleCoordinate(Context ctx) {
if (ctx instanceof Point) {
return (Point) ctx;
} else {
return null;
}
}
@Override
public Context createContext(Map<String, ?> properties) {
if (properties == null)
properties = new HashMap<>();
return new Point(properties);
}
}
|