Zabbix
Zabbix:介面值的最大值
我使用“模板 SMNP 介面”來監控交換機。
它給了我這樣的鍵: ifOutOctets
$$ 16 $$ 我想要一個涵蓋所有埠的項目:
MaxOutOctets = max(ifOutOctets[*])
我可以在圖表中使用。
我已閱讀 https://www.zabbix.com/documentation/2.2/manual/config/items/itemtypes/calculated 但我似乎無法獲得正確的語法。
不幸的是,您所尋求的目前無法開箱即用,但有一個功能要求:ZBXNEXT-1829。請求ZBXNEXT-1420和ZBXNEXT-1521也是相關的。
解決方法(其他人可能會覺得有幫助):
#!/usr/bin/perl # This program reads off traffic from a switch by SNMP. # It compares the values with last run and returns the value of the port with the biggest change # # Usage: # snmp_max_io 192.168.1.1 # # (C) 2014-09-29 Ole Tange # License: GPLv3 my $switch = shift; my ($last,$this) = update_cache_file($switch); my %delta = delta($last,$this); my $max = max(values %delta); print "$max\n"; `logger $0 $switch returned $max`; sub delta { my ($last,$this) = @_; # IF-MIB::ifHCOutOctets.45 = Counter64: 262606806485 my %last = map { split /: /,$_ } grep /Counter/, @$last; my %this = map { split /: /,$_ } grep /Counter/, @$this; my %delta = map { $_ => undef_as_zero($this{$_}) - undef_as_zero($last{$_}) } keys %last, keys %this; return %delta; } sub undef_as_zero { my $a = shift; return $a ? $a : 0; } sub my_dump { # Returns: # ascii expression of object if Data::Dump(er) is installed # error code otherwise my @dump_this = (@_); eval "use Data::Dump qw(dump);"; if ($@) { # Data::Dump not installed eval "use Data::Dumper;"; if ($@) { my $err = "Neither Data::Dump nor Data::Dumper is installed\n". "Not dumping output\n"; print $Global::original_stderr $err; return $err; } else { return Dumper(@dump_this); } } else { # Create a dummy Data::Dump:dump as Hans Schou sometimes has # it undefined eval "sub Data::Dump:dump {}"; eval "use Data::Dump qw(dump);"; return (Data::Dump::dump(@dump_this)); } } sub update_cache_file { # Input: # $switch = DNS name or IP address of switch my $switch = shift; my $tmpdir = "/tmp/switch-$ENV{USER}"; my $tmpfile = "$tmpdir/snmp_last_$switch"; mkdir $tmpdir; chmod 0700, $tmpdir || die; my @last = `cat $tmpfile 2>/dev/null`; my @this = snmpget_io($switch); open(OUT,">",$tmpfile) || die; print OUT @this; close OUT; if(not @last) { @last = @this; } return (\@last,\@this); } sub snmpget_io { # Input: # $switch = DNS name or IP address of switch my $switch = shift; # Requires snmp-mibs-downloader installed return qx{ bash -c 'snmpget -v 2c -c public $switch IF-MIB::ifHCInOctets.{1..60}; snmpget -v 2c -c public $switch IF-MIB::ifHCOutOctets.{1..60};' } } sub max { # Returns: # Maximum value of array my $max; for (@_) { # Skip undefs defined $_ or next; defined $max or do { $max = $_; next; }; # Set $_ to the first non-undef $max = ($max > $_) ? $max : $_; } return $max; }