Added range to prometheus dumping data.

This commit is contained in:
Alberto Soutullo 2023-07-24 11:01:30 +02:00
parent 7b6fa0ce28
commit b6566e395b
2 changed files with 10 additions and 3 deletions

View File

@ -16,7 +16,7 @@ def connect_to_prometheus(ip, port):
return prometheus
def dump_prometheus(config, prometheus_ip, prometheus_port):
def dump_prometheus(config, prometheus_ip, prometheus_port, start_time, finish_time):
to_query = config["plotting"]["by_node"]
to_query = "|".join(to_query)
@ -28,7 +28,8 @@ def dump_prometheus(config, prometheus_ip, prometheus_port):
query = f"{{__name__=~\"{to_query}\"}}"
print(query)
metrics = prometheus_connection.custom_query(query)
metrics = prometheus_connection.custom_query_range(query, start_time=start_time,
end_time=finish_time, step="1s")
with open("/wls/prometheus_data.json", "w") as out_file:
json.dump(metrics, out_file)

View File

@ -7,6 +7,7 @@ import time
import tomllib
import asyncio
import os
from datetime import datetime
# Project Imports
from src.utils import wls_logger
@ -197,8 +198,12 @@ async def main():
t1 = time.time()
wls_logger.G_LOGGER.info(f'Got the signal to start: took {t1-t0} secs')
injection_start_time = datetime.now()
msgs_dict = await start_traffic_injection_async(wls_config, random_emitters)
injection_finish_time = datetime.now()
files.save_messages_to_json(msgs_dict)
# Delete de signal file just in case
@ -206,7 +211,8 @@ async def main():
os.remove('/wls/start.signal')
if prometheus_port is not None:
prometheus.dump_prometheus(config, prometheus_ip, prometheus_port)
prometheus.dump_prometheus(config, prometheus_ip, prometheus_port, injection_start_time,
injection_finish_time)
if __name__ == "__main__":