StatsFS

Example of usage:

from pprint import pprint

import activelogic
from activelogic.legacy.statsfs import StatsFS


def example_statsfs_query():
    al = activelogic.sync_connect('192.168.1.25', 'admin', 'password')
    st = al.begin(StatsFS)

    values = st.transfer_get("2021-12-12", "2021-12-13", "/stat_obj?Statistics Object/", 0, 0)
    pprint(values)

    al.close()


if __name__ == '__main__':
    example_statsfs_query()
class activelogic.legacy.statsfs.StatsFS

The Statistics resource is used for for reading statistics.

Statistics needs to be enabled on the system in order for the resource to function.

async StatsFS.date_list()

List the dates for which statistics are available.

Returns:

A sorted list with dates that have statistics data.

>>> x.date_list()
['2005-12-01', '2005-12-02', '2005-12-03', ...]
async StatsFS.fields_list()

List available statistics fields.

Returns:

Statistics fields as a dict.

>>> x.fields_list()
{'graphs': [{'desc': 'Incoming bps', 'id': 1, 'type': 1},
        {'desc': 'Outgoing bps', 'id': 2, 'type': 1},
        {'desc': 'CPS', 'id': 4, 'type': 2},
        {'desc': 'Unestablished CPS', 'id': 8, 'type': 2},
        {'desc': 'Incoming CPS', 'id': 16, 'type': 2},
        {'desc': 'Outgoing CPS', 'id': 32, 'type': 2},
        {'desc': 'Unestablished Incoming CPS', 'id': 64, 'type': 2},
        {'desc': 'Unestablished Outgoing CPS', 'id': 128, 'type': 2},
        {'desc': 'Incoming concurrrent connections', 'id': 256, 'type': 2},
        {'desc': 'Outgoing concurrent connections', 'id': 512, 'type': 2},
        {'desc': 'Incoming Quality of Experience', 'id': 1024, 'type': 3},
        {'desc': 'Outgoing Quality of Experience', 'id': 2048, 'type': 3}],
 'totals': [{'desc': 'Incoming Bytes', 'id': 1, 'type': 1},
        {'desc': 'Outgoing Bytes', 'id': 2, 'type': 1},
        {'desc': 'Connections', 'id': 4, 'type': 2},
        {'desc': 'Unestablished Connections', 'id': 8, 'type': 2},
        {'desc': 'Incoming Connections', 'id': 16, 'type': 2},
        {'desc': 'Outgoing Connections', 'id': 32, 'type': 2},
        {'desc': 'Incoming Unestablished Connections', 'id': 64, 'type': 2},
        {'desc': 'Outgoing Unestablished Connections', 'id': 128, 'type': 2},
        {'desc': 'Incoming Quality of Experience', 'id': 256, 'type': 3},
        {'desc': 'Outgoing Quality of Experience', 'id': 512, 'type': 3}]}

This method returns the statistics fields as a dict with ‘graphs’ and ‘totals’ sub-dicts. The sub-dicts contain the keys ‘desc’, ‘id’ and ‘type’. The type corresponds to the pathtype used in list/graph calls.

async StatsFS.path_is_expandable(start, end, path, pathtype=0)

Verify that a path is expandable.

Returns:

True if path is expandable.

Parameters:
  • start – Start date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • end – End date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • path – The statistics path to list e.g. /NetObjects

  • pathtype – Value path type.

>>> x.path_is_expandable("2021-11-17", "2021-11-18", "/stat_obj1/", 0)
async StatsFS.list(*args, **kwargs)

List stats nodes between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • end – End date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • path – The statistics path to list e.g. /

  • pathtype – Value path type. For use in firmwares v12.0 and newer.

  • replymask – If replymask is non-zero only data for the fields in the mask will be retured.

Returns:

A dictionary for each stats node inside a list.

Raises:

PLDBUnsupportedInFirmware – If pathtype argument is used without firmware support.

>>> s.list(start="2021-12-01", end="2021-12-02", path="/", pathtype=0, replymask=0)
[{'name': 'HostperNO',
    'values': {'bytes out': 4900070621184.0,
        'connections': 351976704.0,
        'outbound Quality of Experience': 99.520118713378906,
        'inbound Quality of Experience': 99.921859741210938,
        'bytes in': 21536893304832.0},
    'flags': 3,'type': 0},
{'name': 'Top Sites',
        'values': {'bytes out': 4900070621184.0,
            'connections':351976704.0,
            'bytes in':21536893304832.0},
        'flags': 3, 'type': 0},
{'name': 'StatsByClass',
        'values':{'bytes out': 4888053415936.0,
            'bytes in': 21408400801792.0},
        'flags': 3, 'type': 0}]
async StatsFS.transfer_get(start, end, path, pathtype=0, replymask=0)

Retrieve total transfer for path between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • end – End date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • path – The statistics path to list e.g. /stat_obj?Statistics Object/

  • pathtype – Value path type.

  • replymask – If replymask is non-zero only data for the fields in the mask will be retured.

Returns:

Dictionary containing transfer information.

Raises:

RuntimeError – If statistic path could not be read.

>>> s.transfer_get("2021-12-12", "2021-12-13", "/stat_obj?Statistics Object/", 0, 0)
{'flags': 3083,
 'name': 'stat_obj',
 'type': 0,
 'values': {
    'avg latency in': 0,
    'avg latency out': 0,
    'bytes in': 3808418804388,
    'bytes out': 2933780655422,
    'bytes total': 6742199459810,
    'connections': 3232485608,
    'in Quality external': 0,
    'in Quality internal': 0,
    'in Quality packets': 297562648,
    'inbound connections': 952155391,
    'out Quality external': 0,
    'out Quality internal': 0,
    'out Quality packets': 372900897,
    'outbound connections': 2280330217,
    'packet drops in': 0,
    'packet drops out': 0,
    'packet retransmissions in': 27831436,
    'packet retransmissions out': 27831492,
    'shaping drops in': 0,
    'shaping drops out': 0}
 }
async StatsFS.graph(start, end, path, numvals=24, pathtype=0, mode=1, replymask=0, usage_rate=False)

Retrieve graph data between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • end – End date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • path – The statistics path to list e.g. /NetObjects

  • numvals – The number of data points to retrieve.

  • pathtype – Value path type.

  • mode – throughput rate (GRAPH_MODE_SPEED) or actual byte/connection count (GRAPH_MODE_SIZE).

  • replymask – If replymask is non-zero only data for the fields in the mask will be retured.

  • usage_rate – If usage_rate is set then graph rates are calculated based on micro usage bitmask.

Returns:

Dictionaries with data.

For the numval parameter the specified time interval is divided into this number of segments and the average for each segment is reported. This value can be set to 0 to retrieve all data points that have been stored.

>>> s.graph("2021-01-05", "2021-01-05", "/Host per services", 24, 0, s.GRAPH_MODE_SIZE)
    [{'bytes out': 528960416.0, 'connections': 7485.5, 'bytes in': 95168704.0},
     {'bytes out': 503229952.0, 'connections': 7073.0, 'bytes in': 136215120.0},
     {'bytes out': 561612864.0, 'connections': 7457.75, 'bytes in': 165719856.0},
     {'bytes out': 574073536.0, 'connections': 7316.66650390625, 'bytes in': 125461376.0},
     {'bytes out': 575875264.0, 'connections': 7071.0, 'bytes in': 142020688.0},
     {'bytes out': 533374208.0, 'connections': 7379.75, 'bytes in': 128362920.0},
     {'bytes out': 542574656.0, 'connections': 7120.75, 'bytes in': 145863184.0},
     {'bytes out': 627854016.0, 'connections': 7328.91650390625, 'bytes in': 124391448.0},
     {'bytes out': 356714592.0, 'connections': 8949.1669921875, 'bytes in': 111401304.0},
     {'bytes out': 276146240.0, 'connections': 9937.1669921875, 'bytes in': 121161912.0},
     {'bytes out': 271035360.0, 'connections': 10208.8330078125, 'bytes in': 105619560.0},
     {'bytes out': 282889088.0, 'connections': 9836.9169921875, 'bytes in': 105585656.0},
     {'bytes out': 257417728.0, 'connections': 9915.75, 'bytes in': 118984736.0},
     {'bytes out': 291532384.0, 'connections': 10910.6669921875, 'bytes in': 198847856.0},
     {'bytes out': 281107264.0, 'connections': 10963.0830078125, 'bytes in': 96303560.0},
     {'bytes out': 261479232.0, 'connections': 10322.6669921875, 'bytes in': 106611800.0},
     {'bytes out': 365030240.0, 'connections': 10602.9169921875, 'bytes in': 233681280.0},
     {'bytes out': 514466784.0, 'connections': 10718.75, 'bytes in': 129939368.0},
     {'bytes out': 394594048.0, 'connections': 10602.5, 'bytes in': 128155672.0},
     {'bytes out': 1116160000.0, 'connections': 11515.25, 'bytes in': 149660416.0},
     {'bytes out': 423695584.0, 'connections': 10865.25, 'bytes in': 121420984.0},
     {'bytes out': 592000384.0, 'connections': 10532.0, 'bytes in': 228060944.0},
     {'bytes out': 623388928.0, 'connections': 9260.9169921875, 'bytes in': 198206720.0},
     {'bytes out': 323936608.0, 'connections': 8981.25, 'bytes in': 117023752.0}]
async StatsFS.subscriber_count(start, end, path, pathtype=0)

Count number of subscribers for requested path between the two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /

  • pathtype – Value path type.

Returns:

Integer count of subscribers.

async StatsFS.subscriber_count_list(start, end, path, pathtype=0)

List subscriber count for each node for requested path between the two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /

  • pathtype – Value path type.

Returns:

A dictionary for each stats node inside a list.

async StatsFS.subscriber_count_graph(start, end, path, pathtype=0, numvals=24)

Retrieve subscriber count for each requested interval between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /NetObjects

  • pathtype – Value path type.

  • numvals – The number of data points to retrieve. The specified time interval is divided into this number of segments and the average for each segment is reported. In firmware versions 13.1 and newer this value can be set to 0 to retrieve all data points that have been stored.

Returns:

A dictionary for each stats node inside a list.

async StatsFS.data_invalidate(start, end, path, pathtype=0, deleteroot=True)

Invalidate all Statistics data for requested path and all its children.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /NetObjects

  • pathtype – Value path type.

  • deleteroot – Invalidate data for requested path itself.

async StatsFS.graph_invalidate(start, end, path, pathtype=0, deleteroot=True)

Invalidate only graph data for requested path and all its children.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /NetObjects

  • pathtype – Value path type.

  • deleteroot – Invalidate graph data for requested path itself.

async StatsFS.subitem_count(start, end, path, pathtype=0)

Count number of subitems for requested path between the two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /

  • pathtype – Value path type.

Returns:

Dictionary of various subtypes with their count.

Raises:

RuntimeError – If this method is unable to retrieve data for the specified path.

async StatsFS.subitem_count_list(start, end, path, pathtype=0)

Subitem count for the list of stats nodes between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /

  • pathtype – Value path type.

Returns:

A dictionary for each stats node inside a list.

async StatsFS.list_subscribers(start, end, path, pathtype=0, max_nodes=0, replymask=0)

List top N subscribers between two dates (N=0, returns all subscribers).

Parameters:
  • start – Start date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • end – End date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • path – The statistics path to list e.g. /NetObjects

  • pathtype – Value path type. For use in firmwares v12.0 and newer.

  • max_nodes – Maximum number of nodes to output. If this is zero, all nodes will be returned.

  • replymask – If replymask is non-zero only data for the fields in the mask will be returned.

Returns:

If max_nodes=0, returns the list of items each stored as a Dict.

This function exists to limit the amount of data sent between the server and the client. It returns any node which is in the top N list for each of the fields being stored.

>>> res=s.list_subscribers("2021-09-14", "2021-09-14", "/Applications?Statistics Object")
>>> for node in res:
...     print node
...
{'values': {'bytes out': 30924881920.0, 'bytes in': 6812166656.0}, 'name': 'Sub113'}
{'values': {'bytes out': 10508003328.0, 'bytes in': 2729902848.0},  'name': 'Sub5'}
{'values': {'bytes out': 2935312384.0, 'bytes in': 2098169216.0},  'name': 'Sub49'}
{'values': {'bytes out': 577248896.0, 'bytes in': 1004788544.0},  'name': 'Sub362'}
{'values': {'bytes out': 7716958720.0, 'bytes in': 923890496.0},  'name': 'Sub74'}

If max_nodes is non-zero, Dict with the top list for each field stored or requested will be returned. Each list of is a list of dictionaries for each node.

List top N values matching a “search string” between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • end – End date in the format YYYY-MM-DD or YYYY-MM-DD HH:MM:SS

  • path – The statistics path to list e.g. /NetObjects

  • searchstr – The search string to match on.

  • pathtype – Value path type. For use in firmwares v12.0 and newer.

  • max_nodes – Maximum number of nodes to output. If this is zero, all nodes will be returned.

  • recursiondepth – Max depth of Statistics tree to search.

  • replymask – If replymask is non-zero only data for the fields in the mask will be returned. (requires firmwares v14.0 or newer).

Returns:

Returns the list of items each stored as a dict if max_nodes=0.

N = 0, will return all the matching values.

>>> res=s.list_search ("2013-10-02", "2013-10-02", "/Applications", "Sub115",)
>>> for node in res:
...     print node
...
{'values': {'bytes out': 30924881920.0, 'bytes in': 6812166656.0}, 'type': 518, 'name': '/Web Browsing?ServiceObject/HTTP?NetObject'}

If max_nodes is non-zero, Dict with the top list for each field stored or requested. Each list of is a list of dictionaries for each node.

async StatsFS.names_list(start, end, path, pathtype=0, matchstr='')

List the names of stats nodes between two dates.

Parameters:
  • start – Start date in the format YYYY-MM-DD

  • end – End date in the format YYYY-MM-DD

  • path – The statistics path to list e.g. /

  • pathtype – Value path type.

  • path – Match string

Returns:

A dictionary for each stats node inside a list.

async StatsFS.query_callback(query, row_desc_cb, row_data_cb, notice_cb=None)

Issue the query using callbacks.

async StatsFS.query(query)

Fetch statistics data using SQL queries.

Parameters:

query – Query in the form of an SQL string

Returns:

A dictionary with information about columns, rows and notice messages.

>>> query = """SELECT name, bytes_in, bytes_out
... FROM pls_list(date_from='2015-12-31', date_to='2015-12-31',
... value_path='/PSM?0/By Subscriber?NetObject',
... table_name='traffic');
... """
>>> data = s.query(query)

Returned strings are of type ‘bytes’.