Skip to content

Instantly share code, notes, and snippets.

@tairov
Last active December 19, 2015 13:59
Show Gist options
  • Save tairov/5966349 to your computer and use it in GitHub Desktop.
Save tairov/5966349 to your computer and use it in GitHub Desktop.
Chart load average
=======load_avg.sh=========
#! /bin/bash
#if [ 0 == 1 ]; then
HOSTS=('pm.mongo1' 'pm.mongo2' 'pm.mongo3' 'pm.mongo4')
out="[new Date(\"$(date +"%F %H:%M:%S")\")"
for host in ${HOSTS[@]}; do
load_avg=$(ssh -p 60222 user@$host "cat /proc/loadavg")
read avg1 avg5 avg15 _tmp <<< $load_avg
out="$out, $avg1, null"
done
out="$out],";
printf "$out\n" >> load_avg_data.txt
#fi
echo $out
# read content into a variable
avgdata=$(<load_avg_data.txt)
# добавляем слеши в конце строк, чтобы sed нормально смог совершить замену
esc_avgdata=$(echo "$avgdata"|awk '{printf("%s\\n", $0);}')
# подставляем данные в темплейт
sed -e "s/{ROWS_DATA}/$esc_avgdata/g" _template_graph.html > graph.html
cp graph.html "/home/path/Ubuntu One/Public/"
echo "file://"$(pwd)"/graph.html"
=======_template_graph.html===========
<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>LoadAvg pinme mongo servers</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['annotatedtimeline']});
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Date');
data.addColumn('number', 'pm.mongo1');
data.addColumn('string', 'title1');
data.addColumn('number', 'pm.mongo2');
data.addColumn('string', 'title2');
data.addColumn('number', 'pm.mongo3');
data.addColumn('string', 'title3');
data.addColumn('number', 'pm.mongo4');
data.addColumn('string', 'title4');
data.addRows([
{ROWS_DATA}
]);
var annotatedtimeline = new google.visualization.AnnotatedTimeLine(
document.getElementById('visualization'));
annotatedtimeline.draw(data, {'displayAnnotations': true});
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<a href="http://pm.mongo1:28017">pm.mongo1:28017</a>&nbsp;
<a href="http://pm.mongo2:28017">pm.mongo2:28017</a>&nbsp;
<a href="http://pm.mongo3:28017">pm.mongo3:28017</a>&nbsp;
<a href="http://pm.mongo4:28017">pm.mongo4:28017</a>&nbsp;
<div id="visualization" style="width: 1200px; height: 400px;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment