简体   繁体   English

如何将Java连接到Grafana

[英]How to connect Java to Grafana

I really like the capabilities of Grafana for graphing metrics over time and showing a nice dashboard. 我非常喜欢Grafana的功能,可以随着时间的推移绘制指标并显示一个漂亮的仪表板。 I'd like to use it to track CPU, Mem, etc throughout my deployment environment. 我想在整个部署环境中使用它来跟踪CPU,Mem等。 I'd also like to use it to track some numbers from my Java programs. 我还想用它来跟踪我的Java程序中的一些数字。 How can I connect Java to Grafana? 如何将Java连接到Grafana?

Grafana supports three different database solutions (graphite, influxdb, OpenTSDB). Grafana支持三种不同的数据库解决方案(graphite,Influxdb,OpenTSDB)。 I am not using any of these at the moment. 我目前没有使用任何这些。 But influxdb looks easy to setup. 但是,Influxdb看起来很容易设置。 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. 是否有一种简单的方法可以将带有标签和时间戳的单个Java整数推送到Grafana中。 I'm thinking there must be something like log4j for metrics. 我认为必须有像log4j这样的指标。 But I also need to decide which database to use, but hopefully that would be abstracted out of the interface. 但我还需要决定使用哪个数据库,但希望将其从界面中抽象出来。 Any advice? 有什么建议?

InfluxDB is going to be the easiest to set up between the supported options. InfluxDB将是最容易在支持的选项之间建立的。 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. 现在,在Grafana中可视化数据的唯一方法是通过其中一个数据库。

Grafana is 'just' a tool to display time series. Grafana是'只是'显示时间序列的工具。 Which means you will need an additional time series database between your java apllication and grafana. 这意味着您需要在java apllication和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 正如你提到的Influxdb,你可能想看看这个Influxdb-java项目

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 . 为了使用Grafana进行监控,我建议您使用JMX导出器Prometheus( https://prometheus.io/docs/prometheus/latest/getting_started/ ): 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. 如果需要,您可以添加更多导出器( https://prometheus.io/docs/instrumenting/exporters/ ),您可以将应用程序的指标公开给prometheus等。

Prometheus is a fully integrated monitoring solution, just the graphs are limited because you cannot make dashboards, but for that you have Grafana :) Prometheus是一个完全集成的监控解决方案,只是图表是有限的,因为你不能制作仪表板,但为此你有Grafana :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM