Dan Kenigsberg has uploaded a new change for review.
Change subject: introduce connectivity log
......................................................................
introduce connectivity log
Users have been requesting to have access to a simple log file that
tracks host connectivity. This patch adds /var/log/vdsm/connectivity.log
for that purpose. It adds a line for any change of connectivity of
tracked interfaces.
Note that the connectivity change is not implemented with `ip monitor`,
since the latter seems to ignore link speed changes, which are required
to be logged.
Bug-Url:
https://bugzilla.redhat.com/1111234
Change-Id: I86dc41223babe43194add7ce778c6567b2bc5823
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M tests/samplingTests.py
M vdsm/logger.conf.in
M vdsm/virt/sampling.py
3 files changed, 64 insertions(+), 8 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/29472/1
diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index 9890dd3..f2fc59b 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -22,6 +22,7 @@
import tempfile
import shutil
+from vdsm import ipwrapper
import virt.sampling as sampling
from testrunner import VdsmTestCase as TestCaseBase
@@ -101,3 +102,11 @@
with MonkeyPatchScope([(sampling, '_PROC_STAT_PATH',
self._extra_path)]):
self.assertEquals(sampling.getBootTime(), 1395249141)
+
+class InterfaceSampleTests(TestCaseBase):
+ def testDiff(self):
+ lo = ipwrapper.getLink('lo')
+ s0 = sampling.InterfaceSample(lo)
+ s1 = sampling.InterfaceSample(lo)
+ s1.operstate = 'x'
+ self.assertEquals('operstate:x', s1.connlog_diff(s0))
diff --git a/vdsm/logger.conf.in b/vdsm/logger.conf.in
index 5b0cf63..87159e4 100644
--- a/vdsm/logger.conf.in
+++ b/vdsm/logger.conf.in
@@ -1,8 +1,8 @@
[loggers]
-keys=root,vds,Storage,ovirt_hosted_engine_ha
+keys=root,vds,Storage,ovirt_hosted_engine_ha,connectivity
[handlers]
-keys=console,syslog,logfile
+keys=console,syslog,logfile,connlogfile
[formatters]
keys=long,simple,none,sysform
@@ -30,6 +30,12 @@
qualname=ovirt_hosted_engine_ha
propagate=1
+[logger_connectivity]
+level=DEBUG
+handlers=connlogfile
+qualname=connectivity
+propagate=0
+
[handler_syslog]
level=WARNING
class=handlers.SysLogHandler
@@ -43,13 +49,20 @@
level=DEBUG
formatter=long
+[handler_connlogfile]
+class=logging.handlers.WatchedFileHandler
+args=('@VDSMLOGDIR(a)/connectivity.log',)
+filters=storage.misc.TracebackRepeatFilter
+level=DEBUG
+formatter=simple
+
[handler_console]
class: StreamHandler
args: []
formatter: none
[formatter_simple]
-format: %(name)s:%(levelname)s: %(message)s
+format: %(asctime)s:%(levelname)s:%(message)s
[formatter_none]
format: %(message)s
@@ -60,8 +73,3 @@
[formatter_sysform]
format= vdsm %(name)s %(levelname)s %(message)s
datefmt=
-
-
-
-
-
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index f87a15f..591ba7f 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -123,6 +123,23 @@
self.operstate = self.readIfaceOperstate(ifid)
self.speed = self._getLinkSpeed(link)
+ _LOGGED_ATTRS = ('operstate', 'speed')
+
+ def _log_attrs(self, attrs):
+ return ' '.join(
+ '%s:%s' % (attr, getattr(self, attr)) for attr in attrs )
+
+ def to_connlog(self):
+ return self._log_attrs(self._LOGGED_ATTRS)
+
+ def connlog_diff(self, other):
+ """Return a textual description of the interesting stuff new to
self
+ and missing in 'other'."""
+
+ return self._log_attrs(
+ attr for attr in self._LOGGED_ATTRS
+ if getattr(self, attr) != getattr(other, attr))
+
class TotalCpuSample:
"""
@@ -273,6 +290,20 @@
self.thpState = 'never'
self.cpuCores = CpuCoreSample()
self.numaNodeMem = NumaNodeMemorySample()
+
+ def to_connlog(self):
+ return ', '.join(
+ ('%s:(%s)' % (ifid, ifacesample.to_connlog()))
+ for (ifid, ifacesample) in self.interfaces.iteritems())
+
+ def connlog_diff(self, other):
+ text = ''
+ for ifid, sample in self.interfaces.iteritems():
+ if ifid in other.interfaces:
+ text += sample.connlog_diff(other.interfaces[ifid])
+ else:
+ text += 'new (%s) ' % sample.to_connlog()
+ return text
class AdvancedStatsFunction(object):
@@ -443,6 +474,7 @@
"""
AVERAGING_WINDOW = 5
SAMPLE_INTERVAL_SEC = 2
+ _CONNLOG = logging.getLogger('connectivity')
def __init__(self, log):
self.startTime = time.time()
@@ -473,6 +505,13 @@
try:
sample = self.sample()
self._samples.append(sample)
+ if len(self._samples) == 1:
+ self._CONNLOG.debug('%s', sample.to_connlog())
+ else:
+ diff = sample.connlog_diff(self._samples[-2])
+ if diff:
+ self._CONNLOG.debug('%s', diff)
+
self._lastSampleTime = sample.timestamp
if len(self._samples) > self.AVERAGING_WINDOW:
self._samples.pop(0)
--
To view, visit
http://gerrit.ovirt.org/29472
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I86dc41223babe43194add7ce778c6567b2bc5823
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>