Skip to content

Commit 3372a5f

Browse files
committed
feat(sherlock): Implemented prometheus scraper
1 parent 08aa053 commit 3372a5f

File tree

6 files changed

+491
-2
lines changed

6 files changed

+491
-2
lines changed

gazer/deployment.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,27 @@ spec:
150150
app: prometheus
151151
spec:
152152
serviceAccountName: gazer
153+
securityContext:
154+
runAsUser: 65534
155+
runAsNonRoot: true
156+
runAsGroup: 65534
157+
fsGroup: 65534
153158
containers:
154159
- name: prometheus
155160
image: prom/prometheus:v2.33.1
161+
args:
162+
[
163+
"--storage.tsdb.path=/data",
164+
"--config.file=/etc/prometheus/prometheus.yml",
165+
]
156166
ports:
157167
- containerPort: 9090
158168
name: default
159169
volumeMounts:
160170
- name: config-volume
161171
mountPath: /etc/prometheus
162172
- name: prom-pvc
163-
mountPath: /etc/prometheus/data
173+
mountPath: /data
164174
volumes:
165175
- name: config-volume
166176
configMap:
@@ -177,7 +187,6 @@ metadata:
177187
spec:
178188
accessModes:
179189
- ReadWriteOnce
180-
volumeMode: Filesystem
181190
resources:
182191
requests:
183192
storage: 8Gi

sherlock/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data/*.json

sherlock/data/.gitkeep

Whitespace-only changes.

sherlock/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
prometheus-api-client~=0.5.0
2+
tqdm~=4.62.3
3+
matplotlib~=3.5.1

sherlock/scraper.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from prometheus_api_client import PrometheusConnect, MetricRangeDataFrame
2+
from prometheus_api_client.utils import parse_datetime
3+
from tqdm import tqdm
4+
5+
prom = PrometheusConnect(url="http://127.0.0.1:9090", disable_ssl=True)
6+
7+
queries = [
8+
{'name': 'requests_sent_per_minute', "query": 'rate(requests_sent_total[1m])'},
9+
{'name': 'requests_received_per_minute', "query": 'sum by (serviceName) (rate(requests_received_total[1m]))'},
10+
{'name': 'requests_duration_per_minute', "query": 'rate(request_duration_seconds_sum[1m])'},
11+
{'name': 'cpu_usage', "query": 'avg_over_time(cpu_seconds[1m])'},
12+
{'name': 'memory_usage', "query": 'avg_over_time(memory_usage_bytes[1m])'},
13+
{'name': 'acknowledged_bytes_per_minute', "query": 'rate(acknowledged_bytes_sum[1m])'},
14+
{'name': 'acknowledged_bytes_per_minute', "query": 'rate(transmitted_bytes_sum[1m])'},
15+
{'name': 'syn_backlog_per_minute', "query": 'avg_over_time(backlog{level="1"}[1m])'},
16+
{'name': 'high_syn_backlog_per_minute', "query": 'sum by (serviceName) (avg_over_time(backlog{level!="1"}[1m]))'},
17+
]
18+
19+
20+
for query in tqdm(queries):
21+
22+
start_time = parse_datetime("1d")
23+
end_time = parse_datetime("now")
24+
25+
metric_data = prom.custom_query_range(
26+
query['query'], # this is the metric name and label config
27+
start_time=start_time,
28+
end_time=end_time,
29+
step="14",
30+
)
31+
32+
metric_df = MetricRangeDataFrame(metric_data, columns=['timestamp', 'serviceName', 'value'])
33+
34+
metric_df['value'] = metric_df['value'].apply(float)
35+
metric_df.reset_index(inplace=True)
36+
37+
metric_df.to_json(f"data/{query['name']}.json", orient="records", indent=4)

sherlock/visualize.ipynb

+439
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)