Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Copy over example-client.py, link to it

  • Loading branch information...
commit af36d60bd0ad696d861d74fd900149c850a14356 1 parent bc2acb1
Sidnei da Silva authored
Showing with 74 additions and 9 deletions.
  1. +11 −9 README.md
  2. +63 −0 examples/example-client.py
View
20 README.md
@@ -39,12 +39,11 @@ graphs of that data through the frontend [Graphite Web][] application.
## Running carbon-cache.py
First you must tell carbon-cache what user it should run as. This must be a
-user with write privileges to $GRAPHITE_ROOT/storage/whisper/ Specify the user
-account in $GRAPHITE_ROOT/conf/carbon.conf
+user with write privileges to `$GRAPHITE_ROOT/storage/whisper`. Specify the
+user account in `$GRAPHITE_ROOT/conf/carbon.conf`. This user must also have
+write privileges to `$GRAPHITE_ROOT/storage/log/carbon-cache`
-This user must also have write privileges to $GRAPHITE_ROOT/storage/log/carbon-cache/
-
-Alternatively, you can run carbon-cache/carbon-relay/carbon-aggregator as
+Alternatively, you can run `carbon-cache`/`carbon-relay`/`carbon-aggregator` as
[Twistd plugins][], for example:
Usage: twistd [options] carbon-cache [options]
@@ -59,16 +58,19 @@ Alternatively, you can run carbon-cache/carbon-relay/carbon-aggregator as
--help Display this help and exit.
twistd [options] carbon-cache [
-Common options to twistd, like 'pidfile', 'logfile', 'uid', 'gid', 'syslog' and
-'prefix' are fully supported and have precedence over carbon's own options.
+Common options to `twistd(1)`, like `--pidfile`, '--logfile`, `--uid`, `--gid`,
+`--syslog` and `--prefix` are fully supported and have precedence over
+`carbon-*`'s own options. Please refer to `twistd --help` for the full list of
+supported `twistd` options.
[Twistd plugins]: http://twistedmatrix.com/documents/current/core/howto/plugin.html
## Writing a client
First you obviously need to decide what data it is you want to graph with
-graphite. The script examples/example-client.py demonstrates a simple client
-that sends loadavg data for your local machine to carbon on a minutely basis.
+graphite. The script [examples/example-client.py](examples/example-client.py)
+demonstrates a simple client that sends `loadavg` data for your local machine
+to carbon on a minutely basis.
The default storage schema stores data in one-minute intervals for 2 hours.
This is probably not what you want so you should create a custom storage schema
View
63 examples/example-client.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+"""Copyright 2008 Orbitz WorldWide
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License."""
+
+import sys
+import time
+import os
+import platform
+import subprocess
+from socket import socket
+
+CARBON_SERVER = '127.0.0.1'
+CARBON_PORT = 2003
+
+delay = 60
+if len(sys.argv) > 1:
+ delay = int( sys.argv[1] )
+
+def get_loadavg():
+ # For more details, "man proc" and "man uptime"
+ if platform.system() == "Linux":
+ return open('/proc/loadavg').read().strip().split()[:3]
+ else:
+ command = "uptime"
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
+ os.waitpid(process.pid, 0)
+ output = process.stdout.read().replace(',', ' ').strip().split()
+ length = len(output)
+ return output[length - 3:length]
+
+sock = socket()
+try:
+ sock.connect( (CARBON_SERVER,CARBON_PORT) )
+except:
+ print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
+ sys.exit(1)
+
+while True:
+ now = int( time.time() )
+ lines = []
+ #We're gonna report all three loadavg values
+ loadavg = get_loadavg()
+ lines.append("system.loadavg_1min %s %d" % (loadavg[0],now))
+ lines.append("system.loadavg_5min %s %d" % (loadavg[1],now))
+ lines.append("system.loadavg_15min %s %d" % (loadavg[2],now))
+ message = '\n'.join(lines) + '\n' #all lines must end in a newline
+ print "sending message\n"
+ print '-' * 80
+ print message
+ print
+ sock.sendall(message)
+ time.sleep(delay)
Please sign in to comment.
Something went wrong with that request. Please try again.