commit df437560068d5710457e0ea6f8f4e8bc2ac74a71 Author: Rhys Bailey Date: Sun Feb 12 22:47:45 2023 +1100 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..22c3797 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine +RUN apk update && apk add py3-prometheus-client +COPY prometheus_frigate_exporter.py /var/python_scripts/prometheus_frigate_exporter.py +CMD /usr/bin/python3 /var/python_scripts/prometheus_frigate_exporter.py $FRIGATE_STATS_URL + +# docker build -t prometheus_frigate_exporter . \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..161ca36 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Prometheus Frigate stats exporter + +This is a docker container that runs a Prometheus exporter for [Frigate](https://frigate.video/) stats. + +Tested with ghcr.io/blakeblackshear/frigate:0.12.0-beta6 docker image with a single Intel OpenVINO detector. + +## Run the exporter + +Modify the `FRIGATE_STATS_URL` environment variable below to point to your [Frigate API stats](https://docs.frigate.video/integrations/api#get-apistats). Then run the container: + +```bash +docker run -d -p 9100:9100 -e "FRIGATE_STATS_URL=http://:5000/api/stats" --name prometheus_frigate_exporter prometheus_frigate_exporter +``` + +Metrics are available at http://localhost:9100/metrics \ No newline at end of file diff --git a/grafana-screenshot.png b/grafana-screenshot.png new file mode 100644 index 0000000..8bf4a76 Binary files /dev/null and b/grafana-screenshot.png differ diff --git a/grafana_model b/grafana_model new file mode 100644 index 0000000..bf257b0 --- /dev/null +++ b/grafana_model @@ -0,0 +1,1176 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 3, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "center", + "displayMode": "auto", + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "version" + }, + "properties": [ + { + "id": "custom.width", + "value": 0 + } + ] + } + ] + }, + "gridPos": { + "h": 3, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 12, + "maxDataPoints": 1, + "options": { + "footer": { + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true, + "sortBy": [] + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "frigate_service_info", + "format": "table", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Frigate Info", + "type": "table" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "ms" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 0, + "y": 3 + }, + "id": 23, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": true, + "showThresholdMarkers": true + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "code", + "expr": "frigate_detector_inference_speed_seconds*1000", + "legendFormat": "{{name}}", + "range": true, + "refId": "A" + } + ], + "title": "Inference Speed", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 8, + "y": 3 + }, + "id": 25, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": true, + "showThresholdMarkers": true + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "sum(frigate_cpu_usage_percent)", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Total CPU Usage", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 16, + "y": 3 + }, + "id": 26, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": true, + "showThresholdMarkers": true + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "sum(frigate_mem_usage_percent)", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Total Memory Usage", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_detector_inference_speed_seconds", + "legendFormat": "{{name}}", + "range": true, + "refId": "A" + } + ], + "title": "Inference Speed", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 9 + }, + "id": 20, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_gpu_usage_percent", + "legendFormat": "{{gpu}}", + "range": true, + "refId": "A" + } + ], + "title": "GPU utilisation %", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 17 + }, + "id": 10, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_cpu_usage_percent", + "legendFormat": "PID={{pid}}", + "range": true, + "refId": "A" + } + ], + "title": "Process CPU usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "fps" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 18 + }, + "id": 6, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_detection_fps", + "legendFormat": "{{camera}}", + "range": true, + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_detection_total_fps", + "hide": false, + "legendFormat": "Total", + "range": true, + "refId": "B" + } + ], + "title": "Detection FPS", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 25 + }, + "id": 18, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_mem_usage_percent", + "legendFormat": "PID={{pid}}", + "range": true, + "refId": "A" + } + ], + "title": "Process memory usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "fps" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 26 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_camera_fps", + "legendFormat": "{{camera}}", + "range": true, + "refId": "A" + } + ], + "title": "Camera FPS", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 33 + }, + "id": 21, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_gpu_mem_usage_percent", + "legendFormat": "{{gpu}}", + "range": true, + "refId": "A" + } + ], + "title": "GPU memory usage %", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "axisSoftMax": 5, + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "fps" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 34 + }, + "id": 8, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "frigate_skipped_fps", + "legendFormat": "{{camera}}", + "range": true, + "refId": "A" + } + ], + "title": "Skipped FPS", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 39 + }, + "id": 28, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "jg7n1Vzre" + }, + "editorMode": "builder", + "expr": "scrape_duration_seconds{job=\"frigate\"}", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Scrape Duration", + "type": "timeseries" + } + ], + "refresh": "1m", + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-5m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Frigate", + "uid": "rfryG56W7", + "version": 22, + "weekStart": "" +} \ No newline at end of file diff --git a/prometheus_frigate_exporter.py b/prometheus_frigate_exporter.py new file mode 100644 index 0000000..6485334 --- /dev/null +++ b/prometheus_frigate_exporter.py @@ -0,0 +1,126 @@ +from prometheus_client.core import GaugeMetricFamily, InfoMetricFamily, REGISTRY +from prometheus_client import start_http_server +from urllib.request import urlopen +import json +import re +import time +import sys +import logging + +class CustomCollector(object): + + def __init__(self, url): + self.url = url + + def collect(self): + data = json.loads(urlopen(self.url).read()) + + # camera stats + ffmpeg_pid = GaugeMetricFamily('frigate_ffmpeg_pid', 'PID for ffmpeg process', labels=['camera']) + capture_pid = GaugeMetricFamily('frigate_capture_pid', 'PID for the ffmpeg process that consumes this camera', labels=['camera']) + detect_pid = GaugeMetricFamily('frigate_detect_pid', 'PID for the process that runs detection for this camera', labels=['camera']) + camera_fps = GaugeMetricFamily('frigate_camera_fps', 'Frames per second being consumed from your camera.', labels=['camera']) + detection_fps = GaugeMetricFamily('frigate_detection_fps', 'Number of times detection is run per second.', labels=['camera']) + process_fps = GaugeMetricFamily('frigate_process_fps', 'Frames per second being processed by frigate.', labels=['camera']) + skipped_fps = GaugeMetricFamily('frigate_skipped_fps', 'Frames per second skip for processing by frigate.', labels=['camera']) + detection_enabled = GaugeMetricFamily('frigate_detection_enabled', 'Detection enabled for camera', labels=['camera']) + + for d in data: + try: + ffmpeg_pid.add_metric([d], float(data[d]['ffmpeg_pid'])) + detect_pid.add_metric([d], float(data[d]['pid'])) + capture_pid.add_metric([d], float(data[d]['capture_pid'])) + camera_fps.add_metric([d], (data[d]['camera_fps'])) + detection_fps.add_metric([d], float(data[d]['detection_fps'])) + process_fps.add_metric([d], float(data[d]['process_fps'])) + skipped_fps.add_metric([d], float(data[d]['skipped_fps'])) + detection_enabled.add_metric([d], float(data[d]['detection_enabled'])) + except (AttributeError, TypeError, KeyError): + pass + + yield ffmpeg_pid + yield capture_pid + yield detect_pid + yield camera_fps + yield detection_fps + yield process_fps + yield skipped_fps + yield detection_enabled + + # detector stats + yield GaugeMetricFamily('frigate_detection_total_fps', 'Sum of detection_fps across all cameras and detectors.', value=data['detection_fps']) + + detector_inference_speed = GaugeMetricFamily('frigate_detector_inference_speed_seconds', 'Time spent running object detection in seconds.', labels=['name']) + detector_pid = GaugeMetricFamily('frigate_detector_pid', 'PID for the shared process that runs object detection on the detector', labels=['name']) + + for d in data['detectors']: + detector_inference_speed.add_metric([d], data['detectors'][d]['inference_speed']/1000.0) # ms to seconds + detector_pid.add_metric([d], data['detectors'][d]['pid']) + + yield detector_inference_speed + yield detector_pid + + # process stats + cpu_usages = GaugeMetricFamily('frigate_cpu_usage_percent', 'Process CPU usage %', labels=['pid']) + mem_usages = GaugeMetricFamily('frigate_mem_usage_percent', 'Process memory usage %', labels=['pid']) + + data['cpu_usages'].pop('Tasks:') + for d in data['cpu_usages']: + cpu_usages.add_metric([d], float(data['cpu_usages'][d]['cpu'])) + mem_usages.add_metric([d], float(data['cpu_usages'][d]['mem'])) + + yield cpu_usages + yield mem_usages + + # gpu stats + gpu_usages = GaugeMetricFamily('frigate_gpu_usage_percent', 'GPU utilisation %', labels=['gpu']) + gpu_mem_usages = GaugeMetricFamily('frigate_gpu_mem_usage_percent', 'GPU memory usage %', labels=['gpu']) + + for d in data['gpu_usages']: + try: + gpu_usages.add_metric([d], float(re.findall(r'\d+', data['gpu_usages'][d]['gpu'])[0])) + mem_usages.add_metric([d], float(re.findall(r'\d+', data['gpu_usages'][d]['mem'])[0])) # no value for me + except IndexError: + pass + + yield gpu_usages + yield gpu_mem_usages + + # service stats + yield GaugeMetricFamily('frigate_service_last_updated_timestamp', 'Stats recorded time (unix timestamp)', value=data['service']['last_updated']) + info = {'latest_version': data['service']['latest_version'], 'version': data['service']['version']} + yield InfoMetricFamily('frigate_service', 'Frigate version info', value=info) + yield GaugeMetricFamily('frigate_service_uptime_seconds', 'Uptime seconds', value=data['service']['uptime']) + # temperatures: no data for me + + storage_free = GaugeMetricFamily('frigate_storage_free_bytes', 'Storage free bytes', labels=['storage']) + storage_mount_type = InfoMetricFamily('frigate_storage_mount_type', 'Storage mount type', labels=['storage']) + storage_total = GaugeMetricFamily('frigate_storage_total_bytes', 'Storage total bytes', labels=['storage']) + storage_used = GaugeMetricFamily('frigate_storage_used_bytes', 'Storage used bytes', labels=['storage']) + + for d in data['service']['storage']: + storage_free.add_metric([d], data['service']['storage'][d]['free']*1e6) #MB to bytes + storage_total.add_metric([d], (data['service']['storage'][d]['total']*1e6)) + storage_used.add_metric([d], (data['service']['storage'][d]['used']*1e6)) + storage_mount_type.add_metric([d], {'mount_type': data['service']['storage'][d]['mount_type']}) + + yield storage_free + yield storage_mount_type + yield storage_total + yield storage_used + + +if __name__ == '__main__': + logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO) + + if len(sys.argv) < 1: + logging.info("Provide Frigate stats url, e.g. http://:5000/api/stats") + + REGISTRY.register(CustomCollector(sys.argv[1])) + start_http_server(9100) + + logging.info('Started: ' + sys.argv[1]) + + while True: time.sleep(1) + + logging.info("Finished") \ No newline at end of file