1
|
|
|
from unittest import TestCase |
|
|
|
|
2
|
|
|
|
3
|
|
|
from kibana_collector import Metrics |
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class TestMetrics(TestCase): |
|
|
|
|
7
|
|
|
def setUp(self) -> None: |
8
|
|
|
self.metrics_dict = { |
9
|
|
|
'last_updated': '2019-04-02T03:56:41.078Z', |
10
|
|
|
'collection_interval_in_millis': 15000, |
11
|
|
|
'process': { |
12
|
|
|
'memory': { |
13
|
|
|
'heap': { |
14
|
|
|
'total_in_bytes': 175874048, |
15
|
|
|
'used_in_bytes': 157139288, |
16
|
|
|
'size_limit': 1526909922 |
17
|
|
|
}, |
18
|
|
|
'resident_set_size_in_bytes': 285655040 |
19
|
|
|
}, |
20
|
|
|
'event_loop_delay': 0.08109402656555176, |
21
|
|
|
'pid': 18595, |
22
|
|
|
'uptime_in_millis': 2494490 |
23
|
|
|
}, |
24
|
|
|
'os': { |
25
|
|
|
'load': { |
26
|
|
|
'1m': 0.16357421875, |
27
|
|
|
'5m': 0.13720703125, |
28
|
|
|
'15m': 0.13037109375 |
29
|
|
|
}, |
30
|
|
|
'memory': { |
31
|
|
|
'total_in_bytes': 8257908736, |
32
|
|
|
'free_in_bytes': 193777664, |
33
|
|
|
'used_in_bytes': 8064131072 |
34
|
|
|
}, |
35
|
|
|
'uptime_in_millis': 1212738000, |
36
|
|
|
'platform': 'linux', |
37
|
|
|
'platformRelease': 'linux-4.15.0-1034-aws', |
38
|
|
|
'distro': 'Ubuntu Linux', |
39
|
|
|
'distroRelease': 'Ubuntu Linux-18.04', |
40
|
|
|
'cgroup': { |
41
|
|
|
'cpuacct': { |
42
|
|
|
'control_group': '/system.slice/kibana.service', |
43
|
|
|
'usage_nanos': 24967412414 |
44
|
|
|
}, |
45
|
|
|
'cpu': { |
46
|
|
|
'control_group': '/system.slice/kibana.service', |
47
|
|
|
'cfs_period_micros': 100000, |
48
|
|
|
'cfs_quota_micros': -1, |
49
|
|
|
'stat': { |
50
|
|
|
'number_of_elapsed_periods': 0, |
51
|
|
|
'number_of_times_throttled': 0, |
52
|
|
|
'time_throttled_nanos': 0 |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
}, |
57
|
|
|
'response_times': { |
58
|
|
|
'avg_in_millis': 2.3333333333333335, 'max_in_millis': 3 |
59
|
|
|
}, |
60
|
|
|
'requests': { |
61
|
|
|
'disconnects': 0, |
62
|
|
|
'statusCodes': {}, |
63
|
|
|
'total': 3, |
64
|
|
|
'status_codes': { |
65
|
|
|
'302': 3 |
66
|
|
|
} |
67
|
|
|
}, |
68
|
|
|
'concurrent_connections': 0 |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
def test_all_metrics_have_timestamps(self): |
72
|
|
|
metrics = Metrics(self.metrics_dict) |
73
|
|
|
for metric in metrics: |
74
|
|
|
for sample in metric.samples: |
75
|
|
|
self.assertIsNotNone(sample.timestamp, sample) |
76
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.