From a8605825a0af7d97c232a9135ba478954d0666e9 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Tue, 11 Aug 2015 20:02:03 +0100 Subject: [PATCH] Rollback, meant to send a PR --- consoles/node-overview.html | 3 ++- web/blob/static/js/prom_console.js | 36 ++++++++---------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/consoles/node-overview.html b/consoles/node-overview.html index 015da7b37c..0c981e28c1 100644 --- a/consoles/node-overview.html +++ b/consoles/node-overview.html @@ -108,7 +108,8 @@ "node_memory_MemTotal{job='node',instance='{{ .Params.instance }}'} - node_memory_MemFree{job='node',instance='{{.Params.instance}}'} - node_memory_Buffers{job='node',instance='{{.Params.instance}}'} - node_memory_Cached{job='node',instance='{{.Params.instance}}'}", "node_memory_MemFree{job='node',instance='{{ .Params.instance }}'}", ], - name: ["Cached", "Buffers", "Used", "Free"], + name: function(metric) { + return !metric.__name__ ? 'Used' : metric.__name__.split('_', 3)[2] }, min: 0, yUnits: "B", yAxisFormatter: PromConsole.NumberFormatter.humanize1024, diff --git a/web/blob/static/js/prom_console.js b/web/blob/static/js/prom_console.js index 70a076334a..22587ba2de 100644 --- a/web/blob/static/js/prom_console.js +++ b/web/blob/static/js/prom_console.js @@ -296,9 +296,6 @@ PromConsole.graphDefaults = { // If a string, it'll use that. [[ label ]] will be substituted. // If a function it'll be called with a map of keys to values, // and should return the name to use. - // Can be a list of strings/functions, each element - // will be applied to the pplots from the corresponding - // element of the expr list. xTitle: "Time", // The title of the x axis. yUnits: "", // The units of the y axis. yTitle: "", // The title of the y axis. @@ -315,14 +312,7 @@ PromConsole.Graph = function(params) { } } if (typeof params.expr == "string") { - params.expr = [params.expr]; - } - if (typeof params.name == "string" || typeof params.name == "function") { - var name = []; - for (var i = 0; i < params.expr.length; i++) { - name.push(params.name) - } - params.name = name; + params.expr = [params.expr] } this.params = params; @@ -419,23 +409,15 @@ PromConsole.Graph.prototype._render = function(data) { // This will be used on resize. this.rendered_data = data; - - var nameFuncs = []; + var nameFunc; if (this.params.name === null) { - var chooser = PromConsole._chooseNameFunction(data); - for (var i = 0; i < this.params.expr.length; i++) { - nameFuncs.push(chooser); - } + nameFunc = PromConsole._chooseNameFunction(data); + } else if (typeof this.params.name == "string") { + nameFunc = function(metric) { + return PromConsole._interpolateName(this.params.name, metric); + }.bind(this); } else { - for (var i = 0; i < this.params.name.length; i++) { - if (typeof this.params.name[i] == "string") { - nameFuncs.push(function(i, metric) { - return PromConsole._interpolateName(this.params.name[i], metric); - }.bind(this, i)); - } else { - nameFuncs.push(this.params.name[i]); - } - } + nameFunc = this.params.name; } // Get the data into the right format. @@ -445,7 +427,7 @@ PromConsole.Graph.prototype._render = function(data) { series[seriesLen++] = { data: data[e].value[i].values.map(function(s) {return {x: s[0], y: self._parseValue(s[1])} }), color: palette.color(), - name: self._escapeHTML(nameFuncs[e](data[e].value[i].metric)), + name: self._escapeHTML(nameFunc(data[e].value[i].metric)), }; } }