GithubHelp home page GithubHelp logo

mosquito / carbon-client Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 43 KB

graphite/carbon udp client for sending metrics

License: Other

Python 99.72% Shell 0.28%
graphite carbon client-lib python

carbon-client's Introduction

Carbon Client

https://travis-ci.org/mosquito/carbon-client.svg?branch=master Latest Version

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()

carbon-client's People

Contributors

mosquito avatar ostapsteam avatar vlanse avatar waynr avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

waynr durm

carbon-client's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.