Zabbix-自帶監控項與Kye


開啟主機自動發現

⦁選擇配置 ->自動發現 ->創建自動發現->ip范圍必須連續,不連續的話逗號分開
⦁更新間隔 -> 2s ->更新
⦁檢查 -> 選擇新的 -> ICMP ping ->更新

⦁動作 ->事件源(自動發現) –>創建動作 ->iP地址
⦁主機IP =192.168.1.1 192.168.1.254
⦁在線/不在線>=1秒

操作(這里是否報警)->刪除

⦁點擊操作->選擇新的標簽->操作類型->添加主機->添加
⦁點擊操作->選擇新的標簽->操作類型->添加主機群組->選擇一個群組->添加
⦁點擊操作->選擇新的標簽->操作類型->與模板相關聯->選擇你要添加的模板->添加
⦁點擊操作->選擇新的標簽->操作類型->啟用主機->添加

⦁最后點擊->自動發現->啟用自動發現即可


## 監控進程連接數

⦁首先,直接添加一個主機,我們不要選擇模板,直接添加一個裸主機.

⦁其次我們的被控主機安裝一下Apache軟件,並能在控制端通過zabbix-get命令獲取到Apache進程數.

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k proc.num[httpd]
6

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k proc.num[httpd,,,]
6

#以上兩種寫法相同,具體命令參數應該看文檔.

⦁在web界面上,選擇監控項->創建監控項->選擇鍵值->修改成proc.num[httpd,,,]->點擊添加.

⦁接着點擊圖形->創建圖形->選擇創建的自定義key->保存即可.


## 其他常用監控key

同理,我們就可以使用系統默認的監控key來監控內存,CPU以及網絡等流量信息,配置過程同上一個案例相同,只是在配置中使用的配置參數略有區別罷了,此處就不再演示了.

基本的數據采集命令:

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.hostname
localhost.localdomain  // 此處才是主機名稱

zabbix_get.exe -s 192.168.1.20 -p 10050 -k agent.hostname
centos1   // 此處是我們zabbix中自定義的鍵值對

zabbix_get.exe -s 192.168.1.20 -p 10050 -k agent.ping
1

zabbix_get.exe -s 192.168.1.20 -p 10050 -k agent.version
4.4.3      // zabbix 的version

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.boottime
1578564779    // 系統啟動的時間戳

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.cpu.num
1              // 處理器個數

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.localtime
1578569019      // 當前系統時間戳

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.sw.arch
x86_64         // 返回系統架構

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.sw.os
Linux version 3.10.0-1062.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Wed Aug 7 18:08:02 UTC 2019   // 返回系統詳細架構

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.sw.packages[ssh]  // 已安裝軟件列表
[rpm] libssh2-1.8.0-3.el7.x86_64, openssh-7.4p1-21.el7.x86_64, openssh-clients-7.4p1-21.el7.x86_64, openssh-server-7.4p1-21.el7.x86_64

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.uname
Linux localhost.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.uptime
4438   // 系統運行時長(秒)多少秒使用s/uptime來獲取

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.users.num
0    // 登陸用戶數

zabbix_get.exe -s 192.168.1.20 -p 10050 -k kernel.maxfiles
96437  // 系統支持最大的open files整數

zabbix_get.exe -s 192.168.1.20 -p 10050 -k kernel.maxproc
65536  // 系統支持最大進程數

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.hw.macaddr
[ens32] 00:50:56:22:6f:d3   // mac 地址列表

>zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.sw.os
Linux version 3.10.0-1062.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Wed Aug 7 18:08:02 UTC 2019   // 操作系統信息

允許遠程執行命令:

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
EnableRemoteCommands=1
[root@localhost ~]# systemctl restart zabbix-agent

D:\zabbix> zabbix_get.exe -s 192.168.1.20 -p 10050 -k "system.run[df -h]"
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 480M     0  480M   0% /dev
tmpfs                    491M     0  491M   0% /dev/shm
tmpfs                    491M  7.4M  484M   2% /run
tmpfs                    491M     0  491M   0% /sys/fs/cgroup
/dev/mapper/centos-root   27G  1.7G   26G   7% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     99M     0   99M   0% /run/user/0

監控CPU

system.cpu.util[<cpu>,<type>,<mode>]

-CPU:  CPU數量(默認是所有CPU)
-Type: 可用值,idle,nice,user,system,iowait,interrupt,sottrq,steal
-Mode  可用值,avg1(一分鍾負載),avg5,avg15

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k system.cpu.util[,,avg1]
0.016692

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.cpu.num
1   // cpu 個數

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.cpu.util
0.016461  // cpu 利用率百分比

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.hw.cpu  // cpu 詳細信息
processor 0: GenuineIntel Intel(R) Celeron(R) CPU        E3500  @ 2.70GHz working at 2700MHz

監控內存

proc.mem[<name>,<user>,<mode>,<cmdline>,<memtype>]

-name    進程名(默認所有進程)
-user    用戶名(默認所有用戶)
-mode    可選值,avg,max,min,sum
-cmdline 命令過濾

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k proc.mem[httpd,,,]
1376378880
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k proc.mem[]
6479925248

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.swap.in
0      // Swap in (f內存到磁盤) .數字

zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.swap.out
0  //Swap out (f內存到磁盤) .數字
zabbix_get.exe -s 192.168.1.20 -p 10050 -k system.swap.size
2147479552  // 交換分區大小字節或者百分比


mode - total (默認), active, anon, buffers, cached, exec, file, free, inactive, pinned, shared, wired, used, pused, available
zabbix_get.exe -s 192.168.1.20 -p 10050 -k vm.memory.size[free]
598949888   // 監控內存變化

監控網卡

net.if.in [if,<mode>]       #網卡入口流量
net.if.out [if,<mode>]      #網卡出口流量
net.if.total [if,<mode>]    #網卡進/出流量總和

-if    網卡名稱
-mode  可用值(如下)

       bytes    字節數
       packets  包數量
       errors   錯誤數量
       droppend 丟包數量

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k net.if.in[ens32,bytes]
165983
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k net.if.in[ens32,packets]
2166
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k net.if.out[ens32,packets]
2067
[root@localhost ~]# zabbix_get.exe -s 192.168.1.20 -p 10050 -k net.if.discovery
[{"{#IFNAME}":"ens32"},{"{#IFNAME}":"lo"}]  // 列出系統網卡信息
zabbix_get.exe -s 192.168.1.20 -p 10050 -k net.if.total[ens32]
20785083           // 列出網卡總流量

zabbix_get.exe -s 192.168.1.20 -p 10050 -k net.tcp.listen[10050]
1             // 檢測指定端口是否開啟

zabbix_get.exe -s 192.168.1.20 -p 10050 -k net.tcp.port[,80]
0             // 檢測本機web服務是否開啟

zabbix_get.exe -s 192.168.1.20 -p 10050 -k net.tcp.service[ssh,,22]
1            // 檢測是定服務是否在運行

監控IO/讀寫

vfs.dev.read [<device>,<type>,<mode>]    #磁盤讀取
vfs.dev.write [<device>,<type>,<mode>]   #磁盤寫入

-device   磁盤設備(默認all)
-type     sectors,operations,bytes,sps,ops,hps
-mode     默認有(avg1,avg5,avg15)

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.read[/dev/sda,,avg1]
0.000000
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.read[all]
195.200000
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.read[all,,avg1]
195.200000
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.read[all,,avg5]
177.758242
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.write[all,,avg5]
465.284483
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.write[all,,avg1]
877.200000
[root@localhost ~]# zabbix_get -s 192.168.1.25 -k vfs.dev.write[/dev/sda,,]
374.800000

文件操作:

zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.file.exists[/etc/passwd]
1   // 檢測指定文件是否存在

zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.file.md5sum[/etc/passwd]
52f5db4f5688b79b9c07ef5a42ea29af  // md5驗證

zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.file.size[/etc/passwd]
870   // 文件大小字節數

zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.file.time[/etc/passwd]
1578566854  // 文件日期時間戳

zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.fs.discovery  // 列出文件系統所有目錄結構
[{"{#FSNAME}":"/","{#FSTYPE}":"rootfs"},{"{#FSNAME}":"/sys","{#FSTYPE}":"sysfs"},{"{#FSNAME}":"/proc","{#FSTYPE}":"proc"},{"{#FSNAME}":"/dev","{#FSTYPE}":"devtmpfs"},{"{#FSNAME}":"/sys/kernel/security","{#FSTYPE}":"securityfs"},{"{#FSNAME}":"/dev/shm"}]

mode - total (默認), free, used, pfree (空閑百分比), pused (使用百分比)
zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.fs.inode[/dev,free]
122355 // 檢測/dev/空閑空間

zabbix_get.exe -s 192.168.1.20 -p 10050 -k vfs.fs.size[/dev,free]
502525952  // 磁盤空間,返回本地文件系統的使用量字節

## 監控web頁狀態

首先在被控主機安裝httpd服務,並設置好一個頁面.

[root@localhost ~]# yum install -y httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package httpd-2.4.6-88.el7.centos.x86_64 already installed and latest version
Nothing to do

[root@localhost ~]# echo "hello world" > /var/www/html/index.html
[root@localhost ~]# systemctl restart httpd

監控主機選擇 主機->web場景->創建web場景->步驟->網頁狀態.

此時,配置web監控就完成啦,很簡單吧,下面繼續來看一下自定義key的使用步驟吧.

自定義一個Key

1.下面我們來自定義一個Key來實現監控兩個服務,這里我們先寫一個腳本,腳本有一個參數當傳入http時,返回http的進程數量,當傳入system參數時,顯示系統的總進程數,此處實在客戶端操作的.

#!/bin/bash

num=$1

if [ $num == "http" ]
then
        ps aux |grep -v "grep" |grep "http" |wc -l
fi
if [ $num == "system" ]
then
        ps aux |wc -l
fi

[root@localhost ~]# chmod 777 -R shell.sh
[root@localhost ~]# bash shell.sh http
7
[root@localhost ~]# bash shell.sh system
192

2.將我們的腳本放入自定義目錄,並設置zabbix添加一個key.

[root@localhost ~]# cp -a shell.sh  /etc/shell.sh
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf

UnsafeUserParameters=1
UserParameter=shell.shell[*],/etc/shell.sh \$1

[root@localhost ~]# systemctl restart zabbix-agent

3.在zabbix服務端通過zabbix-get命令測試一下效果.

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k shell.shell[http]
7

[root@localhost ~]# zabbix_get -s 192.168.1.25 -k shell.shell[system]
192

4.去web頁面配置一下就可以了,很簡單吧

主機->監控項->創建監控項

主機->圖形->創建圖形


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM