Skip to content

A spring boot starter that helps to configure prometheus

Notifications You must be signed in to change notification settings

chenkunyun/prometheus-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prometheus starter

This is a spring boot auto-configuration that helps to configure prometheus fast. An embed jetty server is used to expose a local port for prometheus server to pull metrics.

Usage

  1. Add maven dependency
<dependency>
    <groupId>com.kchen</groupId>
    <artifactId>prometheus-spring-boot-starter</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
  1. Add the following in your application.yml
prometheus:
  host: localhost
  port: 9010
  contextPath: /
  path: /metrics
  1. Add metrics in your code
@RestController
@RequestMapping("/")
public class HomeController {

    private static final Counter counters = Counter.build()
            .name("http_requests_total")
            .labelNames("app", "uri", "method")
            .help("counter the request")
            .register();

    @RequestMapping("/")
    public String home(HttpServletRequest request) {
        counters.labels("demo", request.getRequestURI(), request.getMethod()).inc();
        return "home";
    }
}

About

A spring boot starter that helps to configure prometheus

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages