Skip to content

Commit 5c8ade3

Browse files
committed
Now reads /proc/net/snmp as well
1 parent 124d256 commit 5c8ade3

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

network/netstats/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
netstats
22
=====
33

4+
Exports raw stats found in `/proc/net/netstat` and /proc/net/snmp`.
45

56
Install
67
-------
@@ -14,7 +15,7 @@ Copy netstats.pyconf to the gmond conf.d directory, e.g. :
1415

1516
- /etc/ganglia/conf.d/
1617

17-
Tune the netstats.pyconf file to match your server interfaces and then restart gmond.
18+
Tune the netstats.pyconf file to match your needs and then restart gmond.
1819

1920
## AUTHOR
2021

network/netstats/conf.d/netstats.basic.pyconf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,27 @@ modules {
55
language = "python"
66
}
77
}
8+
9+
10+
collection_group {
11+
collect_every = 1
12+
time_threshold = 45
13+
14+
# You can enumerate all metrics you want to see from the /proc/net/netstat and
15+
# /proc/net/snmp files. The name of the metric will be "netstat_CATEGORY_NAME".
16+
# Where CATEGORY is a row like Tcp from snmp or TcpExt from netstat and
17+
# NAME is a column like RcvbufErrors from the snmp or InMcastPkts in netstat.
18+
#
19+
# Few examples below:
20+
21+
metric {
22+
name = "netstat_TcpExt_SyncookiesRecv"
23+
title = "TCP syncookies received"
24+
}
25+
26+
metric {
27+
name = "netstat_Tcp_ActiveOpens"
28+
title = "TCP active opened connections"
29+
}
30+
31+
}

network/netstats/python_modules/netstats.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
MODULE_NAME = "netstat"
1212
STATS_FILE = "/proc/net/netstat"
13+
SNMP_FILE = "/proc/net/snmp"
1314

1415
descriptors = list()
1516
Desc_Skel = {}
@@ -82,11 +83,11 @@ def update_metric(self):
8283
}
8384

8485
try:
85-
for stat_type, key, value in netstat_iterator():
86+
for stat_type, key, value in netstats_iterator():
8687
update_dict['%s_%s_%s' % (self.mp, stat_type, key)] = int(value)
8788

88-
except IOError:
89-
dprint("unable to open " + STATS_FILE)
89+
except IOError as err:
90+
dprint("unable to open stats file. %s" % err)
9091
return False
9192

9293
self.metric.update(update_dict)
@@ -115,7 +116,7 @@ def metric_init(params):
115116
'call_back': metric_delta,
116117
'time_max': 60,
117118
'value_type': 'float',
118-
'format': '%d',
119+
'format': '%.2f',
119120
'units': 'XXX',
120121
'slope': 'XXX', # zero|positive|negative|both
121122
'description': 'XXX',
@@ -134,7 +135,7 @@ def metric_init(params):
134135
mp = params["metrix_prefix"]
135136

136137
try:
137-
for stat_type, key, value in netstat_iterator():
138+
for stat_type, key, value in netstats_iterator():
138139
descriptors.append(create_desc(Desc_Skel, {
139140
"name": '%s_%s_%s' % (mp, stat_type, key),
140141
"units": "number",
@@ -147,8 +148,8 @@ def metric_init(params):
147148
return descriptors
148149

149150

150-
def netstat_iterator():
151-
f = open(STATS_FILE, 'r')
151+
def file_iterator(file_name):
152+
f = open(file_name, 'r')
152153

153154
line_number = -1
154155
labels = []
@@ -181,6 +182,14 @@ def netstat_iterator():
181182
yield values_type, labels[ind], value
182183

183184

185+
def netstats_iterator():
186+
for vt, key, val in file_iterator(STATS_FILE):
187+
yield vt, key, val
188+
189+
for vt, key, val in file_iterator(SNMP_FILE):
190+
yield vt, key, val
191+
192+
184193
def create_desc(skel, prop):
185194
d = skel.copy()
186195
for k, v in prop.iteritems():

0 commit comments

Comments
 (0)