<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.11.0</version>
</dependency>
groovy
implementation 'io.prometheus:simpleclient:0.11.0'
import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.exporter.HTTPServer;
Counter requestsCounter = Counter.build()
.name("myapp_requests_total")
.help("Total number of requests received")
.register();
requestsCounter.inc();
HTTPServer server = new HTTPServer(8080);
Counter requestsCounter = Counter.build()
.name("myapp_requests_total")
.help("Total number of requests received")
.labelNames("method")
.register();
requestsCounter.labels("GET").inc();
requestsCounter.labels("POST").inc();
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
groovy
implementation 'io.micrometer:micrometer-registry-prometheus'
yaml
management:
endpoints:
web:
exposure:
include: prometheus
@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class YourApplication {
// ...
}