Add creation date, report RO volumes

After discussion, the best way to see if volumes are being released is
 to check the creation date.

This adds the creation date to reported volume stats, and also starts
reporting RO volumes by default too (skipping them was a theory to
reduce output, but they are important for seeing how releases are
working).

The creation date is reported in statsd with a unix timestamp gauge

Change-Id: I3feb4eac26bf1eb7196531b2d01029d28417e162
This commit is contained in:
Ian Wienand 2018-06-08 12:39:53 +10:00
parent 0c1cb59cc2
commit 1b0b447d51
3 changed files with 31 additions and 18 deletions

View File

@ -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<date>\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<date>\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)

View File

@ -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()

View File

@ -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')