diff --git a/afsmon/__init__.py b/afsmon/__init__.py index 924b53f..92ad31e 100644 --- a/afsmon/__init__.py +++ b/afsmon/__init__.py @@ -12,21 +12,19 @@ # under the License. import collections -import logging import io -import sys -import subprocess +import logging import re +import subprocess + from datetime import datetime from enum import Enum from prettytable import PrettyTable + logger = logging.getLogger("afsmon") -# -# Fileserver -# class FileServerStatus(Enum): NORMAL = 0 @@ -41,7 +39,8 @@ Partition = collections.namedtuple( Volume = collections.namedtuple( 'Voume', 'volume, id, perms, used, quota, percent_used') -class FileServerStats: + +class FileServerStats(object): '''AFS fileserver status Call ``get_stats()`` to populate the statistics for the server. @@ -75,19 +74,18 @@ class FileServerStats: # Matching: # mirror.yum-puppetlabs.readonly 536871036 RO 63026403 K On-line vol_regex = re.compile( - '^(?P[^\s]+)\s+(?P\d+)\s(?PR[OW])\s+(?P\d+) K' + '^(?P[^\s]+)\s+(?P\d+)\s(?PR[OW])\s+(?P\d+) K' ) # Read the output into chunks where each chunk is the info for # one volume. - chunks = [] lines = io.StringIO(output) while True: line = lines.readline() if not line: break chunk = '' - if "On-line" in line: # chunks start with this + if "On-line" in line: # chunks start with this chunk += line # read in the next 9 lines of status for i in range(8): @@ -103,7 +101,6 @@ class FileServerStats: Volume(m['vol'], m['id'], m['perms'], used, quota, percent_used)) - def _get_calls_waiting(self): cmd = ["rxdebug", self.hostname, "7000", "-rxstats", "-noconns"] logger.debug("Running: %s" % cmd) @@ -191,7 +188,7 @@ class FileServerStats: self.table.add_row(["%s free" % n, p.free]) self.table.add_row(["%s total" % n, p.total]) self.table.add_row(["%s %%used" % n, - "%s%%" % p.percent_used]) + "%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. diff --git a/afsmon/cmd/main.py b/afsmon/cmd/main.py index b13cfd6..bd1155f 100644 --- a/afsmon/cmd/main.py +++ b/afsmon/cmd/main.py @@ -15,14 +15,15 @@ import argparse import configparser import logging import os -import sys import statsd +import sys import afsmon logger = logging.getLogger("afsmon.main") -class AFSMonCmd: + +class AFSMonCmd(object): def cmd_show(self): for fs in self.fileservers: @@ -58,7 +59,7 @@ class AFSMonCmd: hn = f.hostname.replace('.', '_') self.statsd.gauge('afs.%s.idle_threads' % hn, f.idle_threads) - self.statsd.gauge('afs.%s.calls_waiting'% hn, f.calls_waiting) + self.statsd.gauge('afs.%s.calls_waiting' % hn, f.calls_waiting) for p in f.partitions: self.statsd.gauge( 'afs.%s.part.%s.used' % (hn, p.partition), p.used) @@ -75,7 +76,6 @@ class AFSMonCmd: self.statsd.gauge( 'afs.%s.vol.%s.quota' % (hn, vn), v.quota) - def main(self, args=None): if args is None: args = sys.argv[1:] @@ -107,7 +107,8 @@ class AFSMonCmd: logger.debug("Debugging enabled") if not os.path.exists(self.args.config): - raise ValueError("Config file %s does not exist" % self.args.config) + raise ValueError("Config file %s does not exist" % + self.args.config) self.config = configparser.RawConfigParser() self.config.read(self.args.config) diff --git a/afsmon/tests/base.py b/afsmon/tests/base.py index 3cf15c3..7d76df5 100644 --- a/afsmon/tests/base.py +++ b/afsmon/tests/base.py @@ -13,20 +13,21 @@ # License for the specific language governing permissions and limitations # under the License. -import os - -import logging import fixtures +import logging +import os import select import socket import testtools import threading import time + _TRUE_VALUES = ('True', 'true', '1', 'yes') logger = logging.getLogger("afsmon.tests.base") + class FakeStatsd(threading.Thread): def __init__(self): threading.Thread.__init__(self) diff --git a/afsmon/tests/test_afsmon.py b/afsmon/tests/test_afsmon.py index 753fa5e..be79fa1 100644 --- a/afsmon/tests/test_afsmon.py +++ b/afsmon/tests/test_afsmon.py @@ -12,8 +12,8 @@ import afsmon import configparser -from afsmon.tests import base from afsmon.cmd.main import AFSMonCmd +from afsmon.tests import base """ test_afsmon @@ -22,6 +22,7 @@ test_afsmon Tests for `afsmon` module. """ + class TestPyAFSMon(base.TestCase): def setUp(self): @@ -68,4 +69,3 @@ class TestPyAFSMon(base.TestCase): self.assertReportedStat( 'afs.afs01_dfw_openstack_org.vol.mirror_moo.quota', value='2048', kind='g') -