-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sherlock): Implemented prometheus scraper
- Loading branch information
Showing
6 changed files
with
491 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data/*.json |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
prometheus-api-client~=0.5.0 | ||
tqdm~=4.62.3 | ||
matplotlib~=3.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from prometheus_api_client import PrometheusConnect, MetricRangeDataFrame | ||
from prometheus_api_client.utils import parse_datetime | ||
from tqdm import tqdm | ||
|
||
prom = PrometheusConnect(url="http://127.0.0.1:9090", disable_ssl=True) | ||
|
||
queries = [ | ||
{'name': 'requests_sent_per_minute', "query": 'rate(requests_sent_total[1m])'}, | ||
{'name': 'requests_received_per_minute', "query": 'sum by (serviceName) (rate(requests_received_total[1m]))'}, | ||
{'name': 'requests_duration_per_minute', "query": 'rate(request_duration_seconds_sum[1m])'}, | ||
{'name': 'cpu_usage', "query": 'avg_over_time(cpu_seconds[1m])'}, | ||
{'name': 'memory_usage', "query": 'avg_over_time(memory_usage_bytes[1m])'}, | ||
{'name': 'acknowledged_bytes_per_minute', "query": 'rate(acknowledged_bytes_sum[1m])'}, | ||
{'name': 'acknowledged_bytes_per_minute', "query": 'rate(transmitted_bytes_sum[1m])'}, | ||
{'name': 'syn_backlog_per_minute', "query": 'avg_over_time(backlog{level="1"}[1m])'}, | ||
{'name': 'high_syn_backlog_per_minute', "query": 'sum by (serviceName) (avg_over_time(backlog{level!="1"}[1m]))'}, | ||
] | ||
|
||
|
||
for query in tqdm(queries): | ||
|
||
start_time = parse_datetime("1d") | ||
end_time = parse_datetime("now") | ||
|
||
metric_data = prom.custom_query_range( | ||
query['query'], # this is the metric name and label config | ||
start_time=start_time, | ||
end_time=end_time, | ||
step="14", | ||
) | ||
|
||
metric_df = MetricRangeDataFrame(metric_data, columns=['timestamp', 'serviceName', 'value']) | ||
|
||
metric_df['value'] = metric_df['value'].apply(float) | ||
metric_df.reset_index(inplace=True) | ||
|
||
metric_df.to_json(f"data/{query['name']}.json", orient="records", indent=4) |
Large diffs are not rendered by default.
Oops, something went wrong.