Module quasardb.stats

Functions

def by_node(conn)
Expand source code
def by_node(conn):
    """
    Returns statistic grouped by node URI.

    Parameters:
    conn: quasardb.Cluster
      Active connection to the QuasarDB cluster
    """
    return {x: of_node(conn.node(x)) for x in conn.endpoints()}

Returns statistic grouped by node URI.

Parameters: conn: quasardb.Cluster Active connection to the QuasarDB cluster

def calculate_delta(prev, cur)
Expand source code
def calculate_delta(prev, cur):
    """
    Calculates the 'delta' between two successive statistic measurements.
    """
    ret = {}
    for node_id in cur.keys():
        ret[node_id] = _calculate_delta_stats(
            prev[node_id]["cumulative"], cur[node_id]["cumulative"]
        )

    return ret

Calculates the 'delta' between two successive statistic measurements.

def is_cumulative_stat(s)
Expand source code
def is_cumulative_stat(s):
    # NOTE(leon): It's quite difficult to express in Python that you don't want any
    # regex to _end_ with uid_[0-9]+, because Python's regex engine doesn't support
    # variable width look-behind.
    #
    # An alternative would be to use the PyPi regex library (for POSIX regexes), but
    # want to stay light on dependencies#
    #
    # As such, we define a 'cumulative' stat as anything that's not a user stat.
    # Simple but effective.
    return user_pattern.match(s) is None
def is_user_stat(s)
Expand source code
def is_user_stat(s):
    return user_pattern.match(s) is not None
def of_node(dconn)
Expand source code
def of_node(dconn):
    """
    Returns statistic for a single node.

    Parameters:
    dconn: quasardb.Node
      Direct node connection to the node we wish to connect to

    """

    start = datetime.now()
    raw = {k: _get_stat(dconn, k) for k in dconn.prefix_get(stats_prefix, 1000)}

    ret = {"by_uid": _by_uid(raw), "cumulative": _cumulative(raw)}

    check_duration = datetime.now() - start

    ret["cumulative"]["check.online"] = 1
    ret["cumulative"]["check.duration_ms"] = int(check_duration.total_seconds() * 1000)

    return ret

Returns statistic for a single node.

Parameters: dconn: quasardb.Node Direct node connection to the node we wish to connect to

def stat_type(stat_id)
Expand source code
def stat_type(stat_id):
    """
    Returns the statistic type by a stat id. Returns one of:

     - 'gauge'
     - 'counter'
     - None in case of unrecognized statistics

    This is useful for determining which value should be reported in a dashboard.
    """
    return _stat_type(stat_id)

Returns the statistic type by a stat id. Returns one of:

  • 'gauge'
  • 'counter'
  • None in case of unrecognized statistics

This is useful for determining which value should be reported in a dashboard.