Base10: Metric abstraction layer

Release v0.6.3. (Changelog)

Base10 is a metrics abstractoin layer for linking multiple metrics source and stores. It also simplifies metric creation and proxying.

Guide

Installation

From PyPi

$ pip install base10

From source

Base10 is developed on Github.

You can clone the public repo:

$ git clone https://github.com/mattdavis90/base10.git

Once you have the source, you can install it into your site-packages with

$ python setup.py install

Usage

Use MetricHelper to aid Metric creation, and MetricHandler to aid reading and writing metrics.

Metric Generator

This shows a simple metric generator that writes a JSON formatted metric, containing a random value, to RabbitMQ.

from random import random
from time import sleep

from base10 import MetricHelper, MetricHandler
from base10.dialects import JSONDialect
from base10.transports import RabbitMQWriter

if __name__ == '__main__':

    class MyMetric(MetricHelper):
        _name = 'metric'

        _fields = [
            'value',
        ]

        _metadata = [
            'hostname',
        ]

    class JSON(MetricHandler):
        _dialect = JSONDialect()
        _writer = RabbitMQWriter(
            broker='127.0.0.1', exchange='amq.topic', topic='metrics.example')

    json = JSON()

    while True:
        json.write(MyMetric(value=random(), hostname='test'))
        sleep(1)

Metric Proxy

This shows a simple proxy that reads JSON formatted metrics from RabbitMQ and outputs them in InfluxDB format over a UDP socket.

from base10 import MetricHandler
from base10.dialects import JSONDialect, SplunkDialect  #InfluxDBDialect
from base10.transports import RabbitMQReader, UDPWriter

if __name__ == '__main__':

    class RabbitMQ(MetricHandler):
        _dialect = JSONDialect()
        _reader = RabbitMQReader(
            broker='127.0.0.1', exchange='amq.topic', routing_key='metrics.#')

    class InfluxDB(MetricHandler):
        _dialect = SplunkDialect()  #InfluxDBDialect()
        _writer = UDPWriter(host='127.0.0.1', port=10000)

    rabbitmq = RabbitMQ()
    influxdb = InfluxDB()

    for metric in rabbitmq.read():
        influxdb.write(metric)

API Reference

Base Classes

class base10.base.Dialect(*args, **kwargs)[source]
__init__(*args, **kwargs)[source]
from_string(string)[source]
to_string(metric)[source]
class base10.base.Metric(name, fields, metadata, **kwargs)[source]

Generic Metric class

__init__(name, fields, metadata, **kwargs)[source]

Create a new Metric

Parameters:
  • name – Name of the metric.
  • fields – List of field names to include.
  • metadata – List of metadata field names to include.
  • **kwargs

    Keyword values for the fields and metadata.

fields

Get Metric fields

metadata

Get Metric metadata

name

Get Metric name

values

Get Metric values

class base10.base.Reader(*args, **kwargs)[source]
__init__(*args, **kwargs)[source]
read()[source]
class base10.base.Writer(*args, **kwargs)[source]
__init__(*args, **kwargs)[source]
write(string)[source]

Helper CLasses

Exceptions

Dialects

class base10.dialects.json_dialect.JSONDialect(*args, **kwargs)[source]
{

name: ‘cpu_usage’, fields: {

user: 0.2, free: 0.75

}, metadata: {

hostname: ‘host-1’

}, timestamp: 1489478831

}

Transports

Project Info

Changelog

0.5.3

  • Removed: Python2.6 support (It didn’t work anyway)

0.5.2

  • Added: base10.__version__

0.5.1 - README on PyPi

  • Changed: README on PyPi (Again!)

0.5.0 - Testing, Docs, Coverage

  • Changed: Semantic versioning
  • Changed: Testing using Travis-CI
  • Changed: Docs on Read the Docs
  • Changed: Coverage on Coveralls

0.5 - Splunk Support

  • Added: Splunk Dialect (Write-only)
  • Changed: RabbitMQ kwarg pass-through
  • Changed: Faster time() function

0.4 - README on PyPi

  • Changed: Added README to PyPi

0.3 - RabbitMQ Support

  • Added: RabbitMQ Transport
  • Changed: Nanosecond timestamp
  • Changed: Breaking changes to API

0.2 - Influx and UDP Support

  • Added: InfluxDB Dialect (Write-only)
  • Added: UDP Transport (Send-only)
  • Changed: Millisecond timestamp
  • Changed: Breaking changes to API

0.1 - Initial Release

  • Added: File Transport
  • Added: JSON Dialect

License

The MIT License (MIT)

Copyright (c) 2017 Matt Davis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.