"""
return sep.join(args)
-class _Statistics():
- """Statistics data set. This class will be remove in the future
- release."""
- # default statistics data
- _data = {}
- # default statistics spec used in case the specfile is omitted when
- # constructing a Counters() object
- _spec = []
-
class Counters():
"""A class for holding and manipulating all statistics counters
for a module. A Counters object may be created by specifying a spec
timers can be temporarily disabled. If disabled, counter values are
not changed even if methods to update them are invoked."""
- # default statistics data set
- _statistics = _Statistics()
-
def __init__(self, spec_file_name=None):
"""A constructor for the Counters class. A path to the spec file
can be specified in spec_file_name. Statistics data based on
self._start_time = {}
self._disabled = False
self._rlock = threading.RLock()
+ self._statistics_data = {}
+ self._statistics_spec = []
if not spec_file_name: return
# change the default statistics spec
- self._statistics._spec = \
+ self._statistics_spec = \
isc.config.module_spec_from_file(spec_file_name).\
get_statistics_spec()
def clear_all(self):
"""clears all statistics data"""
with self._rlock:
- self._statistics._data = {}
+ self._statistics_data = {}
def disable(self):
"""disables incrementing/decrementing counters"""
identifier = _concat(*args)
with self._rlock:
if self._disabled: return
- _inc_counter(self._statistics._data,
- self._statistics._spec,
+ _inc_counter(self._statistics_data,
+ self._statistics_spec,
identifier, step)
def inc(self, *args):
of the specified counter. isc.cc.data.DataNotFoundError is
raised when the counter doesn't have a number yet."""
identifier = _concat(*args)
- return _get_counter(self._statistics._data, identifier)
+ return _get_counter(self._statistics_data, identifier)
def start_timer(self, *args):
"""Starts a timer which is identified by args and keeps it
# set the end time
_stop_timer(
start_time,
- self._statistics._data,
- self._statistics._spec,
+ self._statistics_data,
+ self._statistics_spec,
identifier)
# A datetime value of once used timer should be deleted
# for a future use.
stats module, including each counter. If nothing is counted
yet, then it returns an empty dictionary."""
# entire copy
- statistics_data = self._statistics._data.copy()
+ statistics_data = self._statistics_data.copy()
return statistics_data
import isc.config
from isc.statistics import counters
-class _Statistics():
- """Statistics data set. This class will be removed in the future
- release."""
- # default statistics data
- _data = {}
- # default statistics spec used in case the specfile is omitted when
- # constructing a Counters() object
- _spec = [
- {
- "item_name": "zones",
- "item_type": "named_set",
- "item_optional": False,
- "item_default": {
- "_SERVER_" : {
- "notifyoutv4" : 0,
- "notifyoutv6" : 0
- }
- },
- "item_title": "Zone names",
- "item_description": "Zone names",
- "named_set_item_spec": {
- "item_name": "classname",
- "item_type": "named_set",
- "item_optional": False,
- "item_default": {},
- "item_title": "RR class name",
- "item_description": "RR class name",
- "named_set_item_spec": {
- "item_name": "zonename",
- "item_type": "map",
- "item_optional": False,
- "item_default": {},
- "item_title": "Zone name",
- "item_description": "Zone name",
- "map_item_spec": [
- {
- "item_name": "notifyoutv4",
- "item_type": "integer",
- "item_optional": False,
- "item_default": 0,
- "item_title": "IPv4 notifies",
- "item_description": "Number of IPv4 notifies per zone name sent out"
- },
- {
- "item_name": "notifyoutv6",
- "item_type": "integer",
- "item_optional": False,
- "item_default": 0,
- "item_title": "IPv6 notifies",
- "item_description": "Number of IPv6 notifies per zone name sent out"
- }
- ]
- }
- }
- }
- ]
-
class Counters(counters.Counters):
"""A list of counters which can be handled in the class are like
the following. Also see documentation for
_entire_server = '_SERVER_'
# zone names are contained under this dirname in the spec file.
_perzone_prefix = 'zones'
- # default statistics data set
- _statistics = _Statistics()
def __init__(self, spec_file_name=None):
"""If the item `zones` is defined in the spec file, it obtains a
isc.statistics.counters.Counters.__init__()"""
counters.Counters.__init__(self, spec_file_name)
if self._perzone_prefix in \
- isc.config.spec_name_list(self._statistics._spec):
+ isc.config.spec_name_list(self._statistics_spec):
self._zones_item_list = isc.config.spec_name_list(
isc.config.find_spec_part(
- self._statistics._spec,
+ self._statistics_spec,
'%s/%s/%s' % (self._perzone_prefix,
'_CLASS_', self._entire_server)))
counter. If nothing is counted yet, then it returns an empty
dictionary."""
# entire copy
- statistics_data = self._statistics._data.copy()
+ statistics_data = self._statistics_data.copy()
# If there is no 'zones' found in statistics_data,
# i.e. statistics_data contains no per-zone counter, it just
# returns statistics_data because calculating total counts
return statistics_data
zones = statistics_data[self._perzone_prefix]
# Start calculation for '_SERVER_' counts
- zones_spec = isc.config.find_spec_part(self._statistics._spec,
+ zones_spec = isc.config.find_spec_part(self._statistics_spec,
self._perzone_prefix)
zones_data = {}
for cls in zones.keys():
start_functor(concurrency, number, self.counters.inc,
counter_name)
counters._stop_timer(start_time,
- self.counters._statistics._data,
- self.counters._statistics._spec,
+ self.counters._statistics_data,
+ self.counters._statistics_spec,
timer_name)
self.assertEqual(
- counters._get_counter(self.counters._statistics._data,
+ counters._get_counter(self.counters._statistics_data,
counter_name),
concurrency * number)
self.assertGreaterEqual(
- counters._get_counter(self.counters._statistics._data,
+ counters._get_counter(self.counters._statistics_data,
timer_name), 0.0)
def test_concat(self):
else:
self.assertTrue(isc.config.ModuleSpec(
{'module_name': 'Foo',
- 'statistics': self.counters._statistics._spec}
+ 'statistics': self.counters._statistics_spec}
).validate_statistics(
False, self._statistics_data))
# for counters of xfer running
_suffix = 'xfr_running'
_xfrrunning_names = \
- isc.config.spec_name_list(self.counters._statistics._spec,
+ isc.config.spec_name_list(self.counters._statistics_spec,
"", True)
for name in _xfrrunning_names:
if name.find(_suffix) != 1: continue
# for ipsocket/unixsocket counters
_prefix = 'socket/'
_socket_names = \
- isc.config.spec_name_list(self.counters._statistics._spec,
+ isc.config.spec_name_list(self.counters._statistics_spec,
"", True)
for name in _socket_names:
if name.find(_prefix) != 0: continue