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.prometheus.PrometheusConfig;
|
13
|
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
14
|
import io.micrometer.spring.autoconfigure.export.prometheus.PrometheusProperties;
|
15
|
import io.prometheus.client.CollectorRegistry;
|
16
|
import org.springframework.context.annotation.Bean;
|
17
|
import org.springframework.context.annotation.Configuration;
|
18
|
|
19
|
@Configuration
|
20
|
public class PrometheusEndpointConfig {
|
21
|
|
22
|
@Bean
|
23
|
public PrometheusMeterRegistry prometheusMeterRegistry(PrometheusConfig config, CollectorRegistry collectorRegistry,
|
24
|
Clock clock) {
|
25
|
return new PrometheusMeterRegistry(config, collectorRegistry, clock);
|
26
|
}
|
27
|
|
28
|
@Bean
|
29
|
public Clock micrometerClock() {
|
30
|
return Clock.SYSTEM;
|
31
|
}
|
32
|
|
33
|
@Bean
|
34
|
public PrometheusConfig prometheusConfig(PrometheusProperties props) {
|
35
|
return new DefaultPrometheusConfig(props);
|
36
|
}
|
37
|
|
38
|
@Bean
|
39
|
public PrometheusProperties prometheusProperties(){
|
40
|
return new PrometheusProperties();
|
41
|
}
|
42
|
|
43
|
@Bean
|
44
|
public CollectorRegistry collectorRegistry() {
|
45
|
return new CollectorRegistry(true);
|
46
|
}
|
47
|
|
48
|
private class DefaultPrometheusConfig implements PrometheusConfig {
|
49
|
private final PrometheusProperties props;
|
50
|
private final PrometheusConfig defaults = k -> null;
|
51
|
|
52
|
private DefaultPrometheusConfig(PrometheusProperties props) {
|
53
|
this.props = props;
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public String get(String k) {
|
58
|
return null;
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public boolean descriptions() {
|
63
|
return props.isDescriptions();
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public Duration step() {
|
68
|
return props.getStep() == null ? defaults.step() : props.getStep();
|
69
|
}
|
70
|
}
|
71
|
}
|