Add latest frigate version to stats endpoints (#3038)

* Add latest version to stats in mqtt and http

* Update json to include new field

* Update to use requests

* Don't use incorrect exception
This commit is contained in:
Nicolas Mowen 2022-04-11 06:10:19 -06:00 committed by GitHub
parent 35bd1de5ba
commit 58c32857d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -110,7 +110,8 @@ Sample response:
"service": {
/* Uptime in seconds */
"uptime": 10,
"version": "0.8.0-8883709",
"version": "0.10.1-8883709",
"latest_version": "0.10.1",
/* Storage data in MB for important locations */
"storage": {
"/media/frigate/clips": {

View File

@ -5,6 +5,7 @@ import time
import psutil
import shutil
import os
import requests
from frigate.config import FrigateConfig
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
@ -13,11 +14,22 @@ from frigate.version import VERSION
logger = logging.getLogger(__name__)
def get_latest_version() -> str:
request = requests.get('https://api.github.com/repos/blakeblackshear/frigate/releases/latest')
response = request.json()
if request.ok and response:
return response.get("tag_name", "unknown").replace("v", "")
else:
return "unknown"
def stats_init(camera_metrics, detectors):
stats_tracking = {
"camera_metrics": camera_metrics,
"detectors": detectors,
"started": int(time.time()),
"latest_frigate_version": get_latest_version(),
}
return stats_tracking
@ -83,6 +95,7 @@ def stats_snapshot(stats_tracking):
stats["service"] = {
"uptime": (int(time.time()) - stats_tracking["started"]),
"version": VERSION,
"latest_version": stats_tracking["latest_frigate_version"],
"storage": {},
"temperatures": get_temperatures(),
}