blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
18.2k stars 1.66k forks source link

Keep statistics of total frame count as well as average frame rate for time series databases #13686

Open dsnet opened 1 week ago

dsnet commented 1 week ago

Hi, thank you for your hard work on Frigate.

The /api/stats API currently exposes fields like:

alley-left: {
    audio_dBFS: 0,
    audio_rms: 0,
    camera_fps: 5.1,
    capture_pid: 955,
    detection_enabled: true,
    detection_fps: 0,
    ffmpeg_pid: 961,
    pid: 812,
    process_fps: 5.1,
    skipped_fps: 0
},

In particular, fields like camera_fps (and related fields) report a metric that's a rate (some quantity per time). This is fundamentally hard to scrape since the consumer now needs to know the sampling rate at which this metric is updated. If the field is scraped too slowly, then the consumer may miss sudden dips or spikes in the rate.

Instead of (or in addition to) reporting a rate, I propose that we provide a monotonically increasing counter. So instead of camera_fps, it would be camera_frames, which is the total number of camera frames seen. If this data is being dumped into prometheus or influxdb, it's trivial to take the derivative to produce a more accurate rate (one that cannot miss dips and peaks).

jrcichra commented 6 days ago

This would also be useful for alerting when a camera is offline. Right now I don't see a way from /api/stats to see if a camera stream isn't working. If the frame count was available and weren't increasing that would be one way to know.

NickM-27 commented 6 days ago

You can use camera_fps = 0 which is deliberately set if a camera goes offline. This is what the integration and webui already use