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.20261122

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.20261122
File Size Uploaded Provenance Actions
metrics_utility-0.8.20261122.tar.gz 1.2 MB With provenance Details for metrics_utility-0.8.20261122.tar.gz

Built distribution (wheel)

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

Total release size: 1.9 MB

Release files / metrics_utility-0.8.20261122.tar.gz

Download URL metrics_utility-0.8.20261122.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
ca7eef5b991adfbd8549f0257528426ceb15a68a9408eaf4273a263d5edd0776
BLAKE2b-256 checksum
How to use checksums
c77bcafc7a08673e66dd59aaee838e15430e279814fe2691a054fd98a8e572e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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

Download URL metrics_utility-0.8.20261122-py3-none-any.whl
Size 640.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3c0be43371dd535960f550ae3ab0e7ee1f361ce526c90f6dc19dfc5294b4497
BLAKE2b-256 checksum
How to use checksums
fccd9d90d962350c307e85ebe25894909e1462237765de19d64247d1b2c481a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for metrics-utility 0.8.20261122

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for metrics_utility-0.8.20261122.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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