[AETHER-1278]: Obtain ping DNS averages on modem and adb agents
Change-Id: I58ebd40f192544916843dfd6d5dd60998f2d2f4d
diff --git a/edge-monitoring/agent_adb/edge_monitoring_agent_adb.py b/edge-monitoring/agent_adb/edge_monitoring_agent_adb.py
index af81d5e..9d808b5 100755
--- a/edge-monitoring/agent_adb/edge_monitoring_agent_adb.py
+++ b/edge-monitoring/agent_adb/edge_monitoring_agent_adb.py
@@ -46,7 +46,9 @@
ADB_GET_COMMANDS = {
"apn_mode": "settings get global airplane_mode_on",
"lte_state": "dumpsys telephony.registry | grep -m1 mDataConnectionState",
- "ping_result": "ping -c 3 8.8.8.8&>/dev/null; echo $?"
+ "ping_result": "ping -c 3 8.8.8.8&>/dev/null; echo $?",
+ "ping_dns_result": "ping -c 10 " + "8.8.8.8" +
+ " | tail -1 | awk '{print $4}'"
}
ADB_APN_COMMANDS = {
"home": "input keyevent 3",
@@ -73,6 +75,16 @@
'status': {
'control_plane': None,
'user_plane': 'connected'
+ },
+ 'speedtest': {
+ 'ping': {
+ 'dns': {
+ 'min': None,
+ 'avg': None,
+ 'max': None,
+ 'stddev': None
+ }
+ }
}
}
@@ -138,6 +150,39 @@
return state, None
+def run_ping_test(adb, ip, count):
+ '''
+ Runs the ping test
+ Input: IP to ping, # times to ping
+ Returns: dict of the min/avg/max/stddev numbers from the ping command result
+ '''
+ result = {'min': None,
+ 'avg': None,
+ 'max': None,
+ 'stddev': None}
+ try:
+ commandResult, commandOutput = _run_adb_shell(adb, ADB_GET_COMMANDS['ping_dns_result'])
+ pingResult = commandOutput.split("/")
+ result = {'min': float(pingResult[0]),
+ 'avg': float(pingResult[1]),
+ 'max': float(pingResult[2]),
+ 'stddev': float(pingResult[3])}
+ except Exception as e:
+ logging.error("Ping test failed for " + ip + ": %s", e)
+ return result
+
+
+def get_ping_test(adb):
+ '''
+ Each ping test result saves the min/avg/max/stddev to dict.
+ 1) Performs ping test to Google Public DNS for 10 iterations.
+ 2) # TODO: Performs ping to device on network.
+ '''
+ speedtest_ping = {}
+ speedtest_ping['dns'] = run_ping_test(adb, "8.8.8.8", 10)
+ return speedtest_ping
+
+
def report_aether_network_state():
'''
report the aether network state to the monitoring server
@@ -176,9 +221,11 @@
_run_adb_shell(adb, "svc power stayon true")
cp_state, err = get_control_plane_state(adb)
up_state, err = get_user_plane_state(adb)
+ speedtest_ping = get_ping_test(adb)
edge_status['status']['control_plane'] = cp_state.name
edge_status['status']['user_plane'] = up_state.name
+ edge_status['speedtest']['ping'] = speedtest_ping
report_aether_network_state()
_run_adb_shell(adb, "svc power stayon false")