zabbix自动磁盘IO和TCP监控

2023年 7月 15日 74.2k 0

监控磁盘io发现脚本脚本内容:

#!/usr/bin/perl
# -------------------------------------------------------------------------------
# Filename:    disk i/o
# Revision:    1.1
# Date:        20160707
# Author:      mark
# Email:       usertzc@163.com
# Website:     www.linuxea.com
# -------------------------------------------------------------------------------
# Notice
# Apply zabbix version 2.4.x to 3.0.3 
# auto search disk i/o
#################################################################################

sub get_vmname_by_id
 {
 $vmname=`cat /etc/qemu-server/$_[0].conf | grep name | cut -d : -f 2`;
 $vmname =~ s/^s+//;
 $vmname =~ s/s+$//;
return $vmname
 }
$first = 1;
print "{n";
print "t"data":[nn";
 
for (`cat /proc/diskstats`)
  {
  ($major,$minor,$disk) = m/^s*([0-9]+)s+([0-9]+)s+(S+)s.*$/;
  $dmnamefile = "/sys/dev/block/$major:$minor/dm/name";
  $vmid= "";
  $vmname = "";
  $dmname = $disk;
  $diskdev = "/dev/$disk";

 if (-e $dmnamefile) {
    $dmname = `cat $dmnamefile`;
    $dmname =~ s/n$//; #remove trailing n
    $diskdev = "/dev/mapper/$dmname";

    if ($dmname =~ m/^.*--([0-9]+)--.*$/) {
    $vmid = $1;
    
                 }
     }

print "t,n" if not $first;
  $first = 0;
 
  print "t{n";
  print "tt"{#DISK}":"$disk",n";
  print "tt"{#DMNAME}":"$dmname",n";
  print "tt"{#VMNAME}":"$vmname",n";
  print "tt"{#VMID}":"$vmid"n";
  print "t}n";
  }
 
print "nt]n";
print "}n";

UserParameter:

UserParameter=discovery.disks.iostats,/etc/zabbix/scripts/disk.pl
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}'
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}'
UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 |awk '{print $$4}'
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}'
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}'
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}'

disk io.pngtcp监控:计划任务中添加:

*/1 * * * * /usr/sbin/ss  -tan|awk 'NR>1{++S[$1]}END{for (a in S) print a,S[a]}' > /tmp/tcp-status.txt
*/1 * * * * /usr/sbin/ss -o state established '( dport = :http or sport = :http )' |grep -v Netid > /tmp/httpNUB.txt

UserParameter:

UserParameter=tcp.status[*],awk '{if ($$1~/^$1/)print $$2}' /tmp/tcp-status.txt
UserParameter=tcp.httpd_established,awk 'NR>1' /tmp/httpNUB.txt|wc -l

tcp.png模板下载地址密码:5zhu

相关文章

对接alertmanager创建钉钉卡片(1)
手把手教你搭建OpenFalcon监控系统
无需任何魔法即可使用 Ansible 的神奇变量“hostvars”
openobseve HA本地单集群模式
基于k8s上loggie/vector/openobserve日志收集
openobseve单节点和查询语法

发布评论