From cbaeb0b773cc6401943250edcdac82c6a9a71ca8 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 13 Jun 2010 12:37:50 +0100 Subject: Build charts based on a downloaded list of available rrd files --- index.html | 91 +++++++++++++++++++++++++++++++++++++++------------------- jrrd.js | 63 ++++++++++++++++++++++++++++------------ rrd_finder.rpy | 20 +++++++++++++ 3 files changed, 126 insertions(+), 48 deletions(-) create mode 100644 rrd_finder.rpy diff --git a/index.html b/index.html index 8329f41..7e60c00 100644 --- a/index.html +++ b/index.html @@ -134,15 +134,34 @@ // Recipes for the charts on this page var recipes = [ + + { + title: 'Twisted Web TCP Stats', + data: [ + ['tcpconns-8080-local/tcp_connections-CLOSE_WAIT.rrd', 0, 'CLOSE_WAIT', ''], + ['tcpconns-8080-local/tcp_connections-SYN_RECV.rrd', 0, 'SYN_RECV', ''], + ['tcpconns-8080-local/tcp_connections-TIME_WAIT.rrd', 0, 'TIME_WAIT', ''], + ['tcpconns-8080-local/tcp_connections-CLOSED.rrd', 0, 'CLOSED', ''], + ['tcpconns-8080-local/tcp_connections-FIN_WAIT2.rrd', 0, 'FIN_WAIT2', ''], + ['tcpconns-8080-local/tcp_connections-FIN_WAIT1.rrd', 0, 'FIN_WAIT1', ''], + ['tcpconns-8080-local/tcp_connections-ESTABLISHED.rrd', 0, 'ESTABLISHED', ''], + ['tcpconns-8080-local/tcp_connections-LAST_ACK.rrd', 0, 'LAST_ACK', ''], + ['tcpconns-8080-local/tcp_connections-LISTEN.rrd', 0, 'LISTEN', ''], + ['tcpconns-8080-local/tcp_connections-SYN_SENT.rrd', 0, 'SYN_SENT', ''], + ['tcpconns-8080-local/tcp_connections-CLOSING.rrd', 0, 'CLOSING', ''] + ], + options: jQuery.extend(true, {}, baseOptions, stacked) + }, + { title: 'CPU Usage', data: [ - ['data/cpu-0/cpu-wait.rrd', 0, 'CPU-0 Wait', 'Jiffies'], - ['data/cpu-1/cpu-wait.rrd', 0, 'CPU-1 Wait', 'Jiffies'], - ['data/cpu-0/cpu-system.rrd', 0, 'CPU-0 System', 'Jiffies'], - ['data/cpu-1/cpu-system.rrd', 0, 'CPU-1 System', 'Jiffies'], - ['data/cpu-0/cpu-user.rrd', 0, 'CPU-0 User', 'Jiffies'], - ['data/cpu-1/cpu-user.rrd', 0, 'CPU-1 User', 'Jiffies'] + ['cpu-0/cpu-wait.rrd', 0, 'CPU-0 Wait', 'Jiffies'], + ['cpu-1/cpu-wait.rrd', 0, 'CPU-1 Wait', 'Jiffies'], + ['cpu-0/cpu-system.rrd', 0, 'CPU-0 System', 'Jiffies'], + ['cpu-1/cpu-system.rrd', 0, 'CPU-1 System', 'Jiffies'], + ['cpu-0/cpu-user.rrd', 0, 'CPU-0 User', 'Jiffies'], + ['cpu-1/cpu-user.rrd', 0, 'CPU-1 User', 'Jiffies'] ], options: jQuery.extend(true, {}, baseOptions, stacked) }, @@ -150,10 +169,10 @@ { title: 'Memory', data: [ - ['data/memory/memory-buffered.rrd', 0, 'Buffered', 'B'], - ['data/memory/memory-used.rrd', 0, 'Used', 'B'], - ['data/memory/memory-cached.rrd', 0, 'Cached', 'B'], - ['data/memory/memory-free.rrd', 0, 'Free', 'B'] + ['memory/memory-buffered.rrd', 0, 'Buffered', 'B'], + ['memory/memory-used.rrd', 0, 'Used', 'B'], + ['memory/memory-cached.rrd', 0, 'Cached', 'B'], + ['memory/memory-free.rrd', 0, 'Free', 'B'] ], options: jQuery.extend(true, {}, baseOptions, stacked) }, @@ -161,10 +180,10 @@ { title: 'DNS Query Types', data: [ - ['data/dns/dns_qtype-A.rrd', 0, 'A', 'Q/sec'], - ['data/dns/dns_qtype-PTR.rrd', 0, 'PTR', 'Q/sec'], - ['data/dns/dns_qtype-SOA.rrd', 0, 'SOA', 'Q/sec'], - ['data/dns/dns_qtype-SRV.rrd', 0, 'SRV', 'Q/sec'] + ['dns/dns_qtype-A.rrd', 0, 'A', 'Q/sec'], + ['dns/dns_qtype-PTR.rrd', 0, 'PTR', 'Q/sec'], + ['dns/dns_qtype-SOA.rrd', 0, 'SOA', 'Q/sec'], + ['dns/dns_qtype-SRV.rrd', 0, 'SRV', 'Q/sec'] ], options: jQuery.extend(true, {}, baseOptions) }, @@ -172,9 +191,9 @@ { title: 'DNS Return Codes', data: [ - ['data/dns/dns_rcode-NOERROR.rrd', 0, 'NOERROR', 'Q/sec'], - ['data/dns/dns_rcode-NXDOMAIN.rrd', 0, 'NXDOMAIN', 'Q/sec'], - ['data/dns/dns_rcode-SERVFAIL.rrd', 0, 'SERVFAIL', 'Q/sec'] + ['dns/dns_rcode-NOERROR.rrd', 0, 'NOERROR', 'Q/sec'], + ['dns/dns_rcode-NXDOMAIN.rrd', 0, 'NXDOMAIN', 'Q/sec'], + ['dns/dns_rcode-SERVFAIL.rrd', 0, 'SERVFAIL', 'Q/sec'] ], options: jQuery.extend(true, {}, baseOptions) }, @@ -182,9 +201,9 @@ { title: 'Load Average', data: [ - ['data/load/load.rrd', 'shortterm', 'Short Term', ''], - ['data/load/load.rrd', 'midterm', 'Medium Term', ''], - ['data/load/load.rrd', 'longterm', 'Long Term', ''] + ['load/load.rrd', 'shortterm', 'Short Term', ''], + ['load/load.rrd', 'midterm', 'Medium Term', ''], + ['load/load.rrd', 'longterm', 'Long Term', ''] ], options: jQuery.extend(true, {}, baseOptions) }, @@ -192,29 +211,37 @@ { title: 'Wlan0 Throughput', data: [ - ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'b/sec'], - ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'b/sec'] + ['interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'b/sec'], + ['interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'b/sec'] ], options: jQuery.extend(true, {}, baseOptions) - }, + } ]; - $(function() { + function initialiseCharts(rrdUrlList) { + /** + * Setup chart date range controls and all charts + **/ + + // Add dhtml calendars to the date input fields $(":date").dateinput({format: 'mmm dd yyyy', max: +1}); - // when first date input is changed $(":date[name=startTime]").data("dateinput").change(function() { $(":date[name=endTime]").data("dateinput").setMin(this.getValue(), true); }); $(":date[name=endTime]").data("dateinput").change(function() { $(":date[name=startTime]").data("dateinput").setMax(this.getValue(), true); }); + + // Extract the chart template from the page var chartTemplate = $('.chart-container').remove(); var cc = new jrrd.ChartCoordinator($('.chartRangeControl')); - cc.charts = jQuery.map(recipes, function(recipe, i) { - return jrrd.Chart.fromRecipe( - chartTemplate.clone().appendTo('.charts'), recipe); - }); + cc.charts = jrrd.collectdChartFactory( + rrdUrlList, recipes, function() { + // The chart template must be appended to the page early, so + // that flot can calculate chart dimensions etc. + return chartTemplate.clone().appendTo('.charts'); + }); // Update all charts when a selection is made on one of them $('.charts').bind("plotselected", function(event, ranges) { @@ -233,6 +260,12 @@ // Initialise all the charts cc.reset(); + } + + $(function() { + // Download a list of available rrd files and use it to generate + // any viable chart recipes + $.getJSON('rrd_finder.rpy', initialiseCharts); }); diff --git a/jrrd.js b/jrrd.js index 85f5ebc..f4c3665 100644 --- a/jrrd.js +++ b/jrrd.js @@ -457,31 +457,56 @@ jrrd.Chart.prototype.draw = function() { }; -jrrd.Chart.fromRecipe = function(template, recipe) { +jrrd.collectdChartFactory = function(rrdUrlList, recipes, templateFactory) { /** - * A factory function to generate a I{Chart} from a recipe + * A factory function to generate a list of I{Chart} from a list of recipes + * and a list of available rrd files in collectd path format. * - * @param template: A I{jQuery} containing the element in which the chart is - * drawn. - * @param A recipe I{Object} eg - * {title: '', data: [rrdUrl, rrdDs, label, unit], options: {}} - * @return: A I{Chart} instance + * @param rrdUrlList: A list of rrd download paths + * @param recipes: A list of recipe objects + * @param templateFactory: A callable which generates an html template for a + * chart. **/ - template.find('.title').text(recipe['title']); - var c = new jrrd.Chart(template.find('.chart'), recipe['options']); + var rrdUrlBlob = rrdUrlList.join('\n') + + var charts = []; var dataDict = {}; - var ds, label, rrd, unit; - for(var i=0; i 0) { + template = templateFactory(); + template.find('.title').text(recipe['title']); + c = new jrrd.Chart(template.find('.chart'), recipe['options']); + for(j=0; j