19
19
# --url=http://prometheus.prometheus.svc.cluster.local:9090
20
20
# --pod_type=driver --pod_type=clients --container_name=main
21
21
# --container_name=sidecar
22
- """Perform prometheus range queries to obtain cpu and memory data.
22
+ """Perform Prometheus range queries to obtain cpu and memory data.
23
23
24
24
This module performs range queries through Prometheus API to obtain
25
- total cpu seconds and memory during a tets run for given container
25
+ total cpu seconds and memory during a test run for given container
26
26
in given pods. The cpu data obtained is total cpu second used within
27
- given period of time. The memory data was the instant memory at the
28
- query time.
27
+ given period of time. The memory data was instant memory usage at
28
+ the query time.
29
29
"""
30
30
import argparse
31
31
import json
38
38
39
39
40
40
class Prometheus :
41
- """Objects which holds the start and end time, query URL
42
- for a query."""
41
+ """Objects which holds the start time, end time and query URL."""
43
42
44
43
def __init__ (
45
44
self ,
@@ -54,9 +53,9 @@ def __init__(
54
53
def _fetch_by_query (self , query : str ) -> Dict [str , Any ]:
55
54
"""Fetches the given query with time range.
56
55
57
- Fetch the given query within a time range. The pulling
56
+ Fetch the given query within a time range. The pulling
58
57
interval is every 5s, the actual data from the query is
59
- a time serier .
58
+ a time series .
60
59
"""
61
60
resp = requests .get (
62
61
self .url + '/api/v1/query_range' ,
@@ -75,7 +74,7 @@ def _fetch_cpu_for_pod(self, container_matcher: str,
75
74
"""Fetches the cpu data for each pod.
76
75
77
76
Fetch total cpu seconds during the time range specified in the Prometheus instance
78
- for a pod. After obtain the cpu seconds, the data are trimmed from time serier to
77
+ for a pod. After obtain the cpu seconds, the data are trimmed from time series to
79
78
a data list and saved in the Dict that keyed by the container names.
80
79
81
80
Args:
@@ -96,7 +95,7 @@ def _fetch_memory_for_pod(self, container_matcher: str,
96
95
"""Fetches memory data for each pod.
97
96
98
97
Fetch total memory data during the time range specified in the Prometheus instance
99
- for a pod. After obtain the memory data, the data are trimmed from time serier to
98
+ for a pod. After obtain the memory data, the data are trimmed from time series to
100
99
a data list and saved in the Dict that keyed by the container names.
101
100
102
101
Args:
@@ -118,7 +117,7 @@ def _fetch_memory_for_pod(self, container_matcher: str,
118
117
def fetch_cpu_and_memory_data (
119
118
self , container_list : List [str ],
120
119
pod_dict : Dict [str , List [str ]]) -> Dict [str , Any ]:
121
- """Fetch total cpu seconds and memory data for a multiple pods.
120
+ """Fetch total cpu seconds and memory data for multiple pods.
122
121
123
122
Args:
124
123
container_list: A list of container names to fetch the data for.
@@ -168,7 +167,7 @@ def construct_container_matcher(container_list: List[str]) -> str:
168
167
169
168
def get_data_list_from_timeseries (data : Any ) -> Dict [str , List [float ]]:
170
169
"""Constructs a Dict as keys are the container names and
171
- values are a list of data taken from given timeserie data."""
170
+ values are a list of data taken from given timeseries data."""
172
171
if data ['status' ] != 'success' :
173
172
raise Exception ('command failed: ' + data ['status' ] + str (data ))
174
173
if data ['data' ]['resultType' ] != 'matrix' :
@@ -178,10 +177,10 @@ def get_data_list_from_timeseries(data: Any) -> Dict[str, List[float]]:
178
177
container_name_to_data_list = {}
179
178
for res in data ["data" ]["result" ]:
180
179
container_name = res ["metric" ]["container" ]
181
- container_data_timeserie = res ["values" ]
180
+ container_data_timeseries = res ["values" ]
182
181
183
182
container_data = []
184
- for d in container_data_timeserie :
183
+ for d in container_data_timeseries :
185
184
container_data .append (float (d [1 ]))
186
185
container_name_to_data_list [container_name ] = container_data
187
186
return container_name_to_data_list
@@ -193,7 +192,7 @@ def compute_total_cpu_seconds(cpu_data_list: List[float]) -> float:
193
192
194
193
195
194
def compute_average_memory_usage (memory_data_list : List [float ]) -> float :
196
- """Computes the mean and for given list of data."""
195
+ """Computes the mean and for a given list of data."""
197
196
return statistics .mean (memory_data_list )
198
197
199
198
@@ -224,7 +223,7 @@ def construct_pod_dict(node_info_file: str,
224
223
225
224
226
225
def convert_UTC_to_epoch (utc_timestamp : str ) -> str :
227
- """Converts a utc timstamp string to epoch time string."""
226
+ """Converts a utc timestamp string to epoch time string."""
228
227
parsed_time = parser .parse (utc_timestamp )
229
228
epoch = parsed_time .strftime ('%s' )
230
229
return epoch
0 commit comments