Skip to main content

graphite/carbon udp client for sending metrics

Project description

https://travis-ci.org/mosquito/carbon-client.svg?branch=master Latest Version https://img.shields.io/pypi/wheel/carbon-client.svg https://img.shields.io/pypi/pyversions/carbon-client.svg https://img.shields.io/pypi/l/carbon-client.svg

Client for sending metrics into carbon server

Initialization

By default carbon-client creates a client based on os.environ variables:

  • CARBON_HOST - Contains one or many endpoints (e.g “127.0.0.1:2003, 10.2.1.0:2003”)

  • CARBON_NS - it’s a namespace for sending metrics (e.g. “carbon.coal-service”)

Actually you can configure this by hands.

Example

The simple test :

# You should set ENV variables CARBON_HOST and CARBON_NS
# CARBON_HOST might contains multiple destinations (comma separated)
from time import sleep
from carbon.client import stat
from carbon.client.extras import SimpleCounter

# Will be pended one or two metrics
# carbon_client.counter_ok
# carbon_client.counter_fail - if exception will be raised
# carbon_client is namespace by default.
with SimpleCounter("counter"):
    sleep(1)

# Will be pended one metric
# carbon_client.timer_ok - if exception will be raised
# carbon_client.timer_fail - if exception will be raised
# carbon_client is namespace by default.
with SimpleTimer("timer"):
    sleep(1)

# Will be pended n metric
# carbon_client.collector
# carbon_client is namespace by default.
with SimpleCollector("collector") as collector:
    collector.add(123)
    collector.add(122)
    collector.add(-10)

# all metrics will sent.
stat.send()

The advanced test :

from time import sleep
from carbon.client import UDPClient
from carbon.client.extras import SimpleCounter, SimpleTimer, SimpleCollector

# Will be send to multiple destinations
client = UDPClient("127.0.0.1, 191.168.1.11:2003", "test")

with SimpleCounter("counter", client):
    sleep(1)

with SimpleTimer("timer", client):
    sleep(1)

with SimpleCollector("collector", client) as collector:
    collector.add(123)

client.send()

Another test :

from time import sleep
from carbon.client import stat
from carbon.client import metrics

# Counter
stat['counter'] = metrics.Counter
stat['counter'].inc(1)
sleep(1)
stat['counter'].dec(1)

# Timer
stat['timer'] = metrics.Timer
stop_watch = stat['timer'].start()
sleep(1)
stat['timer'].stop(stop_watch)

# Collector
stat['collector'] = metrics.Collector
stat['collector'].add(1)
sleep(1)
stat['collector'].add(2)
sleep(1)
stat['collector'].add(3)
sleep(1)
stat['collector'].add(-10)

stat.send()

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

carbon-client-0.3.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

carbon_client-0.3.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file carbon-client-0.3.1.tar.gz.

File metadata

File hashes

Hashes for carbon-client-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4503b2913d5c9bcced3a8e412a1222f000251d10693e05664431baa62040d36f
MD5 f1c885d3e1e800d5260f614f3bd1dd9f
BLAKE2b-256 6887e89316e22f6b0c6523bac0c9b6346c2cd185c916e4fc8a2b70cd9a83ac57

See more details on using hashes here.

File details

Details for the file carbon_client-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for carbon_client-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7658f303cd3631725793111763cbd1d6c1e7335009bb576c52cf1769dc60ec7
MD5 73c0eda29ab8f01773e875df3f3dbe97
BLAKE2b-256 eaab0da1ea152db54afee95a382d2c3f5ff850b3c640e25c1546f3540a379541

See more details on using hashes here.

Supported by

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