blob: 61ac69c6ab0b5bb81f3ebd15b27a7db84f7918a0 (
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
55
|
// Copyright Vespa.ai. 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.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 metrics consumer in JDisc.
*
* @author Steinar Knutsen
*/
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.isEmpty())
return Point.emptyPoint();
return new Point(properties);
}
public MetricReceiver receiver() { return receiver; }
}
|