Not sure if anyone is using "latency measurement" feature in Kamailio dispatcher module, I thought I could share a very simple Python script that I am using to monitor remote gateway using this.
Sample Script is attached, it will post data to statsd and is working in cron The feature can be enabled : 3.27. ds_ping_latency_stats (int) Enable latency measurement when pinging nodes If set to 0, disable latency measurement. If set to 1, enable latency measurement https://www.kamailio.org/docs/modules/devel/modules/dispatcher.html#dispatcher.p.ds_ping_latency_stats This is one use case of this feature, another one will be to load balance based on congestion detected on latency, I am planning to share a lab experiment in a little while. Regards
#!/usr/bin/python import subprocess from time import sleep import time # URI: sip:10.10.1.1:5060 #0 FLAGS: AP #1 PRIORITY: 12 #2 LATENCY: { #3 AVG: 30.529000 #4 STD: 4.849000 #5 EST: 30.999000 #6 MAX: 1270 #7 TIMEOUT: 0 def server_stats(ip): idx = -1 for line in dlist.splitlines(): if idx == 5: est_latency = line.strip() if idx == 7: timeout = line.strip() if idx >= 0: idx = idx + 1 if line.find("URI: sip:{}".format(ip)) > 0: idx = 0 if timeout[:9] == "TIMEOUT: ": timeout_count = timeout[9:] cmd = "echo \"fastlink.timeout.{}:{}|g\" | nc -w 1 -u 127.0.0.1 8125".format(ip, timeout_count) subprocess.call(cmd, shell=True) print(cmd) if est_latency[:5] == "EST: ": latency = est_latency[5:] cmd = "echo \"fastlink.latency.{}:{}|g\" | nc -w 1 -u 127.0.0.1 8125".format(ip, latency) subprocess.call(cmd, shell=True) print("est latency:{}".format(latency)) servers = ["10.40.5.175", "10.40.2.233", "10.40.1.103"] interval = 10 it = 0 while it < 6: # while 1: ts = time.time() print("[{}]now:{}".format(it,ts)) next_ts = ts + 10 it = it + 1 dlist = subprocess.check_output(["/usr/bin/docker","exec","kamailio","kamcmd","dispatcher.list"]) for ip in servers: print(ip) server_stats(ip) ts = time.time() print("sleeping:{}".format(next_ts - ts)) wait_ts = next_ts - ts; if wait_ts < 0: wait_ts = 7 sleep(wait_ts)
_______________________________________________ Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users