|
@@ 99-120 (lines=22) @@
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
def proc_stat_cpu_percent(self, key, val): |
| 99 |
|
"""Return cpu utilization metrics in percentage. |
| 100 |
|
|
| 101 |
|
:param key: The metric name (eg. cpu, cpu0, cpu1, etc) |
| 102 |
|
:type key: str |
| 103 |
|
:param val: A deque populated with the metric values from stat |
| 104 |
|
:type val: deque |
| 105 |
|
:rtype: list |
| 106 |
|
""" |
| 107 |
|
result = plumd.Result("cpu") |
| 108 |
|
total = sum([ float(i) for i in val]) |
| 109 |
|
cpu = self.config.get('cpu_metrics') |
| 110 |
|
for map_val in cpu: |
| 111 |
|
if len(val) < 1: |
| 112 |
|
break |
| 113 |
|
metric_val = float(val.popleft()) |
| 114 |
|
mstr = "{0}_{1}".format(key, map_val) |
| 115 |
|
percent_val = metric_val / total * 100.00 |
| 116 |
|
result.add(plumd.Float(mstr, percent_val)) |
| 117 |
|
return result |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
def proc_stat_cpu(self, key, val, ts): |
| 121 |
|
"""Return cpu utilization metrics in USER_HZ or Jiffies |
| 122 |
|
(most likely units of 100Hz intervals ie. 100ms intervals). |
| 123 |
|
|
|
@@ 77-96 (lines=20) @@
|
| 74 |
|
for i, metric in enumerate(self.rates): |
| 75 |
|
if metric not in dat: |
| 76 |
|
self.log.warn("stat: unknown metric {0}".format(metric)) |
| 77 |
|
del(self.rates[i]) |
| 78 |
|
continue |
| 79 |
|
mval = self.calc.per_second(metric, float(dat[metric][0]), ts) |
| 80 |
|
result.add(plumd.Int(metric, mval)) |
| 81 |
|
|
| 82 |
|
# record cpu |
| 83 |
|
if "cpu" in dat: |
| 84 |
|
results.append(self.proc_stat_cpu_percent("cpu", dat["cpu"])) |
| 85 |
|
|
| 86 |
|
# record each cpu if configured |
| 87 |
|
if self.per_cpu: |
| 88 |
|
for i in xrange(0, len(dat)): |
| 89 |
|
mstr = "cpu{0}".format(i) |
| 90 |
|
if mstr not in dat: |
| 91 |
|
break |
| 92 |
|
results.append(self.proc_stat_cpu(mstr, dat[mstr], ts)) |
| 93 |
|
|
| 94 |
|
results.append(result) |
| 95 |
|
return results |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
def proc_stat_cpu_percent(self, key, val): |
| 99 |
|
"""Return cpu utilization metrics in percentage. |