Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Forked from surjikal/1-diamond-install.md
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save bugcy013/11155967 to your computer and use it in GitHub Desktop.

Select an option

Save bugcy013/11155967 to your computer and use it in GitHub Desktop.

What is Diamond?

https://github.com/BrightcoveOS/Diamond

From their wiki:

Diamond is a python daemon that collects system metrics and publishes them to Graphite. It is capable of collecting cpu, memory, network, i/o, load and disk metrics. Additionally, it features an API for implementing custom collectors for gathering metrics from almost any source.

Deps

apt-get install build-essentials
apt-get install python-dev
pip install psutil
pip install configobj

git clone https://github.com/BrightcoveOS/Diamond.git cd Diamond make install

scp -r [email protected]:/etc/init.d/diamond /etc/init.d/diamond scp -r [email protected]:/etc/diamond/diamond.conf /etc/diamond/diamond.conf mkdir /var/log/diamond chmod +x /etc/init.d/diamond /etc/init.d/diamond restart

Installation

Ubuntu Precise Pangolin (12.04)

  • Clone the repo (git clone https://github.com/BrightcoveOS/Diamond.git)
  • Run sudo make install
  • Create and modify /etc/diamond/diamond.conf (copy the example config)
    • Change 'collectors_path' to be '/usr/local/share/diamond/collectors/'
  • Run mkdir /var/log/diamond
  • Replace the init script with the one found below.
#!/bin/sh
#
# diamond Start the diamond statistics collector
#
# chkconfig: 2345 99 01
# description: Diamond is a daemon and toolset for gathering system statistics \
# and publishing them to Graphite.
# processname: python
# config: /etc/diamond/diamond.conf
# pidfile: /var/run/diamond.pid
### BEGIN INIT INFO
# Provides: diamond
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: System statistics collector for Graphite.
# Description: Diamond is a daemon and toolset for gathering system statistics
# and publishing them to Graphite.
### END INIT INFO
# Author: Sam Bashton <[email protected]>
NAME=diamond
DAEMON=/usr/local/bin/diamond
DAEMON_ARGS="-p /var/run/diamond.pid"
PIDFILE=/var/run/diamond.pid
SCRIPTNAME=/etc/init.d/diamond
start() {
echo -n "Starting $NAME: "
start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
echo -n "$NAME."
}
stop() {
echo -n $"Stopping $NAME: "
start-stop-daemon --stop --pidfile $PIDFILE --exec $DAEMON
echo -n "$NAME."
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 2
;;
esac
exit $?
################################################################################
# Diamond Configuration File
################################################################################
################################################################################
### Options for the server
[server]
# Handlers for published metrics.
handlers = diamond.handler.graphite.GraphiteHandler, diamond.handler.archive.ArchiveHandler
# User diamond will run as
# Leave empty to use the current user
user =
# Group diamond will run as
# Leave empty to use the current group
group =
# Pid file
pid_file = /var/run/diamond.pid
# Directory to load collector modules from
#collectors_path = /usr/share/diamond/collectors/
collectors_path = /usr/local/share/diamond/collectors/
# Directory to load collector configs from
collectors_config_path = /etc/diamond/collectors/
# Directory to load handler configs from
handlers_config_path = /etc/diamond/handlers/
handlers_path = /usr/share/diamond/handlers/
# Interval to reload collectors
collectors_reload_interval = 3600
################################################################################
### Options for handlers
[handlers]
# daemon logging handler(s)
keys = rotated_file
### Defaults options for all Handlers
[[default]]
[[ArchiveHandler]]
# File to write archive log files
log_file = /var/log/diamond/archive.log
# Number of days to keep archive log files
days = 7
[[GraphiteHandler]]
### Options for GraphiteHandler
# Graphite server host
host = 192.168.70.231
# Port to send metrics to
port = 2003
# Socket timeout (seconds)
timeout = 15
# Batch size for metrics
batch = 1
[[GraphitePickleHandler]]
### Options for GraphitePickleHandler
# Graphite server host
host = 192.168.70.231
# Port to send metrics to
port = 2004
# Socket timeout (seconds)
timeout = 15
# Batch size for pickled metrics
batch = 256
[[MySQLHandler]]
### Options for MySQLHandler
# MySQL Connection Info
hostname = 127.0.0.1
port = 3306
username = root
password =
database = diamond
table = metrics
# INT UNSIGNED NOT NULL
col_time = timestamp
# VARCHAR(255) NOT NULL
col_metric = metric
# VARCHAR(255) NOT NULL
col_value = value
[[StatsdHandler]]
host = 127.0.0.1
port = 8125
[[TSDBHandler]]
host = 127.0.0.1
port = 4242
timeout = 15
[[LibratoHandler]]
user = [email protected]
apikey = abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
[[HostedGraphiteHandler]]
apikey = abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
timeout = 15
batch = 1
# And any other config settings from GraphiteHandler are valid here
[[HttpPostHandler]]
### Urp to post the metrics
url = http://localhost:8888/
### Metrics batch size
batch = 100
################################################################################
### Options for collectors
[collectors]
[[default]]
### Defaults options for all Collectors
# Uncomment and set to hardcode a hostname for the collector path
# Keep in mind, periods are seperators in graphite
# hostname = my_custom_hostname
# If you prefer to just use a different way of calculating the hostname
# Uncomment and set this to one of these values:
# smart = Default. Tries fqdn_short. If that's localhost, uses hostname_short
# fqdn_short = Default. Similar to hostname -s
# fqdn = hostname output
# fqdn_rev = hostname in reverse (com.example.www)
# uname_short = Similar to uname -n, but only the first part
# uname_rev = uname -r in reverse (com.example.www)
# hostname_short = `hostname -s`
# hostname = `hostname`
# hostname_rev = `hostname` in reverse (com.example.www)
# hostname_method = smart
# Path Prefix and Suffix
# you can use one or both to craft the path where you want to put metrics
# such as: %(path_prefix)s.$(hostname)s.$(path_suffix)s.$(metric)s
# path_prefix = servers
# path_suffix =
# Path Prefix for Virtual Machines
# If the host supports virtual machines, collectors may report per
# VM metrics. Following OpenStack nomenclature, the prefix for
# reporting per VM metrics is "instances", and metric foo for VM
# bar will be reported as: instances.bar.foo...
# instance_prefix = instances
# Default Poll Interval (seconds)
# interval = 300
################################################################################
### Options for logging
# for more information on file format syntax:
# http://docs.python.org/library/logging.config.html#configuration-file-format
[loggers]
keys = root
# handlers are higher in this config file, in:
# [handlers]
# keys = ...
[formatters]
keys = default
[logger_root]
# to increase verbosity, set DEBUG
level = INFO
handlers = rotated_file
propagate = 1
[handler_rotated_file]
class = handlers.TimedRotatingFileHandler
level = DEBUG
formatter = default
# rotate at midnight, each day and keep 7 days
args = ('/var/log/diamond/diamond.log', 'midnight', 1, 7)
[formatter_default]
format = [%(asctime)s] [%(threadName)s] %(message)s
datefmt =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment