From 61fc79ff47dc5f8fd15b8af7772e51cb2de9ddb6 Mon Sep 17 00:00:00 2001 From: UlricQin Date: Mon, 1 Jun 2020 16:36:12 +0800 Subject: [PATCH] add snmp funcs --- src/modules/collector/sys/funcs/funcs.go | 2 ++ src/modules/collector/sys/funcs/snmp.go | 43 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/modules/collector/sys/funcs/snmp.go diff --git a/src/modules/collector/sys/funcs/funcs.go b/src/modules/collector/sys/funcs/funcs.go index 7ef8c46d..dc14a7be 100644 --- a/src/modules/collector/sys/funcs/funcs.go +++ b/src/modules/collector/sys/funcs/funcs.go @@ -30,6 +30,8 @@ func BuildMappers() { EntityNumMetrics, NtpOffsetMetrics, SocketStatSummaryMetrics, + UdpMetrics, + TcpMetrics, }, Interval: interval, }, diff --git a/src/modules/collector/sys/funcs/snmp.go b/src/modules/collector/sys/funcs/snmp.go new file mode 100644 index 00000000..2773864a --- /dev/null +++ b/src/modules/collector/sys/funcs/snmp.go @@ -0,0 +1,43 @@ +package funcs + +import ( + "github.com/toolkits/pkg/logger" + "github.com/toolkits/pkg/nux" + + "github.com/didi/nightingale/src/dataobj" +) + +func UdpMetrics() []*dataobj.MetricValue { + udp, err := nux.Snmp("Udp") + if err != nil { + logger.Errorf("failed to collect UdpMetrics:%v\n", err) + return []*dataobj.MetricValue{} + } + + count := len(udp) + ret := make([]*dataobj.MetricValue, count) + i := 0 + for key, val := range udp { + ret[i] = GaugeValue("snmp.Udp."+key,val) + i++ + } + + return ret +} +func TcpMetrics() []*dataobj.MetricValue { + tcp, err := nux.Snmp("Tcp") + if err != nil { + logger.Errorf("failed to collect TcpMetrics:%v\n", err) + return []*dataobj.MetricValue{} + } + + count := len(tcp) + ret := make([]*dataobj.MetricValue, count) + i := 0 + for key, val := range tcp { + ret[i] = GaugeValue("snmp.Tcp."+key,val) + i++ + } + + return ret +} \ No newline at end of file