1
|
package eu.dnetlib.metrics;
|
2
|
|
3
|
/**
|
4
|
* Created by Alessia Bardi on 2019-06-21.
|
5
|
*
|
6
|
* @author Alessia Bardi
|
7
|
*/
|
8
|
|
9
|
import java.time.Duration;
|
10
|
|
11
|
import io.micrometer.core.instrument.Clock;
|
12
|
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
13
|
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
14
|
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
|
15
|
import io.micrometer.prometheus.PrometheusConfig;
|
16
|
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
17
|
import io.micrometer.spring.autoconfigure.export.prometheus.PrometheusProperties;
|
18
|
import io.prometheus.client.CollectorRegistry;
|
19
|
import org.springframework.context.annotation.Bean;
|
20
|
import org.springframework.context.annotation.Configuration;
|
21
|
|
22
|
@Configuration
|
23
|
public class PrometheusEndpointConfig {
|
24
|
|
25
|
@Bean
|
26
|
public PrometheusMeterRegistry prometheusMeterRegistry(PrometheusConfig config, CollectorRegistry collectorRegistry,
|
27
|
Clock clock) {
|
28
|
PrometheusMeterRegistry pr = new PrometheusMeterRegistry(config, collectorRegistry, clock);
|
29
|
threadMetrics().bindTo(pr);
|
30
|
memoryMetrics().bindTo(pr);
|
31
|
jvmgcMetrics().bindTo(pr);
|
32
|
return pr;
|
33
|
}
|
34
|
|
35
|
@Bean
|
36
|
public Clock micrometerClock() {
|
37
|
return Clock.SYSTEM;
|
38
|
}
|
39
|
|
40
|
@Bean
|
41
|
public PrometheusConfig prometheusConfig(PrometheusProperties props) {
|
42
|
return new DefaultPrometheusConfig(props);
|
43
|
}
|
44
|
|
45
|
@Bean
|
46
|
public PrometheusProperties prometheusProperties(){
|
47
|
return new PrometheusProperties();
|
48
|
}
|
49
|
|
50
|
@Bean
|
51
|
public CollectorRegistry collectorRegistry() {
|
52
|
return new CollectorRegistry(true);
|
53
|
}
|
54
|
|
55
|
@Bean
|
56
|
public JvmThreadMetrics threadMetrics(){
|
57
|
return new JvmThreadMetrics();}
|
58
|
|
59
|
@Bean
|
60
|
public JvmMemoryMetrics memoryMetrics(){
|
61
|
return new JvmMemoryMetrics();
|
62
|
}
|
63
|
|
64
|
@Bean
|
65
|
public JvmGcMetrics jvmgcMetrics(){
|
66
|
return new JvmGcMetrics();
|
67
|
}
|
68
|
|
69
|
|
70
|
private class DefaultPrometheusConfig implements PrometheusConfig {
|
71
|
private final PrometheusProperties props;
|
72
|
private final PrometheusConfig defaults = k -> null;
|
73
|
|
74
|
private DefaultPrometheusConfig(PrometheusProperties props) {
|
75
|
this.props = props;
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public String get(String k) {
|
80
|
return null;
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public boolean descriptions() {
|
85
|
return props.isDescriptions();
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
public Duration step() {
|
90
|
return props.getStep() == null ? defaults.step() : props.getStep();
|
91
|
}
|
92
|
}
|
93
|
}
|