Skip to main content

A lightweight framework for defining arbitrary business metrics as Python code.

Project description

Check All Build & Publish

✨Abstract✨ metrics

A lightweight framework for defining arbitrary business metrics as Python code.

Installation

pip install abstract-metrics

Basic Usage

  1. Install
  2. Subclass one of the metric types (e.g. ApplicationMetricBoolean)
  3. Add an optimistic compute method that returns your metric.
  4. Register a runner with your metric and run it!

Example

Let's say you want to write a metric that checks if one of your applications follows your organizations application naming standards. We will use the ApplicationMetricBoolean type to do this. All metrics are formated as {subject}Metric{type}. In this case, our subject is an Application and our type is Boolean.

Because Applications are our subject, we need to subclass ApplicationMetricBoolean. This class has a few methods that we can use to help us compute our metric. The most important one is compute. This method is called by the runner and should return a the boolean value. Additionally, we should use the application property (via the Application wrapper) to store any context we need to compute this metric.

from metric import Application, ApplicationMetric
from metric.utils import MatrixRunner
from metric.types import OutputFormat

def main():
    # Construct list of basic Application objects
    apps = [Application(app) for app in ["myorg-sales-app", "sandbox-dinasour"]]
    # Construct a list of our metrics
    metrics = [AppNameCompliance]

    # This will not only construct our Application Metrics but it will also execute
    # them and print them to stdout as a table.
    MatrixRunner(format=OutputFormat.OUTPUT_FORMAT_TABLE).run(apps, metrics)

class AppNameCompliance(ApplicationMetricBoolean):
    r"""All Application names should start with 'myorg-'."""

    def compute(self):
        if self.application.name.startswith("myorg-"):
            return True
        return False

If we run this code, we'll get the following output:

Application             AppNameCompliance
myorg-finance-app                    True
myorg-marketing-service              True
myorg-sales-app                      True
sandbox-dinasour                    False

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

abstract_metrics-0.1.0.dev5.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abstract_metrics-0.1.0.dev5-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file abstract_metrics-0.1.0.dev5.tar.gz.

File metadata

  • Download URL: abstract_metrics-0.1.0.dev5.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-1011-azure

File hashes

Hashes for abstract_metrics-0.1.0.dev5.tar.gz
Algorithm Hash digest
SHA256 6553940b042de28af9de81806b097e42ef266d20c2686f910eed63e8eb08c2d3
MD5 8a39ca191add041c692eb350624fe056
BLAKE2b-256 cf71ebfa962556c84b9f6f8d403e58904a6e63cdd83d587464c768e915010199

See more details on using hashes here.

File details

Details for the file abstract_metrics-0.1.0.dev5-py3-none-any.whl.

File metadata

File hashes

Hashes for abstract_metrics-0.1.0.dev5-py3-none-any.whl
Algorithm Hash digest
SHA256 fbf3486a8d8fc784c4d4bf0b9c821fc8e13afcc0bdaf67482d1203f38da11405
MD5 11348a0e41a9326fbd8b39f659d05643
BLAKE2b-256 0919f5bc5d4eba1943429f1d6f17274f5384b98a4b2586a5de6f07d6b1d2d005

See more details on using hashes here.

Supported by

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