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.SafeThreadAbstract statistic handler
Spawns a dedicated thread that outputs a set counters every
p_intervalseconds.User can provide a custom function to get the counters to output. By default the object gets all counters registered in the
StatManagersingleton.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.BaseHandlerOutput counters to filesystem
Given :
- a counter named
counter.nameof value55 - registered in
xtd.core.stat.manager.StatManagerwith namespacea.b.c - a DiskHandler constructed with
/var/snmp
This will create a file
/var/snmp/a/b/c/counter.namecontaining the string55Parameters: Raises: XtdError–p_directoryisn’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.BaseHandlerSend 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 :
POSTContent-Type :
application/jsonBody :
{ "<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.BaseHandlerOutput 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()
-