Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / sockstat-via-procfs @ d7f54f3e

Historique | Voir | Annoter | Télécharger (956 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 86692d70 Lars Kruse
        print('yes')
24 2b6faa67 Xupeng Yun
        sys.exit(0)
25
    if arg == 'config':
26 86692d70 Lars Kruse
        print('graph_title sockstat')
27
        print('graph_category network')
28 2b6faa67 Xupeng Yun
        for name, label in fields:
29 86692d70 Lars Kruse
            print('%s.label %s' % (name, label))
30 2b6faa67 Xupeng Yun
        sys.exit(0)
31
32 be192b52 Lars Kruse
re_num = re.compile(r'(\d+)')
33 2b6faa67 Xupeng Yun
sockstat = open('/proc/net/sockstat').read()
34
numbers = re_num.findall(sockstat)
35
36
for i, (name, label) in enumerate(fields):
37 86692d70 Lars Kruse
    print('%s.value %s' % (name, numbers[i]))
38 2b6faa67 Xupeng Yun
39
sys.exit(0)