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¶
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.
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
-
Helper CLasses¶
Exceptions¶
Dialects¶
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.