OLD | NEW |
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import errno | 5 import errno |
6 import os | 6 import os |
7 import logging | 7 import logging |
8 import time | 8 import time |
9 | 9 |
10 import psutil | 10 import psutil |
11 | 11 |
12 from infra_libs import ts_mon | 12 from infra_libs import ts_mon |
13 | 13 |
14 | 14 |
15 cpu_count = ts_mon.GaugeMetric('dev/cpu/count', | 15 cpu_count = ts_mon.GaugeMetric('dev/cpu/count', |
16 description='Number of CPU cores.') | 16 description='Number of CPU cores.') |
17 cpu_time = ts_mon.FloatMetric('dev/cpu/time', | 17 cpu_time = ts_mon.FloatMetric('dev/cpu/time', |
18 description='percentage of time spent by the CPU' | 18 description='percentage of time spent by the CPU' |
19 ' in different states.') | 19 ' in different states.') |
20 | 20 |
21 disk_free = ts_mon.GaugeMetric('dev/disk/free', | 21 disk_free = ts_mon.GaugeMetric('dev/disk/free', |
22 description='Available bytes on disk partition.') | 22 description='Available bytes on disk partition.', |
| 23 units=ts_mon.MetricsDataUnits.BYTES) |
23 disk_total = ts_mon.GaugeMetric('dev/disk/total', | 24 disk_total = ts_mon.GaugeMetric('dev/disk/total', |
24 description='Total bytes on disk partition.') | 25 description='Total bytes on disk partition.', |
| 26 units=ts_mon.MetricsDataUnits.BYTES) |
25 | 27 |
26 # inode counts are only available on Unix. | 28 # inode counts are only available on Unix. |
27 if os.name == 'posix': # pragma: no cover | 29 if os.name == 'posix': # pragma: no cover |
28 inodes_free = ts_mon.GaugeMetric('dev/inodes/free', | 30 inodes_free = ts_mon.GaugeMetric('dev/inodes/free', |
29 description='Number of available inodes on ' | 31 description='Number of available inodes on ' |
30 'disk partition (unix only).') | 32 'disk partition (unix only).') |
31 inodes_total = ts_mon.GaugeMetric('dev/inodes/total', | 33 inodes_total = ts_mon.GaugeMetric('dev/inodes/total', |
32 description='Number of possible inodes on ' | 34 description='Number of possible inodes on ' |
33 'disk partition (unix only)') | 35 'disk partition (unix only)') |
34 | 36 |
35 mem_free = ts_mon.GaugeMetric('dev/mem/free', | 37 mem_free = ts_mon.GaugeMetric('dev/mem/free', |
36 description='Amount of memory available to a ' | 38 description='Amount of memory available to a ' |
37 'process (in Bytes). Buffers are considered ' | 39 'process (in Bytes). Buffers are considered ' |
38 'free memory.') | 40 'free memory.', |
| 41 units=ts_mon.MetricsDataUnits.BYTES) |
39 | 42 |
40 mem_total = ts_mon.GaugeMetric('dev/mem/total', | 43 mem_total = ts_mon.GaugeMetric('dev/mem/total', |
41 description='Total physical memory in Bytes.') | 44 description='Total physical memory in Bytes.', |
| 45 units=ts_mon.MetricsDataUnits.BYTES) |
42 | 46 |
43 START_TIME = psutil.boot_time() | 47 START_TIME = psutil.boot_time() |
44 net_up = ts_mon.CounterMetric('dev/net/bytes/up', start_time=START_TIME, | 48 net_up = ts_mon.CounterMetric('dev/net/bytes/up', start_time=START_TIME, |
45 description='Number of bytes sent on interface.') | 49 description='Number of bytes sent on interface.', |
| 50 units=ts_mon.MetricsDataUnits.BYTES) |
46 net_down = ts_mon.CounterMetric('dev/net/bytes/down', start_time=START_TIME, | 51 net_down = ts_mon.CounterMetric('dev/net/bytes/down', start_time=START_TIME, |
47 description='Number of Bytes received on ' | 52 description='Number of Bytes received on ' |
48 'interface.') | 53 'interface.', |
| 54 units=ts_mon.MetricsDataUnits.BYTES) |
49 net_err_up = ts_mon.CounterMetric('dev/net/err/up', start_time=START_TIME, | 55 net_err_up = ts_mon.CounterMetric('dev/net/err/up', start_time=START_TIME, |
50 description='Total number of errors when ' | 56 description='Total number of errors when ' |
51 'sending (per interface).') | 57 'sending (per interface).') |
52 net_err_down = ts_mon.CounterMetric('dev/net/err/down', start_time=START_TIME, | 58 net_err_down = ts_mon.CounterMetric('dev/net/err/down', start_time=START_TIME, |
53 description='Total number of errors when ' | 59 description='Total number of errors when ' |
54 'receiving (per interface).') | 60 'receiving (per interface).') |
55 net_drop_up = ts_mon.CounterMetric('dev/net/drop/up', start_time=START_TIME, | 61 net_drop_up = ts_mon.CounterMetric('dev/net/drop/up', start_time=START_TIME, |
56 description='Total number of outgoing ' | 62 description='Total number of outgoing ' |
57 'packets that have been dropped.') | 63 'packets that have been dropped.') |
58 net_drop_down = ts_mon.CounterMetric('dev/net/drop/down', start_time=START_TIME, | 64 net_drop_down = ts_mon.CounterMetric('dev/net/drop/down', start_time=START_TIME, |
59 description='Total number of incoming ' | 65 description='Total number of incoming ' |
60 'packets that have been dropped.') | 66 'packets that have been dropped.') |
61 | 67 |
62 disk_read = ts_mon.CounterMetric('dev/disk/read', start_time=START_TIME, | 68 disk_read = ts_mon.CounterMetric('dev/disk/read', start_time=START_TIME, |
63 description='Number of Bytes read on disk.') | 69 description='Number of Bytes read on disk.', |
| 70 units=ts_mon.MetricsDataUnits.BYTES) |
64 disk_write = ts_mon.CounterMetric('dev/disk/write', start_time=START_TIME, | 71 disk_write = ts_mon.CounterMetric('dev/disk/write', start_time=START_TIME, |
65 description='Number of Bytes written on ' | 72 description='Number of Bytes written on ' |
66 'disk.') | 73 'disk.', |
| 74 units=ts_mon.MetricsDataUnits.BYTES) |
67 | 75 |
68 uptime = ts_mon.GaugeMetric('dev/uptime', | 76 uptime = ts_mon.GaugeMetric('dev/uptime', |
69 description='Machine uptime, in seconds.') | 77 description='Machine uptime, in seconds.', |
| 78 units=ts_mon.MetricsDataUnits.SECONDS) |
70 | 79 |
71 proc_count = ts_mon.GaugeMetric('dev/proc/count', | 80 proc_count = ts_mon.GaugeMetric('dev/proc/count', |
72 description='Number of processes currently ' | 81 description='Number of processes currently ' |
73 'running.') | 82 'running.') |
74 load_average = ts_mon.FloatMetric('dev/proc/load_average', | 83 load_average = ts_mon.FloatMetric('dev/proc/load_average', |
75 description='Number of processes currently ' | 84 description='Number of processes currently ' |
76 'in the system run queue.') | 85 'in the system run queue.') |
77 | 86 |
78 # tsmon pipeline uses backend clocks when assigning timestamps to metric points. | 87 # tsmon pipeline uses backend clocks when assigning timestamps to metric points. |
79 # By comparing point timestamp to the point value (i.e. time by machine's local | 88 # By comparing point timestamp to the point value (i.e. time by machine's local |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 except OSError: # pragma: no cover | 185 except OSError: # pragma: no cover |
177 pass | 186 pass |
178 else: | 187 else: |
179 load_average.set(avg1, fields={'minutes': 1}) | 188 load_average.set(avg1, fields={'minutes': 1}) |
180 load_average.set(avg5, fields={'minutes': 5}) | 189 load_average.set(avg5, fields={'minutes': 5}) |
181 load_average.set(avg15, fields={'minutes': 15}) | 190 load_average.set(avg15, fields={'minutes': 15}) |
182 | 191 |
183 | 192 |
184 def get_unix_time(): | 193 def get_unix_time(): |
185 unix_time.set(int(time.time() * 1000)) | 194 unix_time.set(int(time.time() * 1000)) |
OLD | NEW |