Skip to content

Latest commit

 

History

History
90 lines (73 loc) · 3.13 KB

README.md

File metadata and controls

90 lines (73 loc) · 3.13 KB

Autometricsj

Autometrics is an observability micro-framework built for developers. It makes it easy to instrument any function with the most useful metrics: request rate, error rate, and latency. Autometrics uses instrumented function names to generate Prometheus queries so you don’t need to hand-write complicated PromQL.

This is an implementation of Autometrics in Java. This implementation is built with AspectJ and is built to integrate with Spring Boot and Micrometer.

Usage

To add Autometrics as a dependency

<dependency>
  <groupId>dev.autometrics.bindings</groupId>
  <artifactId>autometricsj</artifactId>
  <version>1.3</version>
</dependency>

To enable Autometrics in your project

@SpringBootApplication
@EnableAutometrics
public class YourApplication {

To generate Autometrics metrics for a function method:

@Autometrics
public String yourMethod() {

In order for this plugin to work with service name and version, you must expose them through your application.yaml file.

app:
  version: 1.0.0

spring:
  application:
    name: application-name

Requirements

1. Micrometer

This plugin leverages Micrometer in order to expose your metrics to Autometrics. If your project does not already have Micrometer configured, then these metrics will not be scraped by Prometheus.

You can include Micrometer via the Actuator dependency. Actuator also exposes some endpoints for health-checking and monitoring.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

In addition, you need the registry dependency for Prometheus. The registry will ensure that the metrics are exposed in a readable way for Prometheus.

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <scope>runtime</scope>
</dependency>

Lastly you should make the endpoint for Prometheus to scrap from available within your application.yaml.

management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus

The Endpoint will be something like this localhost:8080/actuator/prometheus

2. Prometheus

You need a running Prometheus instance to store the data from autometrics and see the charts in the Prometheus UI.

Within the prometheus.yml you must tell Prometheus which endpoint to poll the metrics from.

scrape_configs:
  - job_name: example-api-metrics
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ['localhost:8080']

3. Visualize the data

  • To show tooltips over annotated Methods in IntelliJ, with links to Prometheus queries, install the IntelliJ PlugIn.

  • There are some preconfigured Grafana Dashboards that work with data generated by autometrics.

  • You can also use the Autometrics Explorer with the Autometrics CLI to visualize your Autometrics data.