Giter VIP home page Giter VIP logo

prometheus-grafana's Introduction

Prometheus with Grafana

Minor POC to test time based metrics alternatives

How

Like a cake recipe.

  1. Simple Kotlin/Spring Boot app
  2. Prometheus server up and running
  3. Grafana container (because install in Mac sucks).

Kotlin/Spring Boot app

After a working rest endpoint just add those dependencies:

dependencies {
  // ...
  implementation("io.micrometer:micrometer-core")
  implementation("io.micrometer:micrometer-registry-prometheus")
  // ...
}

and this parameters to application.properties:

#Metrics related configurations
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true

This will add endpoints to actuar and expose metrics through a rest api.

In the code, create objects to collect the metrics like:

@Component
class PrometheusMetrics(@Autowired val meterRegistry: MeterRegistry) {
   private final val callCounter : Counter = Counter
             .builder("echocounter")
             .description("this is an echo counter")
             .register(meterRegistry)

    fun count() {
        println("Count!")
         callCounter.increment()
    }
}

once count() is called, it will add ONE in the prometheus metrics.

Prometheus

Download Prometheus and create a config file as bellow:

#App Config file
#Global configurations
global:
  scrape_interval:     5s # Set the scrape interval to every 5 seconds.
  evaluation_interval: 5s # Evaluate rules every 5 seconds.
scrape_configs:
  - job_name: 'echo-app'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8080']

now start it ./prometheus --config.file=app-config.yml.

Grafana

Start with docker-compose and add a new Prometheus Datasource. (simple right?)

Meta

Alex Rocha - about.me

prometheus-grafana's People

Stargazers

N Peruch avatar

Watchers

James Cloos avatar Alex Rocha avatar

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.