-# Copyright (C) 2009-2012 Internet Systems Consortium.
+# Copyright (C) 2009-2013 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
def tearDown(self):
time.time = self.orig_time_time
# clear all statistics counters after each test
- counter.clear_counters()
+ self.conn._counters.clear_all()
super().tearDown()
def __create_mock_tsig(self, key, error, has_last_signature=True):
self.conn.response_generator = self._create_soa_response_data
# check the statistics counters
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_soaoutv4, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'soaoutv4')
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_soaoutv6, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'soaoutv6')
self.assertEqual(self.conn._check_soa_serial(), XFRIN_OK)
- self.assertEqual(1, counter.get_soaoutv4(TEST_ZONE_NAME_STR))
- self.assertEqual(0, counter.get_soaoutv6(TEST_ZONE_NAME_STR))
+ self.assertEqual(1, self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'soaoutv4'))
+ self.assertEqual(0, self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'soaoutv6'))
def test_soacheck_with_bad_response(self):
self.conn.response_generator = self._create_broken_response_data
self.conn.response_generator = self._create_normal_response_data
# check the statistics counters
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_axfrreqv4, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'axfrreqv4')
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_axfrreqv6, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'axfrreqv6')
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_ixfrreqv4, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'ixfrreqv4')
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_ixfrreqv6, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'ixfrreqv6')
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_xfrsuccess, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'xfrsuccess')
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_time_to_axfr, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'time_to_axfr')
self.assertEqual(self.conn.do_xfrin(False), XFRIN_OK)
self.assertFalse(self.conn._datasrc_client._journaling_enabled)
self.assertEqual(177, self.conn._transfer_stats.byte_count)
self.assertGreater(self.conn._transfer_stats.get_running_time(), 0)
self.assertEqual(1,
- counter.get_axfrreqv4(TEST_ZONE_NAME_STR))
+ self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'axfrreqv4'))
self.assertEqual(0,
- counter.get_axfrreqv6(TEST_ZONE_NAME_STR))
+ self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'axfrreqv6'))
self.assertEqual(0,
- counter.get_ixfrreqv4(TEST_ZONE_NAME_STR))
+ self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'ixfrreqv4'))
self.assertEqual(0,
- counter.get_ixfrreqv6(TEST_ZONE_NAME_STR))
+ self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'ixfrreqv6'))
self.assertEqual(1,
- counter.get_xfrsuccess(TEST_ZONE_NAME_STR))
- self.assertGreater(counter.get_time_to_axfr(TEST_ZONE_NAME_STR),
+ self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'xfrsuccess'))
+ self.assertGreater(self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'time_to_axfr'),
0.0)
def test_do_xfrin_with_tsig(self):
self.conn.response_generator = self._create_normal_response_data
# check the statistics counters
self.assertRaises(isc.cc.data.DataNotFoundError,
- counter.get_xfrfail, TEST_ZONE_NAME_STR)
+ self.conn._counters.get, 'zones', TEST_ZONE_NAME_STR, 'xfrfail')
self.assertEqual(self.conn.do_xfrin(False), XFRIN_FAIL)
self.assertEqual(1, self.conn._tsig_ctx.verify_called)
- self.assertEqual(1, counter.get_xfrfail(TEST_ZONE_NAME_STR))
+ self.assertEqual(1, self.conn._counters.get('zones', TEST_ZONE_NAME_STR, 'xfrfail'))
def test_do_xfrin_without_last_tsig(self):
# TSIG verify will succeed, but it will pretend the last message is
#!@PYTHON@
-# Copyright (C) 2009-2012 Internet Systems Consortium.
+# Copyright (C) 2009-2013 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
from functools import reduce
from optparse import OptionParser, OptionValueError
from isc.config.ccsession import *
-from isc.statistics import counter
+from isc.statistics import Counters
from isc.notify import notify_out
import isc.util.process
from isc.datasrc import DataSourceClient, ZoneFinder
XFRIN_OK = 0 # normal success
XFRIN_FAIL = 1 # general failure (internal/external)
-# setup statistics counter
-counter.init(SPECFILE_LOCATION)
-
class XfrinException(Exception):
pass
# keep a record of this specific transfer to log on success
# (time, rr/s, etc)
self._transfer_stats = XfrinTransferStats()
+ self._counters = Counters(SPECFILE_LOCATION)
def init_socket(self):
'''Initialize the underlyig socket.
self._send_query(RRType.SOA)
# count soaoutv4 or soaoutv6 requests
- getattr(counter,
- 'inc_soaout%s' % self.get_ipver_str())\
- (self._zone_name)
+ self._counters.inc('zones', self._zone_name,
+ 'soaout' + self.get_ipver_str())
data_len = self._get_request_response(2)
msg_len = socket.htons(struct.unpack('H', data_len)[0])
soa_response = self._get_request_response(msg_len)
raise XfrinException('Unable to reconnect to master')
# start statistics timer
- getattr(counter,
- 'start_time_to_%s' % req_str.lower())(self._zone_name)
+ self._counters.start_timer('zones', self._zone_name,
+ 'time_to_' + req_str.lower())
logger.info(XFRIN_XFR_TRANSFER_STARTED, req_str, self.zone_str())
self._send_query(self._request_type)
# count (A|X)IXFR requests for statistics
- getattr(counter,
- 'inc_%sreq%s' % (req_str.lower(), self.get_ipver_str()))\
- (self._zone_name)
+ self._counters.inc('zones', self._zone_name,
+ req_str.lower() + 'req' +
+ self.get_ipver_str())
self.__state = XfrinInitialSOA()
self._handle_xfrin_responses()
# Depending what data was found, we log different status reports
"%.3f" % self._transfer_stats.get_running_time(),
"%.f" % self._transfer_stats.get_bytes_per_second()
)
- # stop start timer
- getattr(counter,
- 'stop_time_to_%s' % req_str.lower())(self._zone_name)
+ # stop statistics timer
+ self._counters.stop_timer('zones', self._zone_name,
+ 'time_to_' + req_str.lower())
except XfrinZoneUptodate:
# Eventually we'll probably have to treat this case as a trigger
self._diff = None
if ret == XFRIN_OK:
# count successful xfer requests
- counter.inc_xfrsuccess(self._zone_name)
+ self._counters.inc('zones', self._zone_name, 'xfrsuccess')
elif ret == XFRIN_FAIL:
# count failed xfer requests
- counter.inc_xfrfail(self._zone_name)
+ self._counters.inc('zones', self._zone_name, 'xfrfail')
return ret
self._cc_setup()
self.recorder = XfrinRecorder()
self._shutdown_event = threading.Event()
+ self._counters = Counters(SPECFILE_LOCATION)
def _cc_setup(self):
'''This method is used only as part of initialization, but is
# that a log becomes too verbose. Because the
# b10-stats daemon is periodically asking to the
# b10-xfrin daemon.
- answer = create_answer(0, counter.dump_statistics())
+ answer = create_answer(0, self._counters.get_statistics())
logger.debug(DBG_XFRIN_TRACE, \
XFRIN_RECEIVED_GETSTATS_COMMAND, \
str(answer))