Skip to content

Commit

Permalink
log and exit if FRIGATE_STATS_URL not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
bairhys committed Dec 13, 2023
1 parent ad688df commit dc7e614
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions prometheus_frigate_exporter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from prometheus_client.core import GaugeMetricFamily, InfoMetricFamily, REGISTRY
from prometheus_client import start_http_server
from urllib.request import urlopen
import json
import re
import time
import sys
import logging
import os
from urllib.request import urlopen
from urllib import error
from prometheus_client.core import GaugeMetricFamily, InfoMetricFamily, REGISTRY
from prometheus_client import start_http_server


def add_metric(metric, label, stats, key, multiplier=1.0):
Expand Down Expand Up @@ -199,21 +200,20 @@ def collect(self):

if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)

try:
url = str(os.environ.get('FRIGATE_STATS_URL', 'http://localhost:5000/api/stats'))
REGISTRY.register(CustomCollector(url))
except IndexError:
url = os.environ['FRIGATE_STATS_URL']
except KeyError:
logging.error(
"Provide Frigate stats url as environment variable to container, "
"e.g. FRIGATE_STATS_URL=http://<your-frigate-ip>:5000/api/stats")
exit()
sys.exit()

REGISTRY.register(CustomCollector(url))
port = int(os.environ.get('PORT', 9100))
start_http_server(port)

logging.info('Started, Frigate API URL: ' + url)
logging.info('Metrics at: http://localhost:' + str(port) + '/metrics')
logging.info('Started, Frigate API URL: %s', url)
logging.info('Metrics at: http://localhost:%d/metrics', port)

while True:
time.sleep(1)

0 comments on commit dc7e614

Please sign in to comment.