AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 630320
Accepted
Ole Tange
Ole Tange
Asked: 2014-09-23 05:46:42 +0800 CST2014-09-23 05:46:42 +0800 CST 2014-09-23 05:46:42 +0800 CST

Zabbix:接口值的最大值

  • 772

我使用“模板 SMNP 接口”来监控交换机。

它给了我这样的键: ifOutOctets[16]

我想要一个涵盖所有端口的项目:

MaxOutOctets = max(ifOutOctets[*])

我可以在图表中使用。

我已阅读 https://www.zabbix.com/documentation/2.2/manual/config/items/itemtypes/calculated 但我似乎无法获得正确的语法。

zabbix
  • 2 2 个回答
  • 1080 Views

2 个回答

  • Voted
  1. Ole Tange
    2014-10-01T03:18:11+08:002014-10-01T03:18:11+08:00

    解决方法(其他人可能会觉得有帮助):

    #!/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;
    }
    
    • 1
  2. Best Answer
    asaveljevs
    2014-09-23T06:55:24+08:002014-09-23T06:55:24+08:00

    不幸的是,您所寻求的目前无法开箱即用,但有一个功能要求:ZBXNEXT-1829。请求ZBXNEXT-1420和ZBXNEXT-1521也是相关的。

    • 0

相关问题

  • Zabbix 是否对一段时间内的数据求和?

  • Zabbix 是适合我的工具吗?

  • 启动 Zabbix 服务器的问题

  • 有没有监控托管解决方案?[关闭]

  • zabbix 的 LAMP 监控

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve