<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- Example HTML/javascript file that display the content of a RRD archive file in a graph using the Flot libraries. This page adds two examples to RRDJFlot.html of using RRDFilterOp to apply operations (here, summing) to several or all of the DS in the RRD. Part of the javascriptRRD package Copyright (c) 2010 Frank Wuerthwein, fkw@ucsd.edu Igor Sfiligoi, isfiligoi@ucsd.edu Original repository: http://javascriptrrd.sourceforge.net/ MIT License [http://www.opensource.org/licenses/mit-license.php] --> <!-- This page requires Flot. Repository: http://www.flotcharts.org/ [Previous repository: http://code.google.com/p/flot/] --> <html> <script type="text/javascript" src="../lib/javascriptrrd.wlibs.js"></script> <!-- the above script replaces the rrdfFlotAsync,rrdFlot, rrdFlotSelection, rrdFile, rrdFilter, binaryXHR and all the jquery libraries --> <head> <title>RRD Graphs with Flot</title> </head> <body> <h1 id="title">RRD Graphs with Flot, with DS Filter Operations</h1> RRD URL: <input type="text" id="input_fname" value="example3.rrd" onchange="fname_update()"> <button onclick="fname_update()">Update</button> <hr> <table id="infotable" border=1> <tr><td colspan="21"><b>Javascript needed for this page to work</b></td></tr> <tr><td><b>RRD file</b></td><td id="fname" colspan="5">None</td></tr> </table> <div id="mygraph"></div> <script type="text/javascript"> // Remove the Javascript warning document.getElementById("infotable").deleteRow(0); //Sum two DSs function SumDS(ds1,ds2) { this.getName = function() {return ds1+"+"+ds2;} this.getDSNames = function() {return [ds1,ds2];} this.computeResult = function(val_list) {return val_list[0]+val_list[1];} } //Sums multiple DSs from a given list function MultiSumDS(list) { this.getName = function() {return "SumTotal";} this.getDSNames = function() { var i = 0; var name_list=[]; for(i=0;i<list.length;i++){ name_list.push(list[i].getName()); } return name_list;} this.computeResult = function(val_list) { var val_sum=0; var i=0; for(i=0;i<val_list.length;i++){ val_sum+=val_list[i]; } return val_sum; } } // this function is called after the data is loaded // but before the graph is displayed function mycallback(obj) { var op_list = []; //list of operations var DS_list = []; //list of DSs to sum in MultiSumDS var i = 0; //create a new rrdlist, which contains almost all original elements // plus additional operated-on DSs from RRDFilterOp for (i=0;i<obj.rrd_data.getNrDSs();i++) { if (i!=1) op_list.push(i); DS_list.push(obj.rrd_data.getDS(i)) } op_list.push(new MultiSumDS(DS_list)); op_list.push(new SumDS(obj.rrd_data.getDS(0).getName(),obj.rrd_data.getDS(1).getName())); //we just customized the DS shown by the graph obj.ds_op_list=op_list; } var graph_opts={legend: { noColumns:4}}; var ds_graph_opts={'Oscilator':{ color: "#ff8000", lines: { show: true, fill: true, fillColor:"#ffff80"} }, 'Idle':{ label: 'IdleJobs', color: "#00c0c0", lines: { show: true, fill: true} }, 'Running':{color: "#000000",yaxis:2}}; // we don't know what DSs we will get, so we have to use the callback // in principle, we could personalize ds_graph_opts in the callback as well, but we keep it simple here flot_obj=new rrdFlotAsync("mygraph",null,null,graph_opts,ds_graph_opts,null,null,null,mycallback); // this function is invoked when the RRD file name changes function fname_update() { var fname=document.getElementById("input_fname").value; flot_obj.reload(fname); document.getElementById("fname").firstChild.data=fname; } </script> </body> </html>