add snmp funcs

This commit is contained in:
UlricQin 2020-06-01 16:36:12 +08:00
parent 7dfefedf77
commit 61fc79ff47
2 changed files with 45 additions and 0 deletions

View File

@ -30,6 +30,8 @@ func BuildMappers() {
EntityNumMetrics, EntityNumMetrics,
NtpOffsetMetrics, NtpOffsetMetrics,
SocketStatSummaryMetrics, SocketStatSummaryMetrics,
UdpMetrics,
TcpMetrics,
}, },
Interval: interval, Interval: interval,
}, },

View File

@ -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
}