Skip to main content

counter-stats

A python module for keeping stats.

This repo has been split-off from the 'aacommons' repo at: https://github.com/tbastian66/aacommons

Installation

pip install counter-stats

Usage

CounterEvent

import json
from time import sleep, time

from stats import CounterEvent

stats = CounterEvent(name="ThingsCounter")

# the following loops automatically creates 3 counts split up into 2 different
# groups.
for i in range(0, 10):
    stats.increment('counter1', 'group1', increment=1)
    stats.increment('counter1', 'group1', increment=1)
    stats.increment('counter2', 'group1', increment=1)
    stats.increment('counter2', 'group1', increment=1)
    stats.increment('counter3', 'group2', increment=1)
    sleep(1)

# Get a snapshot of the counters and the group aggregates

# stop_ts needs to be specified as you might have multiple CounterEvent() objects
# that you want to use the same stop timestamp
stop_ts = time()
# Gets a dictionary (munch)
stats_snapshot = stats.snapshot(update_stats=True, stop_ts=stop_ts)
# pretty print the dict
print(json.dumps(stats_snapshot, indent=4))
{
    "name": "ThingsCounter",
    "original_start_ts": 1654496276.5894873,
    "start_ts": 1654496276.5894873,
    "stop_ts": 1654496286.59915,
    "uptime": 10.01,
    "time_active": 10.01,
    "original_start_time_str": "2022-06-06 14:17:56.589487+0800 (HKT)",
    "start_time_str": "2022-06-06 14:17:56.589487+0800 (HKT)",
    "stop_time_str": "2022-06-06 14:18:06.599150+0800 (HKT)",
    "topic_counts": {
        "group1": {
            "counter1": 20,
            "counter2": 20
        },
        "group2": {
            "counter3": 10
        }
    },
    "group_counts": {
        "group1": 40,
        "group2": 10
    },
    "topic_latest_ts": {
        "group1": {
            "counter1": 1654496285.5980132,
            "counter2": 1654496285.5980191
        },
        "group2": {
            "counter3": 1654496285.5980208
        }
    },
    "group_latest_ts": {
        "group1": 1654496285.5980191,
        "group2": 1654496285.5980208
    },
    "rates": {
        "number_of_topics": {
            "group1": 2,
            "group2": 1
        },
        "interval": 10.01,
        "number_of_groups": 2,
        "topic_rates": {
            "group1": {
                "counter1": 1.998,
                "counter2": 1.998
            },
            "group2": {
                "counter3": 0.999
            }
        },
        "group_rates": {
            "group1": 3.996,
            "group2": 0.999
        },
        "topic_percentage": {
            "group1": {
                "counter1": 0.5,
                "counter2": 0.5
            },
            "group2": {
                "counter3": 1.0
            }
        }
    }
}

CounterTime

CounterTrio

Release files for counter-stats 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for counter-stats 0.0.2
File Size Uploaded
counter-stats-0.0.2.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for counter-stats 0.0.2
File Interpreter ABI Platform
counter_stats-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / counter-stats-0.0.2.tar.gz

Download URL counter-stats-0.0.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ee85073827dbf6a357d1686e24bc55de1303be97c43a21ed5aeed5d443f2be16
BLAKE2b-256 checksum
How to use checksums
d9e36e7a9819afac7450192216da38e5c489ee7123567228e54e297b7bbc01d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release files / counter_stats-0.0.2-py3-none-any.whl

Download URL counter_stats-0.0.2-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d7cd665261509041344e4df395b5c7405451e9147ca053c4e1a9593347bdb0a
BLAKE2b-256 checksum
How to use checksums
1b475a0ea66936981d5121f8a5ccde3c684f017c7145ea363e080a5a09ca97c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page