From bc03c4d466319017925242957015e9841a459734 Mon Sep 17 00:00:00 2001 From: Rhys Bailey Date: Mon, 11 Mar 2024 21:57:46 +1100 Subject: [PATCH] export network bandwidth stats --- README.md | 11 ++++++++++- prometheus_frigate_exporter.py | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 488f5a9..236ac8a 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,10 @@ Exports from Frigate API: - Inference Speed - CPU and MEM process stats - Camera, detection and skipped FPS +- Camera audio stats - Storage total, used and free - Device Temperature (Coral temp) -- Event counter for each camera label +- Event counters for detected labels on each camera [Docker Hub](https://hub.docker.com/r/rhysbailey/prometheus-frigate-exporter) @@ -39,6 +40,14 @@ The default internal exporter port can be modified with `-e "PORT=9100"` Metrics are available at http://localhost:9100/metrics +If you want to export network bandwidth stats, include the section below in your Frigate config (see [here](https://docs.frigate.video/configuration/reference)): + +```yml +telemetry: + stats: + network_bandwidth: True +``` + ### Setup Prometheus If you don't already have Prometheus set up to scrape the `prometheus-frigate-exporter` metrics, diff --git a/prometheus_frigate_exporter.py b/prometheus_frigate_exporter.py index f0ab0e5..94c6748 100644 --- a/prometheus_frigate_exporter.py +++ b/prometheus_frigate_exporter.py @@ -220,6 +220,32 @@ def collect(self): yield storage_total yield storage_used + # bandwidth stats + bandwidth_usages = GaugeMetricFamily('frigate_bandwidth_usages_kBps', 'bandwidth usages kilobytes per second', labels=['pid', 'name', 'process', 'type', 'cmdline']) + + try: + for b_pid, b_stats in stats['bandwidth_usages'].items(): + label = [b_pid] # pid label + try: + n = stats['cpu_usages'][b_pid]['cmdline'] + for p_name, p_stats in stats['processes'].items(): + if str(p_stats['pid']) == b_pid: + n = p_name + break + + # new frigate:0.13.0-beta3 stat 'cmdline' + label.append(n) # name label + label.append(stats['cpu_usages'][b_pid]['cmdline']) # process label + label.append('Other') # type label + label.append(stats['cpu_usages'][b_pid]['cmdline']) # cmdline label + add_metric(bandwidth_usages, label, b_stats, 'bandwidth') + except KeyError: + pass + except KeyError: + pass + + yield bandwidth_usages + # count events events = [] try: