6
votes

I really like the capabilities of Grafana for graphing metrics over time and showing a nice dashboard. I'd like to use it to track CPU, Mem, etc throughout my deployment environment. I'd also like to use it to track some numbers from my Java programs. How can I connect Java to Grafana?

Grafana supports three different database solutions (graphite, influxdb, OpenTSDB). I am not using any of these at the moment. But influxdb looks easy to setup. I'm really just looking for something simple and future-proof. It will only monitor a few servers for now, but it may grow in time. Is there an easy way to push a single Java integer with a label and timestamp into Grafana. I'm thinking there must be something like log4j for metrics. But I also need to decide which database to use, but hopefully that would be abstracted out of the interface. Any advice?

3

3 Answers

3
votes

Grafana is 'just' a tool to display time series. Which means you will need an additional time series database between your java apllication and grafana.

You can find the current list of supported databases on their offical website: Datasources

As you mentioned influxdb, you might want to have a look at this influxdb-java project

1
votes

InfluxDB is going to be the easiest to set up between the supported options. It's still very much a moving target though, although they're working hard to release a stable version.

The only way to visualize data in Grafana right now is through one of those databases.

0
votes

For monitoring with Grafana, I recommand Prometheus (https://prometheus.io/docs/prometheus/latest/getting_started/) with the JMX exporter in your case : https://github.com/prometheus/jmx_exporter.

You can add more exporter if you need (https://prometheus.io/docs/instrumenting/exporters/), you can expose your app's metrics to prometheus, etc.

Prometheus is a fully integrated monitoring solution, just the graphs are limited because you cannot make dashboards, but for that you have Grafana :)