xtd.core.stat.handler module¶
-
class
xtd.core.stat.handler.
BaseHandler
(p_name, p_interval=50, p_fetcher=None)[source]¶ Bases:
xtd.core.tools.thread.SafeThread
Abstract statistic handler
Spawns a dedicated thread that outputs a set counters every
p_interval
seconds.User can provide a custom function to get the counters to output. By default the object gets all counters registered in the
StatManager
singleton.User should inherit this class and define
write()
method.Note
The functor must take no parameter and return something suitable for
write()
Parameters: -
write
(p_counters)[source]¶ Ouput available counter data (abstract)
Parameters: p_counters (dict) – dictionary holding all available counters assiciated with their namespace. { "<namespace>" : [ <counter1>, <counter2>, ... ] }
-
work
()[source]¶ Output available counter data
Implementation of
xtd.core.tools.thread.SafeThread.work()
-
__module__
= 'xtd.core.stat.handler'¶
-
-
class
xtd.core.stat.handler.
DiskHandler
(p_directory, p_interval=50, p_fetcher=None)[source]¶ Bases:
xtd.core.stat.handler.BaseHandler
Output counters to filesystem
Given :
- a counter named
counter.name
of value55
- registered in
xtd.core.stat.manager.StatManager
with namespacea.b.c
- a DiskHandler constructed with
/var/snmp
This will create a file
/var/snmp/a/b/c/counter.name
containing the string55
Parameters: Raises: XtdError
–p_directory
isn’t writable or could ne be created-
write
(p_counters)[source]¶ Write all available counters to filesystem
When object fails to write a counte file, an error log is triggered. Raising an exception woudn’t be helpfull since this part of the code runs in a dedicated thread.
Parameters: p_counters (dict) – see BaseHandler.write()
-
__module__
= 'xtd.core.stat.handler'¶
- a counter named
-
class
xtd.core.stat.handler.
HttpHandler
(p_url, p_interval=50, p_fetcher=None)[source]¶ Bases:
xtd.core.stat.handler.BaseHandler
Send counter values to a http server
Counter values are gathered in a single json and sent to the target url as a POST request.
HTTP Request details :
Method :
POST
Content-Type :
application/json
Body :
{ "<namespace>" : { "<name-of-counter-1>" : value-of-counter-1, "<name-of-counter-2>" : value-of-counter-2, ... }, ... "<namespace>" : { <name-of-counter-N>" : value-of-counter-N ... } }
Note
Keep in mind that counter values can be undefined.
In such case, the json value is a string equals to
"NaN"
.Parameters: - p_url – target url for post request
- p_interval (int) – interval, in second, between two outputs
- p_fetcher (function) – functor that retrieves data counters
-
write
(p_counters)[source]¶ Write all available counters to filesystem
When object fails to send HTTP request, an error log is triggered. Raising an exception woudn’t be helpfull since this part of the code runs in a dedicated thread.
Parameters: p_counters (dict) – see BaseHandler.write()
-
__module__
= 'xtd.core.stat.handler'¶
-
class
xtd.core.stat.handler.
LoggingHandler
(p_name, p_interval=50, p_fetcher=None)[source]¶ Bases:
xtd.core.stat.handler.BaseHandler
Output counter to application logs
Parameters: -
__module__
= 'xtd.core.stat.handler'¶
-
write
(p_counters)[source]¶ Output all available counters to logging facility :param p_counters: see
BaseHandler.write()
-