Skip to main content

metrics-utility

metrics-utility deals with collecting, analyzing and reporting metrics from Ansible Automation Platform (AAP) Controller instances.

It provides two interfaces - a CLI and a python library.

Also see below for dev setup, and other docs.

CLI

A metrics-utility CLI tool for collecting and reporting metrics from Controller, allowing users to:

  • Collect Controller usage data from the database, settings, and prometheus
  • Analyze the data and generate .xlsx or .ods reports
  • Support multiple storage adapters for data persistence (local directory, S3)
  • Push metrics data to console.redhat.com

It can run either standalone (against a specified postgres instance), or inside the Controller's python virtual environment. The controller mode allows the config collector to collect more settings and takes DB connection details from there.

The billing workflow provides two primary commands:

  • gather_automation_controller_billing_data
    • collects data from controller, saves daily tarballs with .csv / .json inside
    • saves tarballs in specified storage
    • optionally sends to console
  • build_report
    • builds an .xlsx report by default, or an .ods report with --format=ods
      • 3 report types - CCSP, CCSPv2, RENEWAL_GUIDANCE
      • the ccsp* reports use the collected tarballs as the source
      • the renewal* report reads from controller db

The candlepin_manage command is an auxiliary management command for Candlepin consumer registration and certificate renewal; see python manage.py candlepin_manage --help.

Example invocation:

pip install metrics-utility

# common
export METRICS_UTILITY_SHIP_PATH="./out"
export METRICS_UTILITY_SHIP_TARGET="directory"

# gather data
metrics-utility gather_automation_controller_billing_data --ship --until=10m
ls out/data/`date +%Y/%m/%d`/ # data/<year>/<month>/<day>/<uuid>-<since>-<until>-<index>-<collection>.tar.gz

# build report
export METRICS_UTILITY_REPORT_TYPE="CCSPv2"

metrics-utility build_report --month=`date +%Y-%m` # year-month
metrics-utility build_report --month=`date +%Y-%m` --format=ods
ls out/reports/`date +%Y/%m`/ # reports/<year>/<month>/<type>-<year>-<month>.xlsx and .ods

See docs/cli.md and docs/old-readme.md for details on the usage,
See docs/environment.md for a full list of environment variables,
See docs/awx.md for more on running against an awx dev env. See docs/architecture.md for the system architecture and maintainer extension points.

Python library

The metrics_utility.library library provides a lower-level python API exposing the collection functionality using these abstractions:

  • collectors - functions that collect specific data, from database to a .csv, or from elsewhere into a python dict
  • storage - the segment.com storage backend (StorageSegment), used to push anonymized data
  • db locking helper (lock)

It is complemented by the sibling metrics_utility.anonymized_rollups package, which rolls up and anonymizes collected data before shipping.

Both are shared with the external metrics-service, which is their main consumer. The library uses no env variables, and doesn't rely on Controller environment, taking everything via params. The CLI uses the library where possible, but is not limited to it, and keeps its own packaging/storage/report implementations under automation_controller_billing/.

Example use:

from metrics_utility.library.collectors.controller import config, main_jobevent
from metrics_utility.library import lock

db = ...  # django.db.connection / psycopg 3

with lock('my-unique-key', wait=False, db=db) as acquired:
    if not acquired:
        raise 'too bad'  # or use wait=True instead

    # dict, will be converted to json
    config_dict = config(db=db).gather()

    # list of .csv filenames; since is included, until is excluded
    # both datetime with timezone, or None
    job_csvs = main_jobevent(db=db, since=since, until=until).gather()

See library README for details.

Developer setup

Prerequisites

  • Python 3.12 or later
  • uv
  • Docker compose
  • make, git

Dependencies are managed via pyproject.toml (& uv.lock). There is also setup.cfg with dependencies but those are only used for the controller mode.

The Docker compose environment is used to provide a quick postgres & SeaweedFS (S3-compatible store) instances on ports 5432 and 8333, but they can be replaced with local setup. See docker-compose.yaml for details, and tools/docker/*.sql for users & data to import in postgres (start with roles.sql and latest.sql). (Or don't, and use docker.)

uv is also not required as long as you can manage your own python venv and install dependencies from pyproject.toml.

Optionally, uvx pre-commit install to run ruff checks from a pre-commit hook, defined in .pre-commit-config.yaml. Or you can run make lint / make fix manually.

Installation

# Clone the repository
git clone https://github.com/ansible/metrics-utility.git
cd metrics-utility

# Install dependencies using uv
uv sync

Run

cd metrics-utility
make compose
cd metrics-utility
uv run ./manage.py --help
uv run ./manage.py gather_automation_controller_billing_data --help
uv run ./manage.py build_report --help

make compose-pytest runs the test suite inside docker compose (also used in CI), make compose-env starts an interactive container with deps installed for manual testing.

make clean resets the docker environment, make lint & make fix run the linters & formatters, make psql runs psql in the postgres container.

See docs/tests-compose.md for more on running tests inside docker compose.

metrics-service

make compose-service runs the full metrics-service stack locally (web, dispatcher, scheduler), make compose-pytest-svc runs the metrics-service test suite with the local metrics-utility checkout.

Both require a ../metrics-service checkout.

Tests

Some tests depend on a running postgres & SeaweedFS instance - run make compose to get one.

make test runs the full test suite, make coverage produces a coverage report.

Use uv run pytest -s -v for running tests with verbose output, also accepts test filenames.

Documentation

More documentation is available in docs/, and elsewhere:

Please follow our Contributor's Guide for details on submitting changes and documentation standards.

Metadata

Release files for metrics-utility 0.8.20261101

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

Source distribution (sdist)

Source distribution for metrics-utility 0.8.20261101
File Size Uploaded Provenance Actions
metrics_utility-0.8.20261101.tar.gz 1.3 MB Without provenance Details for metrics_utility-0.8.20261101.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for metrics-utility 0.8.20261101
File Interpreter ABI Platform Actions
metrics_utility-0.8.20261101-py3-none-any.whl Python 3 none any Details for metrics_utility-0.8.20261101-py3-none-any.whl

Total release size: 1.9 MB

Release files / metrics_utility-0.8.20261101.tar.gz

Download URL metrics_utility-0.8.20261101.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
1feb57f289e53feaa4037e6f355e51f710f377db03c33fbc4c484ab9f9112b05
BLAKE2b-256 checksum
How to use checksums
08dc5ecfece68291ad1f7905d65deed3b673724fb19245f61b57ae997c503679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / metrics_utility-0.8.20261101-py3-none-any.whl

Download URL metrics_utility-0.8.20261101-py3-none-any.whl
Size 637.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d83ab4b02e291b16dfe15a252ce0487f02d65d55c958bf91b86f7fa5767ebca8
BLAKE2b-256 checksum
How to use checksums
64553164e6d3df03f837a2a53229243de5c65077e4c90e535e94f2a017567929
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for metrics-utility 0.8.20261101

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
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