Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing Spring Boot metrics to influxDB for grafana visualization

I have a Spring Boot application running on Cloud Foundry that exposes metrics and health info via the /metrics & /health endpoints respectively. I'd like to post these metrics as a continuous stream to an influxDB user provided service for visualization on a grafana dashboard. I am looking for any resources that explain how the dataflow would work and would appreciate any suggestions.

Thanks.

like image 735
citizenBane Avatar asked Sep 18 '15 15:09

citizenBane


People also ask

Can InfluxDB used with Grafana?

You can also create multiple InfluxDB Data Sources in Grafana. You have a lot of flexibility here. You can, for instance: Create two data sources that point to the same InfluxDB instance, once of which uses Flux, and another that uses InfluxQL.

How can I see Prometheus metrics in Grafana?

Click the graph title, then click "Edit". Under the "Metrics" tab, select your Prometheus data source (bottom right). Enter any Prometheus expression into the "Query" field, while using the "Metric" field to lookup metrics via autocompletion.

What is the difference between Prometheus and InfluxDB?

InfluxDB is a push-based system. It requires an application to actively push data into InfluxDB. Prometheus is a pull-based system. An application publishes the metrics at a given endpoint, and Prometheus fetches them periodically.


2 Answers

Telegraf meets your requirements. It pulls data from jolokia and save to InfluxDB.

All you need to do is enable actuator and jolokia for SpringbootApplication, it is easy to add dependency to your maven:

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

After this you need configure telegraf to connect your web server and influxDB, here is an example config:

[tags]
dc = "local-1"

[agent]
interval = "10s"

[[inputs.jolokia]]
context = "/jolokia"

[[inputs.jolokia.servers]]
name = "catalog"
host = "{web server ip address}"
port = "{web server port}"

[[inputs.jolokia.metrics]]
name = "metrics"
mbean  = "org.springframework.boot:name=metricsEndpoint,type=Endpoint"
attribute = "Data"

[outputs]
[outputs.influxdb]
url = "{http://influxdb:port}"
database = "telegraf"
precision = "s"

Make sure network of upper configuration is available, then you will get data in you influxDB.

Configure grafana to display the data stored in influxDB:

  1. Add a influxDB type datasource
  2. Create a new Dashboard and Graph panel.
  3. Configure Graph panel and choose which filed you want to display in Metrics setting.

You will see the data on the panel.

like image 81
Nie Xing Avatar answered Sep 20 '22 21:09

Nie Xing


InfluxDB (unlike Prometheus) is a push based system. It cannot poll a HTTP endpoint to collect metrics. Your application needs to contiguously/periodically push data into InfuxDB instance.

To push application into InfluxB, others have suggested libraries like influxdb-java, metrics-influxdb, etc.

There is one more (and much better IMO) solution.

You can have a look at a new library, developed by Spring team, called micrometer.

Micrometer is a metrics collection library with support for a huge number of TSDBs (Influx being one of them). It was first introduced in Spring 2, and has been since back-ported to Spring 1.3+.

Micrometer publishes all of default actuator metrics out of the box. It is super-easy to get started with. You can read about all the capabilities here.

like image 33
narendra-choudhary Avatar answered Sep 21 '22 21:09

narendra-choudhary