1
|
package eu.dnetlib.data.search.micrometer;
|
2
|
|
3
|
import io.micrometer.core.instrument.Tags;
|
4
|
import io.micrometer.core.instrument.Timer;
|
5
|
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
6
|
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
7
|
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
|
8
|
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
|
9
|
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.apache.maven.model.Dependency;
|
12
|
import org.apache.maven.model.Model;
|
13
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
14
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.context.annotation.Configuration;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
|
19
|
import javax.annotation.PostConstruct;
|
20
|
import javax.ws.rs.core.Application;
|
21
|
import java.io.IOException;
|
22
|
import java.io.InputStreamReader;
|
23
|
import java.time.Duration;
|
24
|
import java.util.List;
|
25
|
import java.util.concurrent.atomic.AtomicInteger;
|
26
|
|
27
|
|
28
|
@Configuration
|
29
|
@Component
|
30
|
public class Metrics {
|
31
|
|
32
|
private static final Logger logger = Logger.getLogger(Metrics.class);
|
33
|
|
34
|
private static final AtomicInteger n = new AtomicInteger(1);
|
35
|
|
36
|
@Autowired
|
37
|
private PrometheusMeterRegistry registry;
|
38
|
|
39
|
@PostConstruct
|
40
|
public void init() {
|
41
|
|
42
|
new JvmMemoryMetrics().bindTo(registry);
|
43
|
new JvmGcMetrics().bindTo(registry);
|
44
|
new JvmThreadMetrics().bindTo(registry);
|
45
|
new UptimeMetrics().bindTo(registry);
|
46
|
|
47
|
Timer.builder("search.server.response.duration").description("search response time with solr request and transformation included")
|
48
|
.sla(Duration.ofMillis(100), Duration.ofMillis(500), Duration.ofMillis(1000), Duration.ofMillis(2000), Duration.ofMillis(2500),
|
49
|
Duration.ofMillis(3000),Duration.ofMillis(4000), Duration.ofMillis(5000)).register(registry);
|
50
|
|
51
|
Timer.builder("solr.server.response.duration").description("solr response time")
|
52
|
.sla(Duration.ofMillis(100), Duration.ofMillis(500), Duration.ofMillis(1000), Duration.ofMillis(2000), Duration.ofMillis(2500),
|
53
|
Duration.ofMillis(3000),Duration.ofMillis(4000), Duration.ofMillis(5000)).register(registry);
|
54
|
|
55
|
MavenXpp3Reader reader = new MavenXpp3Reader();
|
56
|
Model model = null;
|
57
|
|
58
|
try {
|
59
|
model = reader.read(
|
60
|
new InputStreamReader(
|
61
|
Application.class.getResourceAsStream(
|
62
|
"/META-INF/maven/eu.dnetlib/uoa-search/pom.xml"
|
63
|
)
|
64
|
)
|
65
|
);
|
66
|
|
67
|
} catch (XmlPullParserException e) {
|
68
|
logger.error("Error reading pom. ", e);
|
69
|
|
70
|
} catch (IOException e) {
|
71
|
logger.error("Error reading pom. ", e);
|
72
|
} {
|
73
|
|
74
|
}
|
75
|
|
76
|
List<Dependency> list = model.getDependencies();
|
77
|
Dependency micrometer = list.stream()
|
78
|
.filter(dependency -> dependency.getArtifactId().equals("micrometer-registry-prometheus"))
|
79
|
.findFirst()
|
80
|
.get();
|
81
|
|
82
|
registry.gauge("micrometer_info", Tags.of("component", model.getArtifactId()).and("scmtag", "HEAD").and("version", model.getVersion()), n);
|
83
|
//registry.summary("search.server.response.size");
|
84
|
|
85
|
}
|
86
|
}
|