|
6 | 6 |
|
7 | 7 | PARAMS = {} |
8 | 8 |
|
9 | | -NAME_PREFIX = 'vm_' |
10 | | - |
11 | 9 | METRICS = { |
12 | 10 | 'time' : 0, |
13 | 11 | 'data' : {} |
@@ -55,7 +53,7 @@ def metric_init(params): |
55 | 53 | 'call_back' : get_delta, |
56 | 54 | 'time_max' : 60, |
57 | 55 | 'value_type' : 'float', |
58 | | - 'format' : '%.4f', |
| 56 | + 'format' : '%.0f', |
59 | 57 | 'units' : '/s', |
60 | 58 | 'slope' : 'both', # zero|positive|negative|both |
61 | 59 | 'description' : 'XXX', |
@@ -106,12 +104,41 @@ def metric_init(params): |
106 | 104 | "description" : "transmitted dropped packets per sec", |
107 | 105 | })) |
108 | 106 |
|
| 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 | + |
109 | 133 | return descriptors |
110 | 134 |
|
111 | 135 | def metric_cleanup(): |
112 | 136 | '''Clean up the metric module.''' |
113 | 137 | pass |
114 | 138 |
|
| 139 | +################################################################################### |
| 140 | +# Build a list of interfaces |
| 141 | +################################################################################### |
115 | 142 | def get_interfaces(watch_interfaces, excluded_interfaces): |
116 | 143 | global INTERFACES |
117 | 144 | if_excluded = 0 |
@@ -140,6 +167,47 @@ def get_interfaces(watch_interfaces, excluded_interfaces): |
140 | 167 | return 0 |
141 | 168 |
|
142 | 169 |
|
| 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 | + |
143 | 211 | def get_metrics(): |
144 | 212 | """Return all metrics""" |
145 | 213 |
|
@@ -200,6 +268,7 @@ def get_delta(name): |
200 | 268 | params = { |
201 | 269 | "interfaces": "", |
202 | 270 | "excluded_interfaces": "dummy", |
| 271 | + "send_aggregate_bytes_packets": True, |
203 | 272 | "debug" : True, |
204 | 273 | } |
205 | 274 | metric_init(params) |
|
0 commit comments