Skip to content

Commit

Permalink
feat(sherlock): Implemented prometheus scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
isala404 committed Feb 19, 2022
1 parent 08aa053 commit 3372a5f
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gazer/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,27 @@ spec:
app: prometheus
spec:
serviceAccountName: gazer
securityContext:
runAsUser: 65534
runAsNonRoot: true
runAsGroup: 65534
fsGroup: 65534
containers:
- name: prometheus
image: prom/prometheus:v2.33.1
args:
[
"--storage.tsdb.path=/data",
"--config.file=/etc/prometheus/prometheus.yml",
]
ports:
- containerPort: 9090
name: default
volumeMounts:
- name: config-volume
mountPath: /etc/prometheus
- name: prom-pvc
mountPath: /etc/prometheus/data
mountPath: /data
volumes:
- name: config-volume
configMap:
Expand All @@ -177,7 +187,6 @@ metadata:
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 8Gi
Expand Down
1 change: 1 addition & 0 deletions sherlock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/*.json
Empty file added sherlock/data/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions sherlock/requirements.txt
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
37 changes: 37 additions & 0 deletions sherlock/scraper.py
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)
439 changes: 439 additions & 0 deletions sherlock/visualize.ipynb

Large diffs are not rendered by default.

0 comments on commit 3372a5f

Please sign in to comment.