Skip to main content

Python module for various Counter classes

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

counter-stats-0.0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distributions

counter_stats-0.0.1-py3.9.egg (12.6 kB view details)

Uploaded Source

counter_stats-0.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file counter-stats-0.0.1.tar.gz.

File metadata

  • Download URL: counter-stats-0.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for counter-stats-0.0.1.tar.gz
Algorithm Hash digest
SHA256 65b791cdd6ced2d1c92879ea7be28179792b8e9c30d97258fa7a04f1be6314b5
MD5 ceca1b6e1db4589adc5ef77698d0ae57
BLAKE2b-256 b04ef9faddfa658b84016454f768833de3d495095efb4674b644eda08e9b1b7d

See more details on using hashes here.

File details

Details for the file counter_stats-0.0.1-py3.9.egg.

File metadata

  • Download URL: counter_stats-0.0.1-py3.9.egg
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for counter_stats-0.0.1-py3.9.egg
Algorithm Hash digest
SHA256 c348f16e6d78b2a0100523bda30b848e4a2e13cc3d10dbed771bd6d6be3ff9a9
MD5 4ae8a53a5658fef9907e2a4bd542a970
BLAKE2b-256 9ee33910031f73620955aced211fb48f3161a90abf33a22dcb4c218e563af3d4

See more details on using hashes here.

File details

Details for the file counter_stats-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for counter_stats-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a25e17bb7ae9ffc82c77bd5423f6c58d84a4563e5b99a3d6b828615c5b426ed
MD5 28cd83109f9e4ca566b11a2aa9b3fc0e
BLAKE2b-256 cef5c69ef5a8de532f059c4bc4d40ed4564a5be433ce12ad56b15cc38615abe0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page