Skip to content

Commit a4aa031

Browse files
committed
Override bytes_in,bytes_out from default mod_net module. Use
multi_interface module to sum only interfaces we care about.
1 parent 5831581 commit a4aa031

3 files changed

Lines changed: 112 additions & 3 deletions

File tree

network/multi_interface/README.mkdn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ value for tx_drops_eth1 is 0.0000
3535

3636
You can run the multi_interface.py script by hand to see all of the metrics.
3737

38+
In addition this script can be used to override "default" bytes_in, bytes_out, pkts_in and pkts_out
39+
metrics. To do that you will need to
40+
41+
* set send_aggregate_bytes_packets to True in multi_interface.pyconf
42+
* Uncomment bytes_in, bytes_out metrics to be sent in in multi_interface.pyconf
43+
* Comment out those same metrics you uncommented in step above in gmond.conf so they don't override
44+
each other
45+
46+
3847
Install
3948
===============
4049

network/multi_interface/conf.d/multi_interface.pyconf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ modules {
1111
value = ""
1212
}
1313

14+
# If set to true interfaces that are indicated above will be summed
15+
# to produce bytes_out, bytes_in, pkts_out and pkts_in values
16+
# This may be useful in situations where you don't care about internal
17+
# interfaces ie. if machine is dual homed and really care about
18+
# traffic going only externally
19+
param send_aggregate_bytes_packets {
20+
value = False
21+
}
22+
1423
# Alternatively leave the interfaces list at value = "" then exclude
1524
# specific interfaces by name or regular expression e.g. dummy, lo, eth[0-9]+ etc.
1625
param excluded_interfaces {
@@ -34,4 +43,26 @@ collection_group {
3443
value_threshold = 1.0
3544
}
3645

46+
# Uncomment only if param send_aggregate_bytes_packets set to True
47+
# metric {
48+
# name = "bytes_out"
49+
# value_threshold = 4096
50+
# title = "Bytes Sent"
51+
# }
52+
# metric {
53+
# name = "bytes_in"
54+
# value_threshold = 4096
55+
# title = "Bytes Received"
56+
# }
57+
# metric {
58+
# name = "pkts_in"
59+
# value_threshold = 256
60+
# title = "Packets Received"
61+
# }
62+
# metric {
63+
# name = "pkts_out"
64+
# value_threshold = 256
65+
# title = "Packets Sent"
66+
# }
67+
3768
}

network/multi_interface/python_modules/multi_interface.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
PARAMS = {}
88

9-
NAME_PREFIX = 'vm_'
10-
119
METRICS = {
1210
'time' : 0,
1311
'data' : {}
@@ -55,7 +53,7 @@ def metric_init(params):
5553
'call_back' : get_delta,
5654
'time_max' : 60,
5755
'value_type' : 'float',
58-
'format' : '%.4f',
56+
'format' : '%.0f',
5957
'units' : '/s',
6058
'slope' : 'both', # zero|positive|negative|both
6159
'description' : 'XXX',
@@ -106,12 +104,41 @@ def metric_init(params):
106104
"description" : "transmitted dropped packets per sec",
107105
}))
108106

107+
if params['send_aggregate_bytes_packets']:
108+
descriptors.append(create_desc(Desc_Skel, {
109+
"name" : "pkts_in",
110+
"units" : "pkts/sec",
111+
"call_back" : get_aggregates,
112+
"description" : "Packets Received",
113+
}))
114+
descriptors.append(create_desc(Desc_Skel, {
115+
"name" : "pkts_out",
116+
"units" : "pkts/sec",
117+
"call_back" : get_aggregates,
118+
"description" : "Packets Sent",
119+
}))
120+
descriptors.append(create_desc(Desc_Skel, {
121+
"name" : "bytes_in",
122+
"units" : "bytes/sec",
123+
"call_back" : get_aggregates,
124+
"description" : "Bytes Received",
125+
}))
126+
descriptors.append(create_desc(Desc_Skel, {
127+
"name" : "bytes_out",
128+
"units" : "bytes/sec",
129+
"call_back" : get_aggregates,
130+
"description" : "Bytes Sent",
131+
}))
132+
109133
return descriptors
110134

111135
def metric_cleanup():
112136
'''Clean up the metric module.'''
113137
pass
114138

139+
###################################################################################
140+
# Build a list of interfaces
141+
###################################################################################
115142
def get_interfaces(watch_interfaces, excluded_interfaces):
116143
global INTERFACES
117144
if_excluded = 0
@@ -140,6 +167,47 @@ def get_interfaces(watch_interfaces, excluded_interfaces):
140167
return 0
141168

142169

170+
###################################################################################
171+
# Returns aggregate values for pkts and bytes sent and received. It should be
172+
# used to override the default Ganglia mod_net module. It will generate bytes_in
173+
# bytes_out, pkts_in and pkts_out.
174+
###################################################################################
175+
def get_aggregates(name):
176+
177+
# get metrics
178+
[curr_metrics, last_metrics] = get_metrics()
179+
180+
# Determine the index of metric we need
181+
if name == "bytes_in":
182+
index = stats_tab["rx_bytes"]
183+
elif name == "bytes_out":
184+
index = stats_tab["tx_bytes"]
185+
elif name == "pkts_out":
186+
index = stats_tab["tx_pkts"]
187+
elif name == "pkts_in":
188+
index = stats_tab["rx_pkts"]
189+
else:
190+
return 0
191+
192+
sum = 0
193+
194+
# Loop through the list of interfaces we care for
195+
for iface in INTERFACES:
196+
197+
try:
198+
delta = (float(curr_metrics['data'][iface][index]) - float(last_metrics['data'][iface][index])) /(curr_metrics['time'] - last_metrics['time'])
199+
if delta < 0:
200+
print name + " is less 0"
201+
delta = 0
202+
except KeyError:
203+
delta = 0.0
204+
205+
sum += delta
206+
207+
return sum
208+
209+
210+
143211
def get_metrics():
144212
"""Return all metrics"""
145213

@@ -200,6 +268,7 @@ def get_delta(name):
200268
params = {
201269
"interfaces": "",
202270
"excluded_interfaces": "dummy",
271+
"send_aggregate_bytes_packets": True,
203272
"debug" : True,
204273
}
205274
metric_init(params)

0 commit comments

Comments
 (0)