Skip to main content

Your friendly neighbourhood monitoring library. Record metrics about whatever you are interested in (e.g. application state, data integrity).

Project description

sinai

Monitor application state, data integrity, or anything you want.

Usage

To develop a monitoring application with sinai, you install it and import it like any other Python library. See example.py.

There are no required dependencies, but optional dependencies are required for the relevant features:

  • requests to use API sources and stores, and the Slack store
  • pymongo to use MongoDB sources and stores
  • boto3 to use the CloudWatch store

Development

To develop sinai itself, check out the code from Github and use the following commands to create a development environment:

$ pipenv install --dev
$ pre-commit install

What's it all about?

This is a library for developing monitoring applications.

The idea is akin to Model-View-Controller (MVC) Frameworks that you find in web applications. Sinai provides useful base classes and you subclass them to build your own monitoring application.

Following the MVC analogy, sinai only provides one model called Metric.

The views come in two types. A Source provides data. A Store receives data.

A controller is called a Rule. A rule takes data from sources, does whatever calculations or transformations are required, then returns the metrics to be stored.

We describe those classes in more detail below.

Base Classes

Metric

A Metric records a piece of data that you want to capture, either from an external source or from performing calculations or aggregations on other metrics.

A metric has a few default fields. The precise semantic meaning of the values is specific to your application.

Your metric subclass needs a name to distinguish its instances from others. This is important when storing or serialising the metrics.

Your metric can have an optional context string you can use to group instances of that metric together. For example, if you wanted to group the metrics by region, the context values might be UK, EU, US, etc. If you are monitoring animals, your context values might be lion, crocodile, etc.

The ref field is available to store a piece of arbitrary string data. If your application monitors data integrity, it might be the external reference of a piece of incorrect data in the system under test. If you are tracking planets, it might be the name of the planet.

The value field is available to store a numerical value. Again, whatever that means is particular to your metric. E.g. the number of fish caught, or the refund owed to a customer.

The checked field is available to store a boolean value (True/False). Was the customer happy? Was the suspect read his rights? Have we taken relevant action?

The annotations field is available to store textual data. A list of items bought, notes on the metric. Whatever you want.

You can add extra fields, but you have to deal with the serialisation and deserialisation of those yourself in your source and store classes.

Sources and Stores

Sinai provides several stores and sources, you will subclass them to make your own application specific ones.

Provided Sources:

  • Source - the base class for all stores.

  • ApiSource - Get data from an API endpoint

  • MongoSource - Get data from MongoDB Collections

  • MetricSource - Get Metrics from memory (for aggregation or further calculations)

  • MongoMetricSource - Get Metrics from MongoDB

Provided Stores:

  • Store - the base class for all stores

  • ApiStore - post data to an API endpoint

  • MetricStore - base class for Metric Stores

  • MemoryMetricStore - Store Metrics in memory (for aggregation or further calculations)

  • MongoMetricStore - Store Metrics in MongoDB

  • Slack - Post metrics to a Slack channel

  • CloudWatch - store metrics in AWS Cloudwatch

Rules

Rule is the base class - you override the sources and stores attributes to tell your rule where to take data from and where to send your resulting metrics. Your subclass overrides the evaluate method to perform whatever calculations you require to populate your metric instances with data.

Sinai currently comes with one premade rule:

  • MetricAggregationRule - aggregates stored metrics and produces a metric with the result. Supports count, sum, max, min, mean, mode and median.

Monitor

The Monitor is the entry point to the application. A user invokes the monitor, using a command, or through a cron or AWS lambda or whatever. It connects to the sources, evaluates the rules, then stores the data. Your Monitor subclass overrides the rules attribute with the list of rule classes to run.

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

sinai-0.0.23.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

sinai-0.0.23-py2.py3-none-any.whl (19.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sinai-0.0.23.tar.gz.

File metadata

  • Download URL: sinai-0.0.23.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for sinai-0.0.23.tar.gz
Algorithm Hash digest
SHA256 028a4d62f460ae969c77315bdfacb86ea0163c40b2b3e95ce9790dda4b6adc4e
MD5 dbc6256cf51f7b6c4913aaddf7b9002a
BLAKE2b-256 445286cfa1169673d45a441048404a24fef5e97eaeff6509d7e924fd72ef032e

See more details on using hashes here.

File details

Details for the file sinai-0.0.23-py2.py3-none-any.whl.

File metadata

  • Download URL: sinai-0.0.23-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for sinai-0.0.23-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 959d73574252812822f7f29d2630a49f00ea4c5098e6506d27d705c068b66758
MD5 7f37a89b1dc55bf8e4b43a247ec9ebfd
BLAKE2b-256 898bea3763def83e2a6dc4e7224fed462379fa9c91701e3615b79731d0b2fac0

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