Skip to content

Commit d540962

Browse files
author
Lukas Wingerberg
committed
add some prometheus metrics
1 parent 4f37b0c commit d540962

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

server/grpc-ffmpeg.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@
4040
health_status = {'healthy': False}
4141

4242
# Prometheus metrics
43+
binary_counters = {
44+
binary: Counter(f"{binary}_commands", f"Number of {binary} commands executed")
45+
for binary in ALLOWED_BINARIES
46+
}
4347
ffmpeg_process_gauge = Gauge("ffmpeg_process_count", "Number of running ffmpeg processes")
44-
mediainfo_counter = Counter("mediainfo_commands", "Number of mediainfo commands executed")
45-
ffprobe_counter = Counter("ffprobe_commands", "Number of ffprobe commands executed")
48+
4649

4750
class TokenAuthValidator(grpc.AuthMetadataPlugin):
4851
def __call__(self, context, callback):
@@ -103,11 +106,11 @@ async def read_stream(stream, response_type, stream_name):
103106
exit_code = process.returncode
104107
yield ffmpeg_pb2.CommandResponse(exit_code=exit_code, stream="exit_code")
105108

106-
# Update metrics
107-
if "mediainfo" in tokens[0]:
108-
mediainfo_counter.inc()
109-
elif "ffprobe" in tokens[0]:
110-
ffprobe_counter.inc()
109+
# Update metrics dynamically based on binary executed
110+
for binary in ALLOWED_BINARIES:
111+
if binary in tokens[0]:
112+
binary_counters[binary].inc()
113+
break
111114
finally:
112115
if "ffmpeg" in tokens[0] and HEALTHCHECK_FILE not in tokens:
113116
ffmpeg_process_gauge.dec()

0 commit comments

Comments
 (0)