Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Recompile information from ping statictic line to avoid problems with…

… log reader
  • Loading branch information...
commit 6d10bb9472f1a5e55e3e75f62fb0d4a43c1c668e 1 parent 174b782
@kachayev authored
Showing with 12 additions and 3 deletions.
  1. +12 −3 gearoscope/apps/monitor/agents/pingator.py
View
15 gearoscope/apps/monitor/agents/pingator.py
@@ -8,7 +8,8 @@
many separate threads.
"""
-import subprocess
+import re
+from subprocess import Popep, PIPE
from sonar.logger import DictLogRecord, Log
class PingLogRecord(DictLogRecord):
@@ -34,6 +35,9 @@ class PingAgent(object):
# with "lazy" idea (when work method will be called only)
log = None
+ STAT_LINE = re.compile(r'(?P<received>\d) received, (?P<lost>[\d]+)% packet loss, time (?P<time>[\d]+)ms')
+ RTT_LINE = re.compile(r'rtt min/avg/max/mdev = (?P<rtt>\S+) ms')
+
def __init__(self, server):
self.server = server
@@ -44,6 +48,11 @@ def work(self):
self.log.info(PingLogRecord(self.ping(4), server={'host': self.server.host}))
def ping(count=4):
- cmd = ['ping', self.server.host, '-c', str(count)]
- return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[-1]
+ stat = {}
+
+ ping = '\n'.join(Popen(['ping', self.server.host, '-c', str(count)], stdout=PIPE).communicate())
+ stat.update(STAT_LINE.findall(ping))
+ stat.update(RTT_LINE.findall(ping))
+
+ return stat
Please sign in to comment.
Something went wrong with that request. Please try again.