Skip to content

Instantly share code, notes, and snippets.

@sax
Forked from matthiasg/carbon-cache.sh
Last active December 29, 2015 11:19
Show Gist options
  • Save sax/7663192 to your computer and use it in GitHub Desktop.
Save sax/7663192 to your computer and use it in GitHub Desktop.
{
"alias":"graphite",
"brand": "joyent",
"image_uuid": "84cb7edc-3f22-11e2-8a2a-3f2a7b148699",
"max_physical_memory": 512,
"resolvers": [
"8.8.8.8",
"8.8.4.4"
],
"nics": [
{
"interface": "net0",
"nic_tag": "admin",
"gateway": "192.168.2.254",
"ip": "192.168.2.203",
"netmask": "255.255.255.0"
}
]
}
imgadm import 84cb7edc-3f22-11e2-8a2a-3f2a7b148699
# adjust ip and stuff in graphite.json
vmadm create -f graphite.json
zlogin <uuid of machine just created>
### GRAPHITE
export LC_ALL="en_US.UTF-8" # imporant for syncdb (otherwise the user creation will fail)
PYTHONPATH=/opt/local/lib/python2.7
pkgin in py27-carbon-0.9.10
pkgin in py27-graphite-web-0.9.10
export GRAPHITE_ROOT=/opt/local/graphite/
export GRAPHITE_CONF_DIR=/opt/local/etc/graphite
cd /opt/local/lib/python2.7/site-packages/graphite
cp local_settings.py.example local_settings.py
#
# change these to (timezone based on whatever you need):
#
# TIME_ZONE = 'Europe/Berlin'
#
# CONF_DIR = '/opt/local/graphite/conf'
# STORAGE_DIR = '/opt/local/graphite/storage'
# CONTENT_DIR = '/opt/local/graphite/webapp/content'
#
# also comment in the DATABASE={ ... } part
# and change NAME to /opt/local/graphite/storage/graphite.db
#
#
# Note: I read on http://www.spacevatican.org/2012/9/18/using-statsd-and-graphite-from-a-rails-app/
# that
#
# "When using statsd with its default settings it’s crucial that you keep at least
# some 10 second data (the default graphite config keeps 1min resolution data only).
# If you don’t then the mismatch between statsd’s flush rate and graphite’s
# flush rate will cause you to lose data. "
#
# That means storage-schemas.conf in /opt/local/etc/graphite should be edited like this:
# Add the following to storage-schemas.conf, above the [default_1min_for_1day] section
#
# [stats]
# pattern = ^stats\..*
# retentions = 10:2160,60:10080,600:262974
#
# [stats_count]
# pattern = ^stats_counts\..*
# retentions = 10:2160,60:10080,600:262974
#
# and edit storage-aggregation.conf by adding before the default entry
#
# [stats_counts]
# pattern = ^stats_counts\.
# xFilesFactor = 0
# aggregationMethod = sum
#
# CONFIGURING CARBON
# instead of relying on the declares above you can change the carbon.conf (/opt/local/etc/graphite/carbon.conf) like this
#
#
# STORAGE_DIR = /opt/local/graphite/storage
# CONF_DIR = /opt/local/etc/graphite
# LOG_DIR = /opt/local/graphite/storage/log/carbon-cache
# PID_DIR = /opt/local/graphite/storage
#
# LOCAL_DATA_DIR = /opt/local/graphite/storage/content
#
# STARTING CARBON
carbon-cache.py --config=/opt/local/etc/graphite/carbon.conf start
cd /opt/local/graphite
#will ask for username and password
python /opt/local/lib/python2.7/site-packages/graphite/manage.py syncdb
mkdir /opt/local/graphite/storage/log/webapp
run-graphite-devel-server.py --libs=/opt/local/lib/python2.7/site-packages/graphite /opt/local/graphite &
### STATSD
# I INSTALLED IT IN A DIFFERENT MACHINE (with git) and then copied it over to /opt/local/statsd
# git clone https://github.com/etsy/statsd
# then copy exampleConfig.js into config.js and update ip to 127.0.0.1
cd /opt/local/statsd
node stats.js config.js &
var StatsdClient = new require('statsd-client');
console.dir(StatsdClient)
var sdc = new StatsdClient({host: '<IP?', port:8125, prefix:"test"});
console.dir(sdc)
var timer = new Date();
for (var i = 0; i < 100; i++) {
sdc.increment('counter'); // Increment by one.
};
sdc.increment('counter'); // Increment by one.
sdc.gauge('gauge', 10); // Set gauge to 10
sdc.timing('timer', timer); // Calculates time diff
sdc.close(); // Optional - stop NOW
forward port 8080 and port 8125 to that machines ip if necessary
create a folder for statsd
npm install statsd-client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment