交换机监控(swcollector)

这个插件提供了通过 SNMP 收集交换机性能指标的的功能

插件文件地址
swcollector
插件类型
接受参数,持续执行(Step 周期须指定为 0

插件参数

参数 功能 默认值
interval 收集间隔 30 s
logFile 日志文件路径,运行日志会输出到这里 ""
ipRange 交换机 IP 地址段 [1] []
pingTimeout Ping 超时时间 300 ms
pingRetry Ping 探测重试次数 4
snmpCommunity SNMP 认证字符串 "public"
snmpTimeout SNMP超时时间 1000 ms
snmpRetry SNMP重试次数 5
gosnmp 是否使用 gosnmp 采集, 否则使用 snmpwalk true
concurrentCollectors 采集的并发限制 1000
concurrentQueriesPerHost 单台机器多指标的采集并发限制 4
fastPingMode 快速 Ping 模式 true
reverseLookup 通过 DNS 反向解析交换机的 hostname false
ignore 忽略的采集指标(见下文) []
ignoreIface 忽略的接口 [2] ["Nu","NU","Vlan","Vl"]
customMetrics 自定义监控项(见下文) []
customHosts 自定义 IP -> hostname 映射 [3] {}
[1]对该网段有效 IP,先发 Ping 包探测,对存活 IP 发送 SNMP 请求, 形如 ["192.168.1.1", "192.168.2.1-192.168.2.233", "172.16.123.0/24"]
[2]Nu 匹配 ifName 为 *Nu* 的接口
[3]形如 {"192.168.1.1": "router1"}

ignore 是形如 ["broadcasts", "multicasts"] 的 list,具体定义如下:

ignore 项 忽略指标
operstatus switch.if.OperStatus
packets switch.if.InPkts switch.if.OutPkts
broadcasts switch.if.InBroadcastPkt switch.if.OutBroadcastPkt
multicasts switch.if.InMulticastPkt switch.if.OutMulticastPkt
discards switch.if.InDiscards switch.if.OutDiscards
errors switch.if.InErrors switch.if.OutErrors
unknownprotos switch.if.InUnknownProtos
qlen switch.if.OutQLen
speed switch.if.Speed
octets switch.if.In switch.if.Out

customMetrics 是一个 list,list 元素具体定义如下:

customMetric 项 意义
ipRange 对该 ip 范围启用该自定义监控项 [4]
metric 自定义监控项的名称
oid 监控项的 OID
tags 监控项附加的 tags
[4]与第一层配置中的 ipRange 格式相同

自定义的 oid 只支持 snmp get 方式采集,因此务必填写完整,建议先通过 snmpwalk 验证一下。

上报的监控值

switch.CollectTime
意义:单个交换机收集指标所用的时间
单位:ms
取值:-1.0,或者 (0.0, +Inf)
说明:取值 -1.0 说明收集出错或超时
switch.Ping
意义:Ping RTT
单位:ms
取值:-1.0,或者 (0.0, +Inf)
说明:取值 -1.0 说明 Ping 出错或超时
switch.if.OperStatus
意义:接口状态
取值:[1-7]
Tags:{"ifName": "接口名", "ifIndex": 接口序号 }
取值 意义
1 up
2 down
3 testing
4 unknown
5 dormant
6 notPresent
7 lowerLayerDown

剩余的指标意义明显,不再解释了

监控规则样例

(def swcollector-rules
  (sdo
    (where (host "host-which-runs-swcollector")
      (plugin "swcollector" 0
        {:interval 30
         :snmpCommunity "Your-snmp-community!"
         :ignore [:multicasts :unknownprotos]
         :ipRange ["192.168.10.1-192.168.10.100" "192.168.20.1-192.168.20.100"]
         :reverseLookup true
         :customMetrics [{:metric "switch.AnyconnectSession"
                          :oid "1.3.6.1.4.1.9.9.392.1.3.35.0"
                          :ipRange ["192.168.10.1-192.168.10.100"]
                          :tags {}}
                         {:metric "switch.ConnectionStat"
                          :oid "1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6"
                          :ipRange ["192.168.20.1-192.168.20.100"]
                          :tags {}}]}))

    (where (service "switch.if.OperStatus")
      (by [:host :ifName]
        (adjust [:metric int]
          (judge (!= 1)
            (runs 2 :state
              (alarm-every 5 :min
                (! {:note "交换机接口挂掉了"
                    :level 3
                    :groups [:operation]})))))))))