diff --git a/afsmon/__init__.py b/afsmon/__init__.py index ca1c93d..13b8742 100644 --- a/afsmon/__init__.py +++ b/afsmon/__init__.py @@ -37,7 +37,7 @@ Partition = collections.namedtuple( 'Partition', 'partition, used, free, total, percent_used') Volume = collections.namedtuple( - 'Voume', 'volume, id, perms, used, quota, percent_used') + 'Voume', 'volume, id, perms, used, quota, percent_used, creation') class FileServerStats(object): @@ -65,6 +65,12 @@ class FileServerStats(object): ''' + # Sample AFS timestamps: + # Tue Nov 2 03:35:15 2016 + # Tue Nov 22 03:35:15 2016 + AFS_DATE_REGEX = '(?P\w+ \w+\s+(\d{1,2}) \d+:\d+:\d+ \d+)' + AFS_DATE_STRPTIME = '%a %b %d %H:%M:%S %Y' + def _get_volumes(self): cmd = ["vos", "listvol", "-long", "-server", self.hostname] logger.debug("Running: %s" % cmd) @@ -97,9 +103,14 @@ class FileServerStats(object): used = int(m.group('used')) quota = int(q.group('quota')) percent_used = round(float(used) / float(quota) * 100, 2) + print(chunk) + c = re.search(r'Creation\s+%s' % self.AFS_DATE_REGEX, chunk) + creation = datetime.strptime(c.group('date'), + self.AFS_DATE_STRPTIME) + self.volumes.append( Volume(m.group('vol'), m.group('id'), m.group('perms'), - used, quota, percent_used)) + used, quota, percent_used, creation)) def _get_calls_waiting(self): cmd = ["rxdebug", self.hostname, "7000", "-rxstats", "-noconns"] @@ -148,11 +159,9 @@ class FileServerStats(object): if re.search('currently running normally', output): self.status = FileServerStatus.NORMAL - m = re.search( - r'last started at (?P\w+ \w+ \w+ \d+:\d+:\d+ \d+)', - output) + m = re.search(r'last started at %s' % self.AFS_DATE_REGEX, output) self.restart = datetime.strptime(m.group('date'), - '%a %b %d %H:%M:%S %Y') + self.AFS_DATE_STRPTIME) self.uptime = self.timestamp - self.restart elif re.search('temporarily disabled, currently shutdown', output): @@ -192,14 +201,12 @@ class FileServerStats(object): self.table.add_row(["%s %%used" % n, "%s%%" % p.percent_used]) for v in self.volumes: - # Only add the RW volumes to the table as for now we're - # mostly just worried about viewing the quota. - if v.perms == 'RW': - n = v.volume - self.table.add_row(["%s used" % n, v.used]) - self.table.add_row(["%s quota" % n, v.quota]) - self.table.add_row(["%s %%used" % n, - "%s%%" % v.percent_used]) + n = v.volume + self.table.add_row(["%s used" % n, v.used]) + self.table.add_row(["%s quota" % n, v.quota]) + self.table.add_row(["%s %%used" % n, + "%s%%" % v.percent_used]) + self.table.add_row(["%s creation" % n, v.creation]) def __str__(self): return str(self.table) diff --git a/afsmon/cmd/main.py b/afsmon/cmd/main.py index 53d8aa2..0f6c66a 100644 --- a/afsmon/cmd/main.py +++ b/afsmon/cmd/main.py @@ -74,13 +74,14 @@ class AFSMonCmd(object): pipe.gauge( 'afs.%s.part.%s.total' % (hn, p.partition), p.total) for v in f.volumes: - if v.perms != 'RW': - continue vn = v.volume.replace('.', '_') pipe.gauge( 'afs.%s.vol.%s.used' % (hn, vn), v.used) pipe.gauge( 'afs.%s.vol.%s.quota' % (hn, vn), v.quota) + pipe.gauge( + 'afs.%s.vol.%s.creation' % (hn, vn), + int(v.creation.strftime("%s"))) pipe.send() diff --git a/afsmon/tests/test_afsmon.py b/afsmon/tests/test_afsmon.py index be79fa1..6df1335 100644 --- a/afsmon/tests/test_afsmon.py +++ b/afsmon/tests/test_afsmon.py @@ -14,6 +14,7 @@ import configparser from afsmon.cmd.main import AFSMonCmd from afsmon.tests import base +from datetime import datetime """ test_afsmon @@ -37,9 +38,10 @@ class TestPyAFSMon(base.TestCase): a.idle_threads = 250 a.calls_waiting = 0 a.partitions = [afsmon.Partition('vicepa', 512, 512, 1024, 50.00)] + d = datetime.now() a.volumes = [ - afsmon.Volume('mirror.foo', 12345678, 'RW', 512, 1024, 50.00), - afsmon.Volume('mirror.moo', 87654321, 'RW', 1024, 2048, 50.00), + afsmon.Volume('mirror.foo', 12345678, 'RW', 512, 1024, 50.00, d), + afsmon.Volume('mirror.moo', 87654321, 'RW', 1024, 2048, 50.00, d), ] b = afsmon.FileServerStats('afs02.ord.openstack.org') @@ -69,3 +71,6 @@ class TestPyAFSMon(base.TestCase): self.assertReportedStat( 'afs.afs01_dfw_openstack_org.vol.mirror_moo.quota', value='2048', kind='g') + self.assertReportedStat( + 'afs.afs01_dfw_openstack_org.vol.mirror_foo.creation', + value=str(d.strftime("%s")), kind='g')