zabbix添加自定义监控项

添加自定义监控项遇到的坑1: 普通用户执行脚本没有权限

 

 

 

 

systemctl restart zabbix-agent

 

 

 

以下整理了部分zabbix监控模板的监控指标,以供参考,后续还会详细整理其他性能监控指标。

一、监控cpu,内存,网络等(Template OS Linux (Template App Zabbix Agent))

cpu

CPU jumps

Context switches per second 每秒上下文切换

CPU usage

CPU guest nice time

CPU guest time

CPU softirq time 系统在处理软中断时候所花费的CPU时间

CPU interrupt time CPU中断时间

CPU steal time CPU被强制等待另外虚拟的CPU处理完毕花费的时间

CPU iowait time CPU花费在等待I/O操作上的时间

CPU nice time 系统花费在调整进程优先级上的时间

CPU user time CPU在用户态执行进程的时间

CPU system time CPU在内核运行的时间

CPU utilization

CPU utilization

CPU idle time CPU空闲时间

Interrupts per second 每秒中断

Processor load (1 min average per core) 处理器负载(每个核心平均1分钟)

Processor load (5 min average per core) 处理器负载(每个核心平均5分钟)

Processor load (15 min average per core) 处理器负载(每个核心平均15分钟)

Filesystems

Free disk space on / /可用磁盘空间

Free disk space on / (percentage) /可用磁盘空间/(百分比)

Free disk space on /boot /boot上的可用磁盘空间

Free disk space on /boot (percentage) /boot上的可用磁盘空间(百分比)

Free inodes on / (percentage) /上的剩余inode(百分比)

Free inodes on /boot (percentage) /boot上的剩余inode(百分比)

Total disk space on / /上的总磁盘空间

Total disk space on /boot /boot上的总磁盘空间

Used disk space on / /使用的磁盘空间

Used disk space on /boot / boot上使用的磁盘空间

General(一般)

Host boot time 主机启动时间

Host local time 主机本地时间

Host name 主机名

System information 系统信息

System uptime 系统正常运行时间

Network interfaces(网络)

Incoming network traffic on ens32 ens32的传入网络流量

Outgoing network traffic on ens32 ens32的传出网络流量

Interface eth0: Bits received

Interface eth0: Bits sent

Interface eth0: Outbound packets with errors

Interface eth0: Inbound packets with errors

Interface eth0: Outbound packets discarded

Interface eth0: Inbound packets discarded

Memory(内存)

Available memory 可用内存

Free swap space 剩余swap空间

Free swap space in % 剩余swap空间百分比

Total memory 总内存

Total swap space 总swap空间

Processes(进程)

Number of processes 进程数

Number of running processes 正在运行的进程数

Security(安全)

Checksum of /etc/passwd / etc / passwd的校验和

Number of logged in users 登录用户数

Zabbix agent

Agent ping 代理ping

Host name of zabbix_agentd running 运行zabbix_agentd的主机名

Version of zabbix_agent(d) running zabbix_agent(d)版本正在运行

 

二、监控mysql(Template DB MySQL)

MySQL begin operations per second MySQL每秒开始运算

MySQL bytes received per second 每秒接收的MySQL字节数

MySQL bytes sent per second 每秒发送的MySQL字节数

MySQL commit operations per second 每秒MySQL提交操作

MySQL delete operations per second MySQL每秒删除操作数

MySQL insert operations per second MySQL每秒插入操作数

MySQL queries per second 每秒MySQL查询

MySQL rollback operations per second 每秒MySQL回滚操作

MySQL select operations per second MySQL每秒选择操作

MySQL slow queries MySQL慢查询

MySQL status MySQL状态

MySQL update operations per second 每秒MySQL更新操作

MySQL uptime MySQL正常运行时间

MySQL version MySQL版本

Template Percona MySQL Server(percona插件模板)

三、监控docker状态(Template App Docker - www.monitoringartist.com(外部模板))

docker(jms为docker容器名)

Container jms is running Container jms正在运行

CPU utilization jms CPU利用率jms

Used cache memory jms 使用的缓存内存jms

Used swap jms 使用交换jms

 

 

 

 

 

下面是几个与CPU占用率相关的概念。

CPU利用率:CPU的使用情况。
用户时间(User time) :表示CPU执行用户进程的时间,包括nices时间。通常期望用户空间CPU越高越好。
系统时间(System time) :表示CPU在内核运行时间,包括IRQ和softirq时间。系统CPU占用率高,表明系统某部分存在瓶颈。通常值越低越好。
等待时间(Waiting time) :CPU在等待I/O操作完成所花费的时间。系统不应该花费大量时间来等待I/O操作,否则就说明I/O存在瓶颈。
空闲时间(Idle time) :系统处于空闲期,等待进程运行。
Nice时间(Nice time) :系统调整进程优先级所花费的时间。
硬中断处理时间(Hard Irq time) :系统处理硬中断所花费的时间。
软中断处理时间(SoftIrq time) :系统处理软中断中断所花费的时间。
丢失时间(Steal time) :被强制等待(involuntary wait)虚拟CPU的时间,此时hypervisor在为另一个虚拟处理器服务。

 

top命令看到的CPU占用率信息及各项值含义。

Cpu(s): 0.2%us, 0.2%sy, 0.0%ni, 99.2%id, 0.5%wa, 0.0%hi, 0.0%si, 0.0%st
us: User time,用户态使用的cpu时间比。CPU一共花了多少比例的时间运行在用户态空间或者说是用户进程(running user space processes)。典型的用户态空间程序有:Shell、数据库、web服务器。
sy: System time,系统态使用的cpu时间比。System的含义与User相似。System表示:CPU花了多少比例的时间在内核空间运行。分配内存、IO操作、创建子进程……都是内核操作。这也表明,当IO操作频繁时,System参数会很高。
ni: Nice time,用做nice加权的进程分配的用户态cpu时间比。用户空间进程的CPU的调度优先级,范围为[-20,19]。每个linux进程都有个优先级,优先级高的进程有优先执行的权利,这个叫做pri。进程除了优先级外,还有个优先级的修正值。即比如你原先的优先级是20,然后修正值为-2,那么你最后的进程优先级为18。这个修正值就叫做进程的nice值。
id: Idle time,空闲的cpu时间比。一般而言,idel + user + nice 约等于100%。
wa: Waiting time,cpu等待磁盘写入完成时间。在计算机中,读写磁盘的操作远比CPU运行的速度要慢,CPU负载处理数据,而数据一般在磁盘上需要读到内存中才能处理。当CPU发起读写操作后,需要等着磁盘驱动器将数据读入内存,从而导致CPU 在等待的这一段时间内无事可做。CPU处于这种等待状态的时间由Wait参数来衡量。所以如果一台机器看到wa特别高,那么一般说明是磁盘IO出现问题。
hi: Hard Irq time,硬中断消耗时间
si: SoftIrq time,软中断消耗时间
如果程序都没什么问题,那么是没有hi和si的,但是实际上有个硬中断和软中断的概念。比如硬中断,cpu在执行程序的时候,突然外设硬件(比如硬盘出现问题了)机器需要立刻通知cpu进行现场保存工作。这个时候会cpu会出现上下文切换。就是cpu会有一部分时间会被硬中断占用了,这个时间就是hi。相类似,si是软中断的cpu占用时间,软中断是由软件的指令方式触发的。
st: Steal time,虚拟机偷取时间。对虚拟机来说的,一台物理是可以虚拟化出几台虚拟机的。在其中一台虚拟机上用top查看发现st不为0,就说明本来有这么多个cpu时间是安排给这个虚拟机的,但是由于某种虚拟技术,把这个cpu时间分配给了其他的虚拟机了。这就叫做偷取。

CPU占用率计算:

Linux CPU占用率计算,都是根据/proc/stat文件内容计算而来。

 

怎么查看CPU Steal Time?#

st即 Steal Time, top命令 可以很容易地检测guest VM 实例上的 CPU Steal Time。窃取时间显示在第 3 行末尾的 top 输出中,其中存在%Cpu(s),如下面的截图所示(它是末尾的值,标记为st。)这个示例中我把两个核心的CPU Stell Time 百分比都显示出来了,它们都为 0 ,top默认只显示综合指标。

CPU Steal Time

监控系统上CPU Steal Time

zabbix CPU Steal Time

CPU Steal Time 的定义#

From ibm :

Steal time is the percentage of time a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor.

From opensource.com :

CPU steal time is defined in the [GNU **top**](https://en.wikipedia.org/wiki/Top_(software)) command as "time stolen from [a] VM by the hypervisor." CPU steal time occurs when a hypervisor process and a guest instance are trying to utilize the same hypervisor physical core (pCPU) at the same time. This results in less processor time available to the guest's virtual CPU (vCPU) and performance degradation for the guest.

通俗来讲,我们的虚拟机(VM)会与虚拟环境的宿主机上的多个虚拟机实例共享物理物理CPU资源,也就是共享CPU时间切片。如果多个虚机竞争物理CPU资源,则某些 guest 主机可能在某段时间内需要等待 pCPU 作出响应,这个等待的时间就是 Steal time。

在当今的虚拟化环境(如公有云和私有云)中,guest 实例可能会在以下几种情况下体验性能 CPU 窃取时间:

  • 虚拟机管理程序(hypervisor)的超额分配和具有高 CPU 利用率的多个guest VM 的 vCPU 正在相同的 pCPU 上运行。
  • guest vCPU 及其仿真器线程被固定到同一个 pCPU,导致 vhost 进程在处理 I/O 时从guestvCPU 窃取 CPU 时间。
  • 虚拟机监控程序进程(如监控、日志记录和 I/O 进程)同时使用一个 pCPU,而guest VM vCPU 也在使用该 pCPU。

如何判断 st#

如果你的应用部署虚拟环境, steal time就是你想要关注的性能指标之一。 如果这个指标的数值很高,那么说明机器状态非常糟糕。大体判断标准:

CPU窃取时间低:如果您的 CPU 窃取时间低于 10%,则无需担心。您的应用程序应该可以顺利运行。

CPU窃取时间相对较高:您的 CPU 窃取时间远远超过 10%,持续约 30 分钟。当这种情况发生:

1、迁移虚拟机到另一台物理机器上面。
2、如果steal time维持在很高的数值, 那么增加CPU资源配额。
3、对性能要求高的应用可购买独享型云主机。

 

 

 

 

 

 user(通常缩写为us),代表用户态CPU时间。注意,它不包括下面的nice时间,但包括了guest时间。nice(通常缩写为ni),代表低优先级用户态CPU时间,也就是进程nice值被调整为1-19之间的CPU时间。这里注意,nice可取值范围是-20到19,数值越大,优先级反而越低。

system(通常缩写为sys),代表内核态CPU时间。

idle (通常缩写为id),代表空闲时间,注意,它不包括等待I/O的时间(iowait)。

iowait(通常缩写为wa),代表等待I/O的CPU时间。

irq(通常缩写为hi),代表处理硬中断的CPU时间。

softirq(通常缩写为si),代表处理软中断的CPU时间。

steal(通常缩写为st),代表当系统运行在虚拟机中的时候,被其他虚拟机占用的CPU时间。

guest (通常缩写为guest),代表通过虚拟化运行其他操作系统的时间,也就是运行虚拟机的CPU时间。

guest_nice (通常缩写为gnice),代表以低优先级运行虚拟机的时间。########### 上面为普通监控项:

  •  

     

     

     

     

     

     

     尝试监控tps:

     

     

    iostat |awk '$1~/sda/{print $2}'
    1.99

  •  

     agent配置监控项

     

     UserParameter=sda_tps,iostat | awk '$1~/sda/{print $2}'

  • systemctl restart zabbix-agent

  •  

    server端测试监控项

    wget https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-get-4.0.11-1.el7.x86_64.rpm --no-check-certificat 

  •  

     

    [root@zabbix-server ~]# rpm -ivh zabbix-get-4.0.11-1.el7.x86_64.rpm
    Preparing... ################################# [100%]
    Updating / installing...
    1:zabbix-get-4.0.11-1.el7 ################################# [100%]

    [root@zabbix-server ~]# zabbix_
    zabbix_get zabbix_server zabbix_server_mysql
    [root@zabbix-server ~]# zabbix_get -s 127.0.0.1 -k sda_tps  #监控主机地址不通导致的,检查IP地址是否正确
    zabbix_get [2625]: Get value error: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused
    [root@zabbix-server ~]# zabbix_get -s 192.168.8.101 -k sda_tps    #监控成功,获得了sda_tps的值
    1.57
    [root@zabbix-server ~]# zabbix_get -s 192.168.8.101 -k sda_tsgfsg  #是写错了,key的值
    ZBX_NOTSUPPORTED: Unsupported item key.

  •  

    在web界面添加自定义监控项

  •  

     

     

     

     

     

     

     

     

     

     

     再去看是否能监测到数据:

  • 监测   。。。。。。。。。。最新数据
  •  

     应该选的是被监控的主机群组shop  192.168.8.101   过滤一下新的监控项名称关键字:硬盘(硬盘sda每秒的传输次数)

  •  

     效果如下:

  •  

     

posted @ 2023-03-30 20:12  往事已成昨天  阅读(618)  评论(0编辑  收藏  举报