-
Notifications
You must be signed in to change notification settings - Fork 2
/
MetricValue.java
84 lines (71 loc) · 2.21 KB
/
MetricValue.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package net.thisptr.jmx.exporter.agent.scripting.janino.api;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.thisptr.jmx.exporter.agent.misc.StringWriter;
/**
* This class represents a single Prometheus metric sample.
*
* <p>
* Jackson annotations is added only to implement toString() for logging and debugging.
* Do not expect consistent serialization/deserialization behavior.
* JSON field names are subject to change without any notice, unlike Java field names which are part of the
* Java scripting interface.
* </p>
*/
public class MetricValue {
private static final ObjectMapper MAPPER = new ObjectMapper();
/**
* Name of the metric.
*/
@JsonProperty("name")
public String name;
/*
* THIS FIELD IS NOT PART OF THE API. DO NOT USE FROM TRANSFORM SCRIPTS.
*/
@JsonIgnore
/* package private */ StringWriter nameWriter;
@JsonProperty("suffix")
public String suffix;
/**
* Labels.
*/
@JsonProperty("labels")
public Map<String, String> labels;
/**
* Metric value.
*/
@JsonProperty("value")
public double value;
/**
* Time in milliseconds at which the value is scraped. This timestamp is included in the final /metrics response when
* include_timestamp option is enabled and the timestamp is not 0.
*/
@JsonProperty("timestamp")
@JsonInclude(Include.NON_DEFAULT)
public long timestamp = 0;
/**
* If set and include_help is enabled, this value is included as HELP metadata in the final /metrics response.
*/
@JsonProperty("help")
@JsonInclude(Include.NON_NULL)
public String help;
/**
* If set and include_type is enabled, this value is included as TYPE metadata in the final /metrics response.
*/
@JsonProperty("type")
@JsonInclude(Include.NON_NULL)
public String type;
@Override
public String toString() {
try {
return MAPPER.writeValueAsString(this);
} catch (JsonProcessingException e) {
throw new RuntimeException(e); // not expected to happen
}
}
}