Skip to content

Instantly share code, notes, and snippets.

@sinky
Last active May 25, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinky/dc6299491495ca86a9864fc5175aec56 to your computer and use it in GitHub Desktop.
Save sinky/dc6299491495ca86a9864fc5175aec56 to your computer and use it in GitHub Desktop.
RRD to Highchart with rrdtool xport
<!doctype html>
<html lang="de-DE">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>RRD to Highchart</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highcharts/6.0.7/css/highcharts.css" />
<style></style>
</head>
<body>
<div id="chart"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/6.0.7/highcharts.js"></script>
<script>
$(function(){
var options = {
chart: {
renderTo: 'chart',
type: 'line'
},
title: {
text: "Temperatures"
},
xAxis: {
type: 'datetime',
title: {
text: 'Date'
}
},
};
$.ajax({
type: "GET",
url: "temp.xml",
dataType: "xml",
success: function(xml) {
if(typeof options.series != "object") {
options.series = [];
}
$(xml).find("entry").each(function() {
var seriesOptions = {
name: $(this).text(),
data: []
};
options.series.push(seriesOptions);
});
$(xml).find("row").each(function() {
var t = parseInt($(this).find("t").text()) *1000
$(this).find("v").each(function(index) {
var v = parseFloat($(this).text())
console.log(t,v)
v = v || null
if (v != null) {
options.series[index].data.push([t, v])
};
});
});
chart = new Highcharts.Chart(options);
}
})
});
</script>
</body>
</html>
rrdtool xport \
DEF:Line1=DB1.rrd:1:AVERAGE XPORT:Line1:Legende1 \
DEF:Line2=DB2.rrd:1:AVERAGE XPORT:Line2:Legende2 \
--start -2years > /temp.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment