-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkamailio_recording_exporter
90 lines (68 loc) · 4.11 KB
/
kamailio_recording_exporter
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
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3.4
import inspect
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))))
import threading
from http.server import HTTPServer
import socket
import time
from prometheus.collectors import Gauge
from prometheus.registry import Registry
from prometheus.exporter import PrometheusMetricHandler
PORT_NUMBER = 9255
def gather_data(registry):
"""Gathers the metrics"""
host = socket.gethostname()
asterisk_total_active_channels_metric = Gauge("asterisk_active_channels", "Total current acitve channels",
{'host': host})
asterisk_total_active_calls_metric = Gauge("asterisk_active_calls", "Total current acitve calls",
{'host': host})
asterisk_total_calls_processed_metric = Gauge("asterisk_calls_processed", "Total current calls processed",
{'host': host})
asterisk_total_sip_peers_metric = Gauge("asterisk_sip_peers", "Total sip peers",
{'host': host})
asterisk_total_sip_peers_online_metric = Gauge("asterisk_sip_peers_online", "Total sip peers online",
{'host': host})
asterisk_total_sip_peers_offline_metric = Gauge("asterisk_sip_peers_offline", "Total sip peers offline",
{'host': host})
asterisk_total_core_uptime_metric = Gauge("asterisk_core_uptime", "Total core uptime",
{'host': host})
kamailio_active_recording_total_metric = Gauge("kamailio_active_recording_total", "Kamailio active recording total",
{'host': host})
kamailio_active_call_total_metric = Gauge("kamailio_active_call_total", "Kamailio active call total",
{'host': host})
kamailio_current_connections_total_metric = Gauge("kamailio_current_connections_total", "Kamailio current connections total",
{'host': host})
kamailio_max_connections_total_metric = Gauge("kamailio_max_connections_total_metric", "Kamailio max connections total",
{'host': host})
registry.register(kamailio_active_recording_total_metric)
registry.register(kamailio_active_call_total_metric)
registry.register(kamailio_current_connections_total_metric)
registry.register(kamailio_max_connections_total_metric)
while True:
time.sleep(1)
command_kamailio_active_recording = "ls /tmp/rtpengine/recording/ | wc -l"
command_kamailio_active_call = "kamctl rpc dlg.stats_active | grep all | awk '{print $2}'"
command_kamailio_current_connections = "kamcmd stats.get_statistics all | grep ws_sip_current_connections | awk '{print $3}'"
command_kamailio_max_connections = "kamcmd stats.get_statistics all | grep 'websocket:ws_sip_max_concurrent_connections' | awk '{print $3}'"
kamailio_active_recording = os.popen(command_kamailio_active_recording).read()
kamailio_active_recording_total_metric.set({'type': "kamailio_active_recording", }, kamailio_active_recording)
kamailio_active_call = os.popen(command_kamailio_active_call).read()
kamailio_active_call_total_metric.set({'type': "kamailio_active_call", }, kamailio_active_call)
kamailio_current_connections = os.popen(command_kamailio_current_connections).read()
kamailio_current_connections_total_metric.set({'type': "kamailio_current_connections", }, kamailio_current_connections)
kamailio_max_connections = os.popen(command_kamailio_max_connections).read()
kamailio_max_connections_total_metric.set({'type': "kamailio_max_connections", }, kamailio_max_connections)
if __name__ == "__main__":
registry = Registry()
thread = threading.Thread(target=gather_data, args=(registry, ))
thread.start()
try:
def handler(*args, **kwargs):
PrometheusMetricHandler(registry, *args, **kwargs)
server = HTTPServer(('', PORT_NUMBER), handler)
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
thread.join()