Created
November 15, 2011 19:16
-
-
Save TimidRobot/1368022 to your computer and use it in GitHub Desktop.
**Deprecated by https://github.com/TimZehta/graphite-dashgen** naive bash script that creates default graphite dashboards for all hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Created on 2011-11-03 by Tim Baldoni <tim@clockwork.net> | |
# | |
# Creates HOST_default dashboards in graphite | |
# | |
# | |
# Notes: | |
# - First and last items are missing from the graph definitions below. This | |
# makes things much easier...but prevents the resulting graphs from being | |
# cloned in the Graphite Dashboard. | |
# - maximumAbove function used to filter noise | |
# - sortByMaxima fucntion to prevent data loss in resulting graphs (maintain | |
# z order) | |
# - keepLastValue function used where data is collected less frequently | |
# - functions used above mean that colors can shift as data is reported. The | |
# following values, however, are always green to aid quick reading: | |
# - Apache Scoreboard open | |
# - CPU idle | |
# - Process State sleeping | |
# - Memory free | |
# - Swap free | |
# - DF free | |
# (green has been removed from default lineColors in graphTemplates.conf) | |
# | |
graphite_host='HOSTNAME' | |
hosts=/opt/graphite/storage/whisper/collectd | |
db=/opt/graphite/storage/graphite.db | |
sqlfile=$(mktemp -t ${prog}.XXXXXXXX) | |
trap 'es=${?};rm -f ${sqlfile};exit ${es}' INT TERM EXIT | |
width=300 | |
height=230 | |
date=$(date +%FT%T) | |
color_combined='2f4f4f' # DarkSlateGray | |
color_free='green' | |
# relative time range | |
units='hours' | |
quantity=1 | |
# backup graphite database | |
cp ${db} ~/graphite_db_backups/graphite.db.$(date +%F_%H-%M) | |
for _host_path in ${hosts}/* | |
do | |
_host=${_host_path##*/} | |
_name=${_host}_default | |
# begining of sql statement | |
echo -n "INSERT OR REPLACE INTO dashboard_dashboard (name,state) VALUES ('${_name}','{\"name\": \"${_name}\", \"defaultGraphParams\": {\"width\": \"${width}\", \"from\": \"-${quantity}${units}\", \"until\": \"now\", \"height\": \"${height}\", \"fontName\": \"Sans\"}, \"refreshConfig\": {\"interval\": 60000, \"enabled\": false}, \"graphs\": [" | |
# Carbon | |
if [[ "${_host}" == "${graphite_host}" ]] | |
then | |
# Carbon Metrics | |
echo -n "[\"\", {\"vtitle\": \"points\", \"target\": [\"alias(keepLastValue(carbon.aggregator.luxon_cw-a.metricsReceived),\\\"aggregator_received\\\")\", \"alias(keepLastValue(carbon.agents.luxon_cw-a.metricsReceived),\\\"cache_received\\\")\", \"alias(keepLastValue(carbon.agents.luxon_cw-a.committedPoints),\\\"cache_committed\\\")\"], \"title\": \"Carbon_Metrics\"}, \"\"]" | |
echo -n ', ' | |
# Carbon Cache Errors | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(lineWidth(keepLastValue(carbon.agents.luxon_cw-a.errors),2),3)\"], \"title\": \"Carbon_Cache_Errors\"}, \"\"]" | |
echo -n ', ' | |
# Carbon Cache Avg Update Time | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(keepLastValue(carbon.agents.luxon_cw-a.avgUpdateTime),3)\"], \"title\": \"Carbon_Cache_Avg_Update_Time\"}, \"\"]" | |
echo -n ', ' | |
# Carbon Cache Points per Update | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(keepLastValue(carbon.agents.luxon_cw-a.pointsPerUpdate),3)\"], \"title\": \"Carbon_Cache_Points_per_update\"}, \"\"]" | |
echo -n ', ' | |
# Carbon Cache Queues | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(keepLastValue(carbon.agents.luxon_cw-a.cache.queues),4)\"], \"title\": \"Carbon_Cache_Queues\"}, \"\"]" | |
echo -n ', ' | |
# Carbon Cache Queries | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(keepLastValue(carbon.agents.luxon_cw-a.cache.queries),4)\"], \"title\": \"Carbon_Cache_Queries\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# Apache | |
if [[ -d ${_host_path}/apache ]] | |
then | |
# Apache Bytes | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(collectd.${_host}.apache.apache_bytes,3)\"], \"title\": \"Apache_Bytes\"}, \"\"]" | |
echo -n ', ' | |
# Apache Connections and Requests | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.apache.apache_connections,3)\", \"substr(collectd.${_host}.apache.apache_requests,3)\"], \"title\": \"Apache_Connections_and_Requests\"}, \"\"]" | |
echo -n ', ' | |
# Apache Scoreboard | |
echo -n "[\"\", {\"hideLegend\": \"false\", \"areaMode\": \"stacked\", \"target\": [\"substr(sortByMaxima(maximumAbove(collectd.${_host}.apache.scoreboard.[a-np-z]*,0.1)),4)\", \"substr(color(collectd.${_host}.apache.scoreboard.open,\\\"${color_free}\\\"),4)\"], \"title\": \"Apache_Scoreboard\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# Memcached | |
if [[ -d ${_host_path}/memcached ]] | |
then | |
# Memcached Cache and Items | |
if [[ -d ${_host_path}/memcached/cache ]] | |
then | |
echo -n "[\"\", {\"target\": [\"substr(stacked(collectd.${_host}.memcached.cache.used),4)\", \"substr(color(stacked(collectd.${_host}.memcached.cache.free),\\\"${color_free}\\\"),4)\", \"substr(secondYAxis(collectd.${_host}.memcached.items),3)\"], \"yMinLeft\": \"0\", \"yMinRight\": \"0\", \"title\": \"Memcached_Cache_and_Items\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# Memcached Commands and Ops | |
echo -n "[\"\", {\"target\": [\"substr(sortByMaxima(collectd.node01.memcached.{command,ops}.*),4)\"], \"title\": \"Memcached_Commands_and_Ops\"}, \"\"]" | |
echo -n ', ' | |
# Memcached Connections | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(collectd.${_host}.memcached.connections,3)\"], \"title\": \"Memcached_Connections\"}, \"\"]" | |
echo -n ', ' | |
# Memcached Hit_Ratio | |
if [[ -f ${_host_path}/memcached/hitratio.wsp ]] | |
then | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(collectd.${_host}.memcached.hitratio,3)\"], \"title\": \"Memcached_Hit_Ratio\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# Memcached Octets | |
if [[ -d ${_host_path}/memcached/octets ]] | |
then | |
echo -n "[\"\", {\"target\": [\"alias(dashed(color(sumSeries(collectd.${_host}.memcached.octets.*),\\\"${color_combined}\\\"),1),\\\"combined\\\")\", \"substr(collectd.${_host}.memcached.octets.*,4)\"], \"title\": \"Memcached_Octets\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# Memcached Processes | |
if [[ -d ${_host_path}/memcached/ps_count ]] | |
then | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.memcached.ps_count.*,4)\"], \"title\": \"Memcached_Processes\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# Memcached CPU Time | |
echo -n "[\"\", {\"areaMode\": \"stacked\", \"target\": [\"substr(sortByMaxima(collectd.${_host}.memcached.ps_cputime.*),4)\"], \"title\": \"Memcached_CPU_Time\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# MySQL | |
if [[ -d ${_host_path}/mysql/collectd_mon ]] | |
then | |
# MySQL Cache Size | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(collectd.${_host}.mysql.collectd_mon.cache_size,4)\"], \"title\": \"MySQL_Cache_Size\"}, \"\"]" | |
echo -n ', ' | |
# MySQL Cache Result | |
echo -n "[\"\", {\"areaMode\": \"stacked\", \"target\": [\"substr(sortByMaxima(collectd.${_host}.mysql.collectd_mon.cache_result.*),5)\"], \"title\": \"MySQL_Cache_Result\"}, \"\"]" | |
echo -n ', ' | |
# MySQL top six Commands | |
echo -n "[\"\", {\"hideLegend\": \"false\", \"areaMode\": \"stacked\", \"target\": [\"substr(sortByMaxima(highestMax(collectd.${_host}.mysql.collectd_mon.mysql_commands.*,6)),5)\"], \"title\": \"MySQL_top_six_Commands\"}, \"\"]" | |
echo -n ', ' | |
# MySQL Threads | |
echo -n "[\"\", {\"target\": [\"substr(sortByMaxima(collectd.${_host}.mysql.collectd_mon.threads.*),5)\"], \"title\": \"MySQL_Threads\"}, \"\"]" | |
echo -n ', ' | |
# MySQL Locks | |
echo -n "[\"\", {\"target\": [\"substr(sortByMaxima(collectd.${_host}.mysql.collectd_mon.mysql_locks.*),5)\"], \"title\": \"MySQL_Locks\"}, \"\"]" | |
echo -n ', ' | |
# MySQL Octets | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.mysql.collectd_mon.mysql_octets.*,5)\"], \"title\": \"MySQL_Octets\"}, \"\"]" | |
echo -n ', ' | |
fi | |
# CPU | |
# - comma and space (echo -n ', ') provided by conditional above | |
echo -n "[\"\", {\"areaMode\": \"stacked\", \"target\": [\"sortByMaxima(maximumAbove(groupByNode(exclude(collectd.${_host}.cpu.*.*,\\\"idle\\\"),4,\\\"sumSeries\\\"),0.1))\",\"substr(color(sumSeries(collectd.${_host}.cpu.*.idle),\\\"${color_free}\\\"),4)\"], \"title\": \"CPU\"}, \"\"]" | |
# Load | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(sortByMaxima(collectd.${_host}.load.*),3)\"], \"title\": \"Load\"}, \"\"]" | |
# Process_State | |
echo -n ', ' | |
echo -n "[\"\", {\"areaMode\": \"stacked\", \"target\": [\"substr(sortByMaxima(maximumAbove(exclude(collectd.${_host}.processes.ps_state.*,\\\"sleeping\\\"),0.1)),4)\", \"substr(color(collectd.${_host}.processes.ps_state.sleeping,\\\"${color_free}\\\"),4)\"], \"title\": \"Process_State\"}, \"\"]" | |
# Process_Fork_Rate | |
echo -n ', ' | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(collectd.${_host}.processes.fork_rate,3)\"], \"title\": \"Process_Fork_Rate\"}, \"\"]" | |
# Memory | |
# - explicit metric names to ensure order | |
echo -n ', ' | |
echo -n "[\"\", {\"areaMode\": \"stacked\", \"target\": [\"substr(collectd.${_host}.memory.{used,buffered,cached}*,3)\", \"substr(color(collectd.${_host}.memory.free,\\\"${color_free}\\\"),3)\"], \"title\": \"Memory\"}, \"\"]" | |
# Swap | |
# - explicit metric names to ensure order | |
echo -n ', ' | |
echo -n "[\"\", {\"areaMode\": \"stacked\", \"target\": [\"substr(collectd.${_host}.swap.{used,cached},3)\", \"substr(color(collectd.${_host}.swap.free,\\\"${color_free}\\\"),3)\"], \"title\": \"Swap\"}, \"\"]" | |
# df | |
for _df in ${_host_path}/df/* | |
do | |
_df=${_df##*/} | |
_df_name=${_df//-/.} | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(stacked(collectd.${_host}.df.${_df}.{used,reserved}),4)\", \"substr(color(stacked(collectd.${_host}.df.${_df}.free),\\\"${color_free}\\\"),4)\", \"alias(color(scale(sumSeries(collectd.${_host}.df.${_df}.*),0.8),\\\"white\\\"),\\\"80%\\\")\"], \"yMin\": \"0\", \"title\": \"DF_${_df_name}\"}, \"\"]" | |
done | |
# disk | |
for _disk_path in ${_host_path}/disk/* | |
do | |
_disk=${_disk_path##*/} | |
_disk_name=${_disk//-/.} | |
# octets | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"alias(dashed(color(sumSeries(collectd.${_host}.disk.${_disk}.octets.*),\\\"${color_combined}\\\"),1),\\\"combined\\\")\", \"substr(collectd.${_host}.disk.${_disk}.octets.*,5)\"], \"title\": \"Disk_${_disk_name}_octets\"}, \"\"]" | |
# ops | |
if [[ -d ${_disk_path}/ops ]] | |
then | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"alias(dashed(color(sumSeries(collectd.${_host}.disk.${_disk}.ops.*),\\\"${color_combined}\\\"),1),\\\"combined\\\")\", \"substr(collectd.${_host}.disk.${_disk}.ops.*,5)\"], \"title\": \"Disk_${_disk_name}_ops\"}, \"\"]" | |
fi | |
# time | |
if [[ -d ${_disk_path}/time ]] | |
then | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"alias(dashed(color(sumSeries(collectd.${_host}.disk.${_disk}.time.*),\\\"${color_combined}\\\"),1),\\\"combined\\\")\", \"substr(collectd.${_host}.disk.${_disk}.time.*,5)\"], \"title\": \"Disk_${_disk_name}_time\"}, \"\"]" | |
fi | |
unset _disk | |
done | |
# interface | |
for _iface in ${_host_path}/interface/* | |
do | |
_iface=${_iface##*/} | |
_iface_name=${_iface//-/.} | |
# octets | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"alias(dashed(color(sumSeries(collectd.${_host}.interface.${_iface}.octets.*),\\\"${color_combined}\\\"),1),\\\"combined\\\")\", \"substr(collectd.${_host}.interface.${_iface}.octets.*,5)\"], \"title\": \"Interface_${_iface_name}_octets\"}, \"\"]" | |
# packets | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"alias(dashed(color(sumSeries(collectd.${_host}.interface.${_iface}.packets.*),\\\"${color_combined}\\\"),1),\\\"combined\\\")\", \"substr(collectd.${_host}.interface.${_iface}.packets.*,5)\"], \"title\": \"Interface_${_iface_name}_packets\"}, \"\"]" | |
# errors | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.interface.${_iface}.errors.*,5)\"], \"title\": \"Interface__${_iface_name}__errors\"}, \"\"]" | |
done | |
# NFS | |
if [[ -d ${_host_path}/nfs/client ]] | |
then | |
# NFS Client | |
echo -n ', ' | |
echo -n "[\"\", {\"hideLegend\": \"false\", \"target\": [\"substr(sortByMaxima(highestAverage(collectd.${_host}.nfs.client.*,6)),4)\"], \"title\": \"NFS_Client\"}, \"\"]" | |
fi | |
if [[ -d ${_host_path}/nfs/server ]] | |
then | |
# NFS Server | |
echo -n ', ' | |
echo -n "[\"\", {\"hideLegend\": \"false\", \"target\": [\"substr(sortByMaxima(highestAverage(collectd.${_host}.nfs.server.*,6)),4)\"], \"title\": \"NFS_Server\"}, \"\"]" | |
fi | |
# Postfix Inbound Connections | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.tail.postfix.conn-in.open,5)\", \"substr(sortByMaxima(maximumAbove(exclude(collectd.${_host}.tail.postfix.conn-in.*,\\\"open\\\"),0.1)),5)\"], \"title\": \"Postfix_Inbound_Connections\"}, \"\"]" | |
# Postfix Outbound Connections | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.tail.postfix.conn-out.*,5)\"], \"title\": \"Postfix_Outbound_Connections\"}, \"\"]" | |
# Postfix Status | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(sortByMaxima(collectd.${_host}.tail.postfix.status.sent),5)\", \"substr(sortByMaxima(maximumAbove(exclude(collectd.${_host}.tail.postfix.status.*,\\\"sent\\\"),0.1)),5)\"], \"title\": \"Postfix_Status\"}, \"\"]" | |
# Postfix Delays | |
if [[ -d ${_host_path}/tail/postfix/delay ]] | |
then | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.tail.postfix.delay.total,5)\", \"substr(sortByMaxima(maximumAbove(exclude(collectd.${_host}.tail.postfix.delay.*,\\\"total\\\"),0.1)),5)\"], \"title\": \"Postfix_Delays\", \"drawNullAsZero\": \"true\"}, \"\"]" | |
fi | |
# Postfix Rejected | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(collectd.${_host}.tail.postfix.rejected.total,5)\", \"substr(sortByMaxima(maximumAbove(exclude(collectd.${_host}.tail.postfix.rejected.*,\\\"total\\\"),0.1)),5)\"], \"title\": \"Postfix_Rejected\"}, \"\"]" | |
# Postfix Message Size | |
echo -n ', ' | |
echo -n "[ \"\", {\"hideLegend\": \"true\", \"target\": [\"substr(collectd.${_host}.tail.postfix.message-size,4)\"], \"title\": \"Postfix_Message_Size\"}, \"\"]" | |
# Apache Access All First Byte | |
if [[ -d ${_host_path}/tail/access_log_all/first_byte ]] | |
then | |
echo -n ', ' | |
echo -n "[\"\", {\"vtitle\": \"ms\", \"target\": [\"substr(scale(collectd.${_host}.tail.access_log_all.first_byte.{avg,min},0.001),5)\", \"substr(secondYAxis(scale(collectd.${_host}.tail.access_log_all.first_byte.max,0.001)),5)\"], \"title\": \"Apache_Access_All_First_Byte\"}, \"\"]" | |
fi | |
# Apache Access All Response | |
if [[ -d ${_host_path}/tail/access_log_all/response ]] | |
then | |
echo -n ', ' | |
echo -n "[\"\", {\"vtitle\": \"ms\", \"target\": [\"substr(scale(collectd.${_host}.tail.access_log_all.response.{avg,min},0.001),5)\", \"substr(secondYAxis(scale(collectd.${_host}.tail.access_log_all.response.max,0.001)),5)\"], \"title\": \"Apache_Access_All_Response\"}, \"\"]" | |
fi | |
# Apache Access All Status | |
if [[ -d ${_host_path}/tail/access_log_all/status ]] | |
then | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(sortByMaxima(maximumAbove(collectd.${_host}.tail.access_log_all.status.*,0.1)),5)\"], \"title\": \"Apache_Access_All_Status\"}, \"\"]" | |
fi | |
# NTP Offset | |
echo -n ', ' | |
echo -n "[\"\", {\"target\": [\"substr(limit(collectd.${_host}.ntpd.time_offset.[0-9]*,4),4)\"], \"title\": \"NTP_Offset\"}, \"\"]" | |
# Entropy | |
echo -n ', ' | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"vtitle\": \"bits\", \"target\": [\"substr(collectd.${_host}.entropy,2)\"], \"title\": \"Entropy\"}, \"\"]" | |
echo -n ', ' | |
# Users | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"target\": [\"substr(lineWidth(collectd.${_host}.users,2),2)\"], \"title\": \"Users\"}, \"\"]" | |
echo -n ', ' | |
# Uptime | |
echo -n "[\"\", {\"hideLegend\": \"true\", \"vtitle\": \"days\", \"target\": [\"substr(lineWidth(scale(collectd.${_host}.uptime,0.00001157),2),2)\"], \"title\": \"Uptime\"}, \"\"]" | |
# TCP Ports | |
for _tcp_dir in ${_host_path}/tcpconns/* | |
do | |
_port=${_tcp_dir##*/} | |
_name=${_port//-/_} | |
echo -n ', ' | |
echo -n "[\"\", {\"hideLegend\": \"false\", \"target\": [\"substr(sortByMaxima(maximumAbove(collectd.${_host}.tcpconns.${_port}.*,0.1)),4)\"], \"title\": \"TCP_${_name}\"}, \"\"]" | |
done | |
# end of sql statement | |
echo -n "], \"timeConfig\": {\"startDate\": \"${date}\", \"endDate\": \"${date}\", \"startTime\": \"8:00 AM\", \"units\": \"${units}\", \"endTime\": \"5:00 PM\", \"type\": \"relative\", \"quantity\": \"${quantity}\"}, \"graphSize\": {\"width\": \"${width}\", \"height\": \"${height}\"}}');" | |
unset _host _name | |
done > ${sqlfile} | |
# SQLite | |
sqlite3 ${db} < ${sqlfile} || echo " es: ${?}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script relies on metric name rewrites. See https://github.com/TimZehta/collectd-carbon/blob/examples/examples/carbon.rewrite-rules.conf