Skip to content

Commit

Permalink
fix bandwidth stats
Browse files Browse the repository at this point in the history
  • Loading branch information
bairhys committed Mar 11, 2024
1 parent 54bec9c commit 9b4af20
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions prometheus_frigate_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ def collect(self):
yield detection_fps
yield process_fps
yield skipped_fps

# bandwidth stats
bandwidth_usages = GaugeMetricFamily('frigate_bandwidth_usages_kBps', 'bandwidth usages kilobytes per second', labels=['pid', 'name', 'process', '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(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

# detector stats
try:
Expand Down Expand Up @@ -260,32 +285,6 @@ 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:
Expand Down

0 comments on commit 9b4af20

Please sign in to comment.