前面我们给prometheus添加了一些监控项,但是这些数据指标对我们现在来说并没有什么概念。
我们这章就将这些稀碎的信息聚合起来进行显示,而使用的工具就是grafana ♪(^∇^*)
一. grafana安装
grafana 提供给prometheus一个非常好看的UI界面,我们可以通过promQL来支持数据的可视化
安装
#拉取软件包(略慢)
wget https://dl.grafana.com/oss/release/grafana-7.4.1-1.x86_64.rpm
#可以用我的包
https://download.csdn.net/download/qq_42883074/15707947
#安装
rpm -ivh grafana-7.4.1-1.x86_64.rpm
#启动
systemctl daemon-reload
systemctl enable grafana-server
systemctl restart grafana-server.service
访问
http://192.168.1.20:3000/login
#默认用户密码都是admin,第一次登陆会修改密码
#我这里修改为123456

二. 添加数据源
我们需要将prometheus纳管进数据源,使得我们可以在grafana上通过promQL语句对调用prometheus上的指标
三. 使用Dashboard模板来显示数据
#grafana数据显示模板
https://grafana.com/grafana/dashboards
#大家可能会好奇,为什么我们设置了prometheus数据源,并添加了模板,但是却没有数据?
#首先我们要知道刚才添加的模板是基于node-exporter服务所收集的指标进行显示的
#之前我们在prometheus配置中node-exporter添加了过滤器,屏蔽掉了部分指标收集
#然而,grafana的监控显示界面大部分都是由一条一条"promeQL"语句查询得到的数据进行显示的
#如下,我们从一个显示框内拿到了他的promQL语句进行查询发现并没有得到指标数据
我们将prometheus中的过滤器配置去掉
vi /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
metrics_path: /metrics
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['192.168.1.21:9100']
# params: #我们将这一大段过滤器注释
# collect[]:
# - cpu
# - meminfo
# - diskstats
# - netdev
# - systemd
- job_name: 'docker'
static_configs:
- targets: ['192.168.1.20:8081']
- job_name: 'grafana' #捎带收集一下grafana指标状态
static_configs:
- targets: ['192.168.1.20:3000']
重载服务
curl -X POST http://192.168.1.20:9090/-/reload
可以看到上图中,我们已经收集到了node-exporter的指标并且显示出来o(* ̄▽ ̄*)o
但是,我们在内网使用时是无法直接通过模板进行在线配置的
更多的时候我们需要将模板的json文件导出到本地去使用