Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/collect-statistics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ env:
data_path: monitoring/data
monitoring_properties: monitoring/monitoring.properties
push_script: monitoring/push_with_rebase.sh
PUSHGATEWAY_HOSTNAME: monitoring.utbot.org
PUSHGATEWAY_ADDITIONAL_PATH: /pushgateway-custom
PROM_ADDITIONAL_LABELS: /service/github

jobs:
setup_matrix:
Expand Down Expand Up @@ -184,7 +187,8 @@ jobs:
if: ${{ inputs.send_to_grafana }}
run: |
python monitoring/prepare_metrics.py --stats_file $stats_file --output_file grafana_metrics.json
echo "TODO send metrics to grafana"
chmod +x scripts/project/json_to_prometheus.py
python3 scripts/project/json_to_prometheus.py grafana_metrics.json | curl -u "${{ secrets.PUSHGATEWAY_USER }}:${{ secrets.PUSHGATEWAY_PASSWORD }}" --data-binary @- https://${PUSHGATEWAY_HOSTNAME}${PUSHGATEWAY_ADDITIONAL_PATH}/metrics/job/pushgateway-custom/instance/nightly-statistics${PROM_ADDITIONAL_LABELS}
env:
stats_file: ${{ steps.insert.outputs.output }}

Expand Down
36 changes: 36 additions & 0 deletions scripts/project/json_to_prometheus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
import json

with open(sys.argv[1]) as metrics_raw:
metrics_json = json.load(metrics_raw)

# metrics is a json list e.g.:
# [
# {
# "metric": "total_classes",
# "labels": {
# "project": "guava",
# "fuzzing_ratio": 0.1
# },
# "value": 20
# },
# {
# "metric": "testcases_generated",
# "labels": {
# "project": "guava",
# "fuzzing_ratio": 0.1
# },
# "value": 1042
# }
# ]
#
# the loop below iterates over each list item and constructs metrics set
metrics_set_str = ""
for metric in metrics_json:
labels_set_str = ""
comma = ""
for label, value in metric['labels'].items():
labels_set_str = f'{labels_set_str}{comma}{label}=\"{value}\"'
comma = ","
metrics_set_str += f'{metric["metric"]}{{{labels_set_str}}} {metric["value"]}\n'
print(metrics_set_str)