-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsilent-check-prom.py
79 lines (64 loc) · 1.91 KB
/
silent-check-prom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!{{ sc__venv }}/bin/python
# {{ ansible_managed }}
import argparse
parser = argparse.ArgumentParser(description='Receive information from liquidsoap scripts')
parser.add_argument(
'--source',
required=True,
help='The name of the source',
metavar='stream',
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'--blank',
action='store_false',
help='Specify this flag if blank is detected',
dest='noise',
)
group.add_argument(
'--noise',
action='store_true',
help='Specify this flag if noise is detected',
dest='noise',
)
parser.add_argument(
'--min_noise',
default=0.0,
type=float,
help='The value of min_noise of the on_blank function in seconds',
)
parser.add_argument(
'--max_blank',
default=20.0,
type=float,
help='The value of max_blank of the on_blank function in seconds',
)
parser.add_argument(
'--threshold',
default=-40.0,
type=float,
help='The value of threshold of the on_blank function in decibels',
)
args = parser.parse_args()
print(args)
import srvlookup
rr = srvlookup.lookup('pushgateway', domain='consul')
if len(rr) == 0:
raise RuntimeError('no pushgateway found')
rr = rr[0]
addr = '%s:%s' % (rr.host, rr.port)
from prometheus_client import Gauge, CollectorRegistry, push_to_gateway
registry = CollectorRegistry()
g = Gauge(
'silent_check_stream_noise',
'Result of liquidsoap stream blank detection',
[
'source',
'min_noise',
'max_blank',
'threshold'
],
registry=registry
)
g.labels(source=args.source, min_noise=args.min_noise, max_blank=args.max_blank, threshold=args.threshold).set(args.noise)
push_to_gateway(addr, job='silent_checker', grouping_key={'source': args.source}, registry=registry)