Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Simple cleanup on python example script #194

Merged
merged 3 commits into from

2 participants

@sivy

This script needed to do something if simply run, as one might to test a new install.

I added an if__name__=="main" block and added a proper initializer for the sample client.

sivy added some commits
@sivy sivy Update examples/python_example.py
Give sample client a proper initializer, and give it a basic example 
metric to run if the script is called itself.
d9ecb0a
@sivy sivy Update examples/python_example.py
Fix host parameter value.
6061c3b
@sivy sivy Update examples/python_example.py
call the client a Client.
5953c66
@mrtazz
Owner

thanks for the pull request!

@mrtazz mrtazz merged commit ebf5bb7 into etsy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 12, 2012
  1. @sivy

    Update examples/python_example.py

    sivy authored
    Give sample client a proper initializer, and give it a basic example 
    metric to run if the script is called itself.
  2. @sivy

    Update examples/python_example.py

    sivy authored
    Fix host parameter value.
  3. @sivy

    Update examples/python_example.py

    sivy authored
    call the client a Client.
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 2 deletions.
  1. +17 −2 examples/python_example.py
View
19 examples/python_example.py
@@ -9,7 +9,17 @@
# statsd_port = 8125
# Sends statistics to the stats daemon over UDP
-class Statsd(object):
+class StatsdClient(object):
+ def __init__(self, host='localhost', port=8125):
+ self.host = host
+ self.port = port
+ try:
+ import local_settings as settings
+ self.host = settings.statsd_host
+ self.port = settings.statsd_port
+ except:
+ pass
+ self.addr=(host, port)
@staticmethod
def timing(stat, time, sample_rate=1):
@@ -83,9 +93,14 @@ def send(data, sample_rate=1):
for stat in sampled_data.keys():
value = sampled_data[stat]
send_data = "%s:%s" % (stat, value)
- udp_sock.sendto(send_data, addr)
+ udp_sock.sendto(send_data, self.addr)
except:
import sys
from pprint import pprint
print "Unexpected error:", pprint(sys.exc_info())
pass # we don't care
+
+
+if __name__=="__main__":
+ c = StatsdClient()
+ c.increment('example.python')
Something went wrong with that request. Please try again.