Giter Site home page Giter Site logo

ilya-rochev / grafana-dashboard-generator Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 186 KB

Annotation processor which automatically generates Grafana Dashboard JSON model based on metrics declared in application

Java 100.00%
grafana-dashboard grafana-prometheus prometheus

grafana-dashboard-generator's Introduction

Grafana Dashboard Generator

Annotation processor which automatically generates Grafana Dashboard JSON model based on metrics declared in application.

How to build project

run command

./mvnw clean install

How to use library

  1. Add next dependencies to pom.xml
<dependency>
    <groupId>io.github.ilya-rochev</groupId>
    <artifactId>grafana-dashboard-annotations-processor</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>io.github.ilya-rochev</groupId>
    <artifactId>prometheus-metric-spring-boot-starter</artifactId>
    <version>1.0</version>
</dependency>
  1. Migrate creating Counter and Timer beans to processed by prometheus-metric-spring-boot-starter annotation i.r.grafana.json.annotations.promethues.@Metric.

If you create metrics like this

@Configuration
@RequiredArgsConstructor
public class MetricConfig {

    private final MeterRegistry meterRegistry;

    @Bean
    public Counter savedObjectsCounter() {
        return meterRegistry.counter("counter_as_field",  "type", "saved");
    }
    
    ...  
}

Change creating metrics declarative way using @Metric annotation

@Service
@RequiredArgsConstructor
@ParametersAreNonnullByDefault
public class ExternalCounterServiceStub {

    @Metric(value = "counter_as_field", extraTags = {"type", "saved"}, description = "Saved object counter")
    private final Counter savedObjectsCounter;
    
    ...
}   

Notice: prometheus-metric-spring-boot-starter processes annotation @Metric during starting application. It creates Timer or Counter bean with name and tags you provided as annotation parameters.

  1. Declare you Grafana dashboard using annotations from package i.r.grafana.json.annotations
@Dashboard(title = "Demo application metrics", panels = {
        @Panel(metric = "timer_as_field", title = "External service invocation time (FIELDS)"),
        @Panel(metric = "timer_as_annotation", title = "External service invocation time (ANNOTATIONS)"),
        @Panel(metric = "counter_as_field", title = "External objects counters (FIELDS)"),
        @Panel(metric = "counter_as_annotation", title = "External objects counters (ANNOTATION)")}
)
public class GrafanaDashboardConfiguration { }

Notice: grafana-dashboard-annotations-processor processes annotations from package i.r.grafana.json.annotations during compile. It generates dashboard model and injects metrics you declared using @Metric annotation;

  1. Build your project. Created grafana json model will be stored in target\classes\dasboard_{uuid}.json file, for example - dashboard_221a4f4c-2d60-4ec0-9fa5-7c828fee81eb.json

  2. Run your project and import generated json file to grafana. Enjoy to view you custom application metrics.

Demo application

Project provides demo application to be informed how to use library in practice

Requires:

- "docker" runned at your machine;
  1. Start locally grafana and prometheus in docker:
docker-compose up -d
  1. Export generated metrics to Grafana

  2. Start demo application;

  3. Test demo application with postman collection docs/Demo_Application_GRAFANA.postman_collection.json

  4. See metrics in Grafana Alt text

grafana-dashboard-generator's People

Contributors

ilya-rochev avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ihebbmz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.