1
|
package eu.dnetlib.metrics;
|
2
|
|
3
|
import java.util.Collections;
|
4
|
import java.util.List;
|
5
|
|
6
|
import io.micrometer.core.instrument.DistributionSummary;
|
7
|
import io.micrometer.core.instrument.MeterRegistry;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.stereotype.Controller;
|
12
|
import org.springframework.web.bind.annotation.RequestMapping;
|
13
|
import org.springframework.web.bind.annotation.RequestMethod;
|
14
|
import org.springframework.web.bind.annotation.ResponseBody;
|
15
|
|
16
|
/**
|
17
|
* Created by Alessia Bardi on 2019-06-21.
|
18
|
*
|
19
|
* @author Alessia Bardi
|
20
|
*/
|
21
|
|
22
|
@Controller
|
23
|
public final class TestController {
|
24
|
|
25
|
private static final Log log = LogFactory.getLog(TestController.class);
|
26
|
|
27
|
private final DistributionSummary counter;
|
28
|
|
29
|
@Autowired
|
30
|
public TestController(final MeterRegistry registry) {
|
31
|
this.counter = DistributionSummary.builder("get.counter.requests")
|
32
|
.tags("version", "v1")
|
33
|
.publishPercentileHistogram()
|
34
|
.register(registry);
|
35
|
}
|
36
|
|
37
|
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
38
|
@ResponseBody
|
39
|
public List<String> getStudents() {
|
40
|
log.info("/test [GET]");
|
41
|
counter.record(10.0); // <-- We shall record latency here
|
42
|
return Collections.emptyList();
|
43
|
}
|
44
|
|
45
|
|
46
|
|
47
|
}
|