Zabbix添加主机监控及自定义item监控
1.zabbix_get命令详解
1
|
安装zabbix-get命令 |
1
|
[[email protected] ~] # yum install -y zabbix_get
|
1
2
3
4
5
|
参数说明: -s --host: 指定客户端主机名或者IP -p --port:客户端端口,默认10050 -I -- source -address:指定源IP,写上zabbix server的ip地址即可,一般留空,服务器如果有多ip的时候,你指定一个。
-k --key:你想获取的key |
1
2
3
4
5
6
|
获取负载: [[email protected] ~] # zabbix_get -s 127.0.0.1 -k system.cpu.load[,avg5]
0.030000 获取cpu空闲百分比: [[email protected] ~] # zabbix_get -s linux-node2 -k system.cpu.util[,idle]
99.916206 |
2.安装zabbix-agent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[[email protected] ~] # yum install -y zabbix-agent
[[email protected] ~] # vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.56.11 ServerActive=192.168.56.11:10050 HostnameItem=system. hostname
[[email protected] ~] # systemctl enable zabbix-agent
[[email protected] ~] # systemctl start zabbix-agent
[[email protected] ~] # netstat -tulnp
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 866 /sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2235 /master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 24188 /zabbix_agentd tcp6 0 0 :::22 :::* LISTEN 866 /sshd tcp6 0 0 ::1:25 :::* LISTEN 2235 /master tcp6 0 0 :::10050 :::* LISTEN 24188 /zabbix_agentd
|
3.添加主机监控
Configuration-->Hosts-->create host-->填写主机名、所属组-->链接模板"Templates"-->ADD
4.创建自定义Key监控
在客户端配置文件 zabbix_angentd.conf 里面配置 UserParameter。语法如下:
UserParameter=key,command(key是自定义的,command是使用命令获取数值的方法;在取值时尽量避免使用管道,以免获取数值超时)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
查看系统上的自定义Key格式: [[email protected] zabbix_agentd.d] # tail -2 userparameter_mysql.conf
UserParameter=mysql. ping ,HOME= /var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V 创建自定义key,监控 /etc/services 大小。直接写一个conf文件,将自定义Key写入
[[email protected] zabbix_agentd.d] # cat monitor_file.conf
UserParameter=monitor_file,stat -c %s /etc/services
重启zabbix-agent [[email protected] zabbix_agentd.d] # systemctl restart zabbix-agent
[[email protected] ~] # netstat -tulnp
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 866 /sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2235 /master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 24188 /zabbix_agentd tcp6 0 0 :::22 :::* LISTEN 866 /sshd tcp6 0 0 ::1:25 :::* LISTEN 2235 /master tcp6 0 0 :::10050 :::* LISTEN 24188 /zabbix_agentd 在zabbix-server上使用zabbix_get命令获取监控值 [[email protected] ~] # zabbix_get -s linux-node2 -k monitor_file
670293 |
5.web界面添加item
1
|
"Configuration" --> "Host" --> "Items" --> "Create item"
|
创建完成,可以在监控的最新数据进行查看获取数值
6.zabbix的值映射show value mapping
zabbix 为了显示更人性化的数据,在使用过程中,我们可以将获取到得数据映射为一个字符串。比如,我们写脚本监控 MySQL 是否在运行中, 一般返回 0 表示数据库挂了, 1 表示数据库正常,还有各种各样的监控都是返回 0, 1,
2, 3 这样的数据,监控页上显示的都是数据字,完全不知道是什么意思。 为了更加友好地提示,就有一个show value mapping的功能。
下面以监控linux-node2上的80端口为例子。
创建监控项,监听80端口,在show value选择映射Service state,会指向两种状态显示:0-->Down ; 1-->Up
在未启动httpd服务和启动之后的的状态变化都会以Down和Up来展示,这样更能清晰掌握服务的状态。
7.Zabbix解决中文乱码
找到本地 C:\Windows\Fonts\simkai.ttf(楷体)上传到服务器 zabbix 网站目录 fonts 目录下。
1
2
3
4
5
6
7
8
9
10
11
12
|
[[email protected] ~] # cd /usr/share/zabbix/fonts/
[[email protected] fonts] # ll
总用量 0 lrwxrwxrwx 1 root root 33 12月 4 17:43 graphfont.ttf -> /etc/alternatives/zabbix-web-font
[[email protected] fonts] # ll
总用量 11512 lrwxrwxrwx 1 root root 33 12月 4 17:43 graphfont.ttf -> /etc/alternatives/zabbix-web-font
-rw-r--r-- 1 root root 11785184 6月 11 2009 SIMKAI.TTF [[email protected] fonts] # \mv SIMKAI.TTF graphfont.ttf
[[email protected] fonts] # ll
总用量 11512 -rw-r--r-- 1 root root 11785184 6月 11 2009 graphfont.ttf |
版权声明:原创作品,谢绝转载。否则将追究法律责任
本文转自 IT_外卖小哥 51CTO博客,原文链接:http://blog.51cto.com/jinlong/2051022