I have a simple Spring Boot application. I want to monitor application metrics using grafana and prometheus. To do this, I added the actuator and micrometer-registry-prometheus to the application
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
I have written two methods for counter and timer
@Service
public class MicrometerServiceImpl implements MicrometerService {
@Autowired
private MeterRegistry meterRegistry;
@Override
public void addCounterMetric(String statName, String description, double count, String... tags){
Counter.builder(statName)
.description(description)
.tags(tags)
.register(meterRegistry)
.increment(count);
}
@Override
public void addTimerMetric(String statName, String description, long duration, String... tags){
Timer.builder(statName)
.description(description)
.tags(tags)
.register(meterRegistry)
.record(duration, TimeUnit.MILLISECONDS);
}
}
And added a method call to the controller
@RequestMapping(path = "/addMetric")
public String callMetric(HttpServletRequest request) {
long start = System.currentTimeMillis();
//some work
micrometerService.addCounterMetric("CONTROLLER_COUNTER", "controller with COUNTER", 1);
micrometerService.addTimerMetric("CONTROLLER_TIMER", "controller with Timer",
System.currentTimeMillis() - start);
return "addMetric";
}
I would like the counter value to be reset to zero every minute, that is, the number of calls per minute is counted. Is it possible to do this using micrometer or grafana? Now I see that the counter is only increasing.
I know there are metrics that count the number of http requests. But I need this for custom metrics, when the metric is considered under certain conditions (for example, the number of errors during processing)