Skip to main content

A Python client for OpenTSDB which creates a separate thread for TCP communication.

Project description

potsdb
======

Python client to OpenTSDB

This was designed with a long running parent program in mind, where sending metrics was something that happens on the side.
Implemented such that sending the metric "put" message to the Time Series Database API does not block the calling application. This is achieved by creating a background worker thread which takes metrics off the Queue, then sending them on a TCP socket to HOST. The client.log method simply sets up and puts the metric on the Queue, then returns.

When the client object is instantiated, a temporary socket is created to the target HOST, PORT combination to check for connectivity. This may fail with a timeout error. However if the background thread encounters socket communication problems like timeout further down the line (in the sending metrics loop) then it will silenty keep trying to reconnect forever.

Keep in mind that if you send a bunch of metrics through .log then immediately quit, the background thread will also terminate, without having had enough time to send your metrics properly.

Rate limiting for sending metrics over TCP is by default set to 100 Metrics Per Second. This can be overwritten upon instantiation.

Installation
===
Clone this repo, then
```
cd potsdb
python setup.py install
```
or
```
pip install potsdb
```

Usage
===
```
import potsdb

# minimum is hostname. port is defaulted to 4242:
metrics = potsdb.Client('hostname.local')
# all options:
metrics = potsdb.Client('hostname.local', port=4242, qsize=1000, host_tag=True, mps=100, check_host=True)

# qsize: Max Size of Queue
# host_tag: True for automatic, string value for override, None for nothing
# mps: Metrics Per Second rate limiting
# check_host: change to false to skip startup connectivity checking

# Bare minimum is metric name, metric value
metrics.send('test.metric2', 100)
# tags can also be specified
metrics.send('test.metric5', 100, extratag1='tagvalue', extratag2='tagvalue')
# host tag is set automatically, but can be overwritten
metrics.send('test.metric6', 34, host='app1.local')

# waits for all outstanding metrics to be sent and background thread closes
metrics.wait()

```

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

potsdb-1.0.0.tar.gz (12.2 kB view details)

Uploaded Source

File details

Details for the file potsdb-1.0.0.tar.gz.

File metadata

  • Download URL: potsdb-1.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for potsdb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a42342d92e48594857e3ae7509fe7f7b5dc06fcb4ade066b1b4771988c08058f
MD5 b4cfa09735334e3378fabab861a4d984
BLAKE2b-256 7b1bc85ce2f452d0eb704fe01f3d1af68ec2fc8814656cc95522f0c521c63945

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