Skip to content

Instantly share code, notes, and snippets.

@sysdig-blog
Created March 26, 2019 18:02
Show Gist options
  • Save sysdig-blog/5b0ea34c09ca7f5c89c4d990f7b6c222 to your computer and use it in GitHub Desktop.
Save sysdig-blog/5b0ea34c09ca7f5c89c4d990f7b6c222 to your computer and use it in GitHub Desktop.
Python code example using StatsD
import statsd
import time
if __name__ == '__main__':
# Create a new connection for the client
connection = statsd.Connection(
host='127.0.0.1',
port=8125,
sample_rate=1,
)
# Create the client
client = statsd.Client("python", connection)
# Create counter
counter = client.get_counter("counter")
# Create gauge
gauge = client.get_gauge("gauge")
# Create average
average = client.get_average("average")
while True:
# Create a timer
timer = client.get_timer("timer")
# Will send the elapsed time once all the block has been executed
with timer:
counter += 1 # Increment by one the counter
gauge.set('foo', 10) # Send a gauge of 10
average.send('avg', 5)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment