summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@aziz>2010-06-13 23:29:48 +0100
committerRichard Wall <richard@aziz>2010-06-13 23:29:48 +0100
commite896666f593a644f534c447d843d0cc730163190 (patch)
tree1ec23ec4706424de0cd223bd259c4b45be10f0cc
parent528caf8bdec86c43e10932249154da15cdc6d408 (diff)
Rename recipe parser function
-rw-r--r--index.html8
-rw-r--r--jrrd.js106
2 files changed, 58 insertions, 56 deletions
diff --git a/index.html b/index.html
index 966ed47..953499c 100644
--- a/index.html
+++ b/index.html
@@ -73,22 +73,22 @@
});
cc.charts = [].concat(
- jrrd.collectdChartFactory(
+ jrrd.Chart.fromRecipe(
rrdUrlList,
[].concat(
jrrd.COLLECTD_RECIPES.cpu,
jrrd.COLLECTD_RECIPES.memory,
jrrd.COLLECTD_RECIPES.load),
templateFactory('.system-charts')),
- jrrd.collectdChartFactory(
+ jrrd.Chart.fromRecipe(
rrdUrlList,
jrrd.COLLECTD_RECIPES.interface,
templateFactory('.network-charts')),
- jrrd.collectdChartFactory(
+ jrrd.Chart.fromRecipe(
rrdUrlList,
jrrd.COLLECTD_RECIPES.dns,
templateFactory('.dns-charts')),
- jrrd.collectdChartFactory(
+ jrrd.Chart.fromRecipe(
rrdUrlList,
application_recipes,
templateFactory('.application-charts'))
diff --git a/jrrd.js b/jrrd.js
index cab736f..a0a59e4 100644
--- a/jrrd.js
+++ b/jrrd.js
@@ -457,6 +457,59 @@ jrrd.Chart.prototype.draw = function() {
};
+jrrd.Chart.fromRecipe = function(rrdUrlList, recipes, templateFactory) {
+ /**
+ * 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 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.
+ **/
+ var rrdUrlBlob = rrdUrlList.join('\n')
+
+ var charts = [];
+ var dataDict = {};
+
+ var recipe, chartData, template, c, i, j, x, ds, label, rrd, unit, re, match;
+
+ for(i=0; i<recipes.length; i++) {
+ recipe = recipes[i];
+ chartData = [];
+
+ for(j=0; j<recipe['data'].length; j++) {
+ rrd = recipe['data'][j][0];
+ ds = recipe['data'][j][1];
+ label = recipe['data'][j][2];
+ unit = recipe['data'][j][3];
+ re = new RegExp('.*/' + rrd, 'gm');
+ match = rrdUrlBlob.match(re);
+ if(!match) {
+ continue;
+ }
+ for(x=0; x<match.length; x++) {
+
+ if(typeof dataDict[match[x]] == 'undefined') {
+ dataDict[match[x]] = new jrrd.RrdQueryRemote(match[x], unit);
+ }
+ chartData.push([label, new jrrd.RrdQueryDsProxy(dataDict[match[x]], ds)]);
+ }
+ }
+ if(chartData.length > 0) {
+ template = templateFactory();
+ template.find('.title').text(recipe['title']);
+ c = new jrrd.Chart(template.find('.chart'), recipe['options']);
+ for(j=0; j<chartData.length; j++) {
+ c.addData.apply(c, chartData[j]);
+ }
+ charts.push(c);
+ }
+ }
+ return charts;
+};
+
+
// Options common to all the chart on this page
jrrd.Chart.BASE_OPTIONS = {
grid: {
@@ -499,6 +552,7 @@ jrrd.Chart.STACKED_OPTIONS = {
}
};
+
jrrd.COLLECTD_RECIPES = {
'cpu': [
{
@@ -577,58 +631,6 @@ jrrd.COLLECTD_RECIPES = {
]
};
-jrrd.collectdChartFactory = function(rrdUrlList, recipes, templateFactory) {
- /**
- * 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 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.
- **/
- var rrdUrlBlob = rrdUrlList.join('\n')
-
- var charts = [];
- var dataDict = {};
-
- var recipe, chartData, template, c, i, j, x, ds, label, rrd, unit, re, match;
-
- for(i=0; i<recipes.length; i++) {
- recipe = recipes[i];
- chartData = [];
-
- for(j=0; j<recipe['data'].length; j++) {
- rrd = recipe['data'][j][0];
- ds = recipe['data'][j][1];
- label = recipe['data'][j][2];
- unit = recipe['data'][j][3];
- re = new RegExp('.*/' + rrd, 'gm');
- match = rrdUrlBlob.match(re);
- if(!match) {
- continue;
- }
- for(x=0; x<match.length; x++) {
-
- if(typeof dataDict[match[x]] == 'undefined') {
- dataDict[match[x]] = new jrrd.RrdQueryRemote(match[x], unit);
- }
- chartData.push([label, new jrrd.RrdQueryDsProxy(dataDict[match[x]], ds)]);
- }
- }
- if(chartData.length > 0) {
- template = templateFactory();
- template.find('.title').text(recipe['title']);
- c = new jrrd.Chart(template.find('.chart'), recipe['options']);
- for(j=0; j<chartData.length; j++) {
- c.addData.apply(c, chartData[j]);
- }
- charts.push(c);
- }
- }
- return charts;
-}
-
/**
* Presents the user with a form and a timeline with which they can choose a