blob: edfa198416e08ad888a010ba4fd5966c301f560a (
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
56
57
58
59
60
|
// 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;
import com.google.common.annotations.Beta;
import com.yahoo.metrics.simple.UntypedMetric.AssumedType;
import edu.umd.cs.findbugs.annotations.Nullable;
/**
* A gauge metric, i.e. a bucket of arbitrary sample values. Create a gauge
* metric by declaring it with {@link MetricReceiver#declareGauge(String)} or
* {@link MetricReceiver#declareGauge(String, Point)}.
*
* @author steinar
*/
@Beta
public class Gauge {
@Nullable
private final Point defaultPosition;
private final String name;
private final MetricReceiver receiver;
Gauge(String name, Point defaultPosition, MetricReceiver receiver) {
this.name = name;
this.defaultPosition = defaultPosition;
this.receiver = receiver;
}
/**
* Record a sample with default or no position.
*
* @param x
* sample value
*/
public void sample(double x) {
sample(x, defaultPosition);
}
/**
* Record a sample at the given position.
*
* @param x
* sample value
* @param p
* position/dimension values for the sample
*/
public void sample(double x, Point p) {
receiver.update(new Sample(new Measurement(Double.valueOf(x)), new Identifier(name, p), AssumedType.GAUGE));
}
/**
* Create a PointBuilder with the default dimension values reflecting those
* given when this gauge was declared.
*
* @return a builder initialized with defaults from this metric instance
*/
public PointBuilder builder() {
return new PointBuilder(defaultPosition);
}
}
|