-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate to Prometheus Spring Java
Rohith Kunnath Puthan Veedu edited this page Jan 27, 2021
·
3 revisions
@Configuration
@EnableScheduling
public class HibernateMetricsConfig {
private final MeterRegistry meterRegistry;
public HibernateMetricsConfig(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
@Scheduled(cron = "*/50 * * * * *")
public void updateMetric() {
MetricPublisher.INSTANCE.queryWithMaxRows()
.forEach((query, count) -> {
new MicrometerMetricsCaptor(meterRegistry)
.gaugeBuilder("sql_fetch_rows", count, value -> count.intValue())
.tag("sql", query)
.build();
});
MetricPublisher.INSTANCE.queryWithMaxExecutionTime()
.forEach((query, count) -> {
new MicrometerMetricsCaptor(meterRegistry)
.gaugeBuilder("sql_fetch_time", count, value -> count.intValue())
.tag("sql", query)
.build();
});
}
}
The data is added to meter registry every 50 seconds and this will be later available in prometheus.