root / plugins / network / sockstat-via-procfs @ 8589c6df
Historique | Voir | Annoter | Télécharger (950 octets)
| 1 | 2b6faa67 | Xupeng Yun | #!/usr/bin/env python |
|---|---|---|---|
| 2 | |||
| 3 | import re |
||
| 4 | import sys |
||
| 5 | |||
| 6 | fields = ( |
||
| 7 | ('sockets_used', 'sockets used'),
|
||
| 8 | ('tcp_inuse', 'TCP inuse'),
|
||
| 9 | ('tcp_orphan', 'TCP orphan'),
|
||
| 10 | ('tcp_tw', 'TCP tw'),
|
||
| 11 | ('tcp_alloc', 'TCP alloc'),
|
||
| 12 | ('tcp_mem', 'TCP mem'),
|
||
| 13 | ('udp_inuse', 'UDP inuse'),
|
||
| 14 | ('udplite_inuse', 'UDPLITE inuse'),
|
||
| 15 | ('raw_inuse', 'RAW inuse'),
|
||
| 16 | ('frag_inuse', 'FRAG inuse'),
|
||
| 17 | ('frag_memory', 'FRAG memory'),
|
||
| 18 | ) |
||
| 19 | |||
| 20 | if len(sys.argv) > 1: |
||
| 21 | arg = sys.argv[1] |
||
| 22 | if arg == 'autoconfig': |
||
| 23 | print 'yes' |
||
| 24 | sys.exit(0) |
||
| 25 | if arg == 'config': |
||
| 26 | print 'graph_title sockstat' |
||
| 27 | print 'graph_category network' |
||
| 28 | for name, label in fields: |
||
| 29 | print '%s.label %s' % (name, label) |
||
| 30 | sys.exit(0) |
||
| 31 | |||
| 32 | re_num = re.compile('(\d+)')
|
||
| 33 | sockstat = open('/proc/net/sockstat').read()
|
||
| 34 | numbers = re_num.findall(sockstat) |
||
| 35 | |||
| 36 | for i, (name, label) in enumerate(fields): |
||
| 37 | print '%s.value %s' % (name, numbers[i]) |
||
| 38 | |||
| 39 | sys.exit(0) |
