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