Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: snmptop utility. #142

Merged
merged 9 commits into from
Jul 15, 2017
Next Next commit
Added: sketch for snmptop utility.
  • Loading branch information
strizhechenko committed Jul 15, 2017
commit 10d32f386fa127b67d1a5b307ab421a041cd3338
39 changes: 39 additions & 0 deletions netutils_linux_monitoring/snmptop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding=utf-8

import json
from six import print_
from netutils_linux_monitoring.base_top import BaseTop


class SnmpTop(BaseTop):
@staticmethod
def make_parser(parser=None):
if not parser:
parser = BaseTop.make_parser()
parser.add_argument('--snmp-file', default='/proc/net/snmp',
help='Option for testing on MacOS purpose.')
return parser

def __int(self, line):
return [self.int(item) for item in line.strip().split()]

def parse(self):
with open(self.options.snmp_file) as file_fd:
lines = file_fd.readlines()
return {
"IP": dict(zip(lines[0].split()[1:], lines[1].split()[1:])),
"ICMP": dict(zip(lines[2].split()[1:], lines[3].split()[1:])),
"TCP": dict(zip(lines[6].split()[3:], lines[7].split()[1:])),
"UDP": dict(zip(lines[8].split()[3:], lines[9].split()[1:])),
}


def __repr__(self):
return json.dumps(self.parse(), indent=4)

if __name__ == '__main__':
import sys
sys.argv = [sys.argv[0], '--snmp-file=tests/proc_net_snmp/snmp1']
top = SnmpTop()
top.options = top.make_parser().parse_args()
print_(top)
12 changes: 12 additions & 0 deletions tests/proc_net_snmp/snmp1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates
Ip: 1 64 22199703066 64 0 3991292426 3 0 18205118253 20899686159 1183 0 5 5 0 5 8 0 16
Icmp: InMsgs InErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps
Icmp: 17864682 762911 13469164 11533 0 53 7 4361700 21720 7 0 0 0 27650690 0 23265781 52 0 0 0 23150 4361700 0 7 0 0
IcmpMsg: InType0 InType3 InType4 InType5 InType8 InType11 InType13 OutType0 OutType3 OutType8 OutType11 OutType14
IcmpMsg: 21720 13469164 53 7 4361700 11533 7 4361700 23265781 23150 52 7
Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts
Tcp: 1 200 120000 -1 1144887168 1265503546 23608568 26172378 77 17669927663 16338441124 133674663 167169 53028318
Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
Udp: 494467706 14809371 76 319088 0 0
UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
UdpLite: 0 0 0 0 0 0
12 changes: 12 additions & 0 deletions tests/proc_net_snmp/snmp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates
Ip: 1 64 22199717960 64 0 3991292567 3 0 18205133002 20899699894 1183 0 5 5 0 5 8 0 16
Icmp: InMsgs InErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps
Icmp: 17864706 762912 13469188 11533 0 53 7 4361700 21720 7 0 0 0 27650753 0 23265844 52 0 0 0 23150 4361700 0 7 0 0
IcmpMsg: InType0 InType3 InType4 InType5 InType8 InType11 InType13 OutType0 OutType3 OutType8 OutType11 OutType14
IcmpMsg: 21720 13469188 53 7 4361700 11533 7 4361700 23265844 23150 52 7
Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts
Tcp: 1 200 120000 -1 1144887961 1265504683 23608597 26172379 79 17669942271 16338454400 133674769 167169 53028393
Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
Udp: 494467738 14809443 76 319088 0 0
UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
UdpLite: 0 0 0 0 0 0