Linux-监控三剑客之Grafana

发布时间 2023-03-23 16:53:49作者: wh459086748

Grafana

一、环境准备

环境
zabbix-server zabbix服务端 10.0.0.62
grafana-server grafana服务端 10.0.0.63

二、使用流程

1.部署grafana 9.3.6

[root@grafana-server ~]# ll
total 119100
-rw-------. 1 root root     1340 Jan  9 09:09 anaconda-ks.cfg
-rw-r--r--  1 root root 88935132 Mar 21 08:16 grafana-9.3.6-1.x86_64.rpm
-rw-r--r--  1 root root 33016641 Mar 21 08:16 grafana-9.3.6-alexanderzobnin-zabbix-app-v4.2.10.tar.gz
#安装grafana
[root@grafana-server ~]# yum localinstall -y grafana-9.3.6-1.x86_64.rpm
#启动grafana
[root@grafana-server ~]# systemctl enable --now grafana-server.service
[root@grafana-server ~]# ss -lnutp|grep grafana
tcp    LISTEN     0      128    [::]:3000  [::]:*   users:(("grafana-server",pid=6046,fd=11))

#解压插件
[root@grafana-server ~]# tar xf grafana-9.3.6-alexanderzobnin-zabbix-app-v4.2.10.tar.gz 
[root@grafana-server ~]# ll
total 119104
drwxr-xr-x  7 root root     4096 Mar 20 21:42 alexanderzobnin-zabbix-app
#创建插件目录
[root@grafana-server ~]# mkdir -p /var/lib/grafana/plugins
[root@grafana-server ~]# mv alexanderzobnin-zabbix-app/ /var/lib/grafana/plugins
#重启grafana
[root@grafana-server ~]# systemctl restart grafana-server.service
#查看grafana插件
[root@grafana-server ~]# grafana-cli plugins ls
installed plugins:
alexanderzobnin-zabbix-app @ 4.2.10
Please restart Grafana after installing plugins. Refer to Grafana documentation for instructions if necessary.

2.web页面访问

http://gra.cn:3000/

image-20230321194044830

3.简单配置

image-20230321194152103

image-20230321194218337

4. 配置zbx插件

image-20230321194330539

image-20230321194406180

image-20230321194414026

如果搜索不到zabbix表示没有安装对应的插件.

可以通过提供的软件包解压或者grafana-cli plugins install alexanderzobnin-zabbix-app安装.

5.配置grafana的数据源

image-20230321194512686

image-20230321194524046

image-20230321194648041

image-20230321194844750

image-20230321194934723

6.导入自带的几个仪表盘

image-20230321195417116

image-20230321195430819

image-20230321195446207

三、Grafana web页面添加与配置图形 dashboard

image-20230321195616432

1.修改主机名

image-20230321195707070

image-20230321195742450

image-20230321200011867

image-20230321200257299

image-20230321200457663

image-20230321200622527

2.修改显示cpu使用率

image-20230321200808923

3.修改显示uptime

image-20230321200855422

4.保存修改后的面板

image-20230321200919664

image-20230321200934727

image-20230321200942985

5.测试是否从zabbix获取值

image-20230321202052204

image-20230321202117202

image-20230321202132196

四、自定义监控获取zbx服务端的每秒新值

zabbix.stats键值的结果之一.

需要通过自定义监控创建1个监控项运行zabbix.stats键值.

创建相关项(监控项)对上面监控项结果进行过滤(sed反向引用).

1.定义监控项(主要项)

image-20230321201225204

image-20230321201347162

2.创建相关项

image-20230321201521775

image-20230321201630947

image-20230321201642209

image-20230321201733052

image-20230321201748548

image-20230321202233855

注意事项:

如果zabbix做了高可用,这里可能会有问题

image-20230321205707849

五、更完善的模板(仪表盘)

下载官方仪表盘https://grafana.com/grafana/dashboards/?plcmt=footer

1.下载模板

image-20230321204247524

image-20230321204317635

image-20230321204417646

image-20230321204446171

image-20230321204517672

image-20230321204532855

image-20230321204548739

2.配置模板可编辑

image-20230321204632527

image-20230321204643499

image-20230321204650848

image-20230321204700156

image-20230321204712713

image-20230321204735615

3.grafana仪表盘中变量的设置与修改

image-20230321204758534

image-20230321204917181

image-20230321204957032

image-20230321205027867

image-20230321205038623

image-20230321205049437