mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-04 18:25:22 +03:00
wip
This commit is contained in:
parent
d97fa99ec5
commit
bada7db290
@ -6,6 +6,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
from prometheus_client import REGISTRY, generate_latest
|
||||||
import pytz
|
import pytz
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@ -35,6 +36,7 @@ from frigate.config import FrigateConfig
|
|||||||
from frigate.const import CLIPS_DIR, MAX_SEGMENT_DURATION, RECORD_DIR
|
from frigate.const import CLIPS_DIR, MAX_SEGMENT_DURATION, RECORD_DIR
|
||||||
from frigate.models import Event, Recordings
|
from frigate.models import Event, Recordings
|
||||||
from frigate.object_processing import TrackedObject
|
from frigate.object_processing import TrackedObject
|
||||||
|
from frigate.prometheus_exporter import FrigateCollector
|
||||||
from frigate.stats import stats_snapshot
|
from frigate.stats import stats_snapshot
|
||||||
from frigate.util import (
|
from frigate.util import (
|
||||||
clean_camera_user_pass,
|
clean_camera_user_pass,
|
||||||
@ -81,6 +83,8 @@ def create_app(
|
|||||||
|
|
||||||
app.register_blueprint(bp)
|
app.register_blueprint(bp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
@ -820,6 +824,12 @@ def stats():
|
|||||||
return jsonify(stats)
|
return jsonify(stats)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/metrics")
|
||||||
|
def metrics():
|
||||||
|
|
||||||
|
return generate_latest()
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/<camera_name>")
|
@bp.route("/<camera_name>")
|
||||||
def mjpeg_feed(camera_name):
|
def mjpeg_feed(camera_name):
|
||||||
fps = int(request.args.get("fps", "3"))
|
fps = int(request.args.get("fps", "3"))
|
||||||
|
|||||||
40
frigate/prometheus_exporter.py
Normal file
40
frigate/prometheus_exporter.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
from typing import Dict
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
from os import path
|
||||||
|
from urllib.request import urlopen
|
||||||
|
import yaml
|
||||||
|
from prometheus_client.core import GaugeMetricFamily, REGISTRY, CounterMetricFamily
|
||||||
|
|
||||||
|
|
||||||
|
def add_metric(metric, label, data, key, multiplier=1.0):
|
||||||
|
try:
|
||||||
|
string = str(data[key])
|
||||||
|
value = float(re.findall(r'\d+', string)[0])
|
||||||
|
metric.add_metric([label], value * multiplier)
|
||||||
|
except (KeyError, TypeError, IndexError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class FrigateCollector(object):
|
||||||
|
|
||||||
|
def __init__ (self, metricsobject, dataobject):
|
||||||
|
self.metricsobject = metricsobject
|
||||||
|
self.dataobject = dataobject
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def collect(self):
|
||||||
|
|
||||||
|
|
||||||
|
class PromMetricsClass:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.metrics = dict()
|
||||||
|
|
||||||
|
class PromDataClass:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.values_in = dict()
|
||||||
|
self.values_out = dict()
|
||||||
Loading…
Reference in New Issue
Block a user