diff --git a/opentrafficshaper/plugins/statistics/statistics.pm b/opentrafficshaper/plugins/statistics/statistics.pm index 20da5e171559e313c7507b2758c2785ca667984f..edbbba4184f28c9c8e1fd9be852f8d461ca39e61 100644 --- a/opentrafficshaper/plugins/statistics/statistics.pm +++ b/opentrafficshaper/plugins/statistics/statistics.pm @@ -276,7 +276,7 @@ sub plugin_init my $now = time(); foreach my $key (keys %{$statsConfig}) { # Get aligned time so we cleanup sooner - $lastCleanup->{$key} = _getAlignedTime($now); + $lastCleanup->{$key} = _getAlignedTime($now,$statsConfig->{$key}->{'precision'}); } $lastConfigManagerStats = $now; } @@ -779,18 +779,18 @@ sub getConfigManagerCounters # Grab user count my %counters; - $counters{"ConfigManager:TotalUsers"} = @limits; + $counters{"ConfigManager:TotalLimits"} = @limits; # Start off with 0's foreach my $cid (keys %{$classes}) { - $counters{"ConfigManager:ClassUsers:$cid"} = 0; + $counters{"ConfigManager:ClassLimits:$cid"} = 0; } # Generate ClassID counts foreach my $lid (@limits) { my $limit = getLimit($lid); my $cid = $limit->{'ClassID'}; # Bump the class counter - $counters{"ConfigManager:ClassUsers:$cid"}++; + $counters{"ConfigManager:ClassLimits:$cid"}++; } return \%counters; @@ -847,7 +847,7 @@ sub _getConfigManagerStats # Loop through counters and create stats items foreach my $item (%{$counters}) { - my $identifierID = getSIDFromCounter($item); + my $identifierID = setSIDFromCounter($item); my $stat = { 'identifierid' => $identifierID, 'timestamp' => $now, diff --git a/opentrafficshaper/plugins/webserver/pages/static/awit-flot/functions.js b/opentrafficshaper/plugins/webserver/pages/static/awit-flot/functions.js new file mode 100644 index 0000000000000000000000000000000000000000..8a4ab880679543183a3ad6fad8e3aac453bef2df --- /dev/null +++ b/opentrafficshaper/plugins/webserver/pages/static/awit-flot/functions.js @@ -0,0 +1,167 @@ +/* + * Functions used for FLOT charts + * Copyright (c) 2013, AllWorldIT + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * + */ + + +// Function to format thousands with , and add Kbps +function awit_flot_format_bandwidth(value, axis) { + return awit_flot_format_thousands(value,axis) + ' Kbps'; +} + + +// Function to format thousands +function awit_flot_format_thousands(value, axis) { + // Convert number to string + value = value.toString(); + // Match on 3 digits + var R = new RegExp('(-?[0-9]+)([0-9]{3})'); + while(R.test(value)) { + // Replace market with , + value = value.replace(R, '$1,$2'); + } + + return value; +} + + +// Function draw a graph +function awit_flot_draw_graph(options) { + + // Setting up the graph here + var baseOptions = { + + series: { + lines: { + show: true, + lineWidth: 1, + fill: true, + fillColor: { + colors: [ + { opacity: 0.1 }, + { opacity: 0.13 } + ] + } + }, + + points: { + show: false, + lineWidth: 2, + radius: 3 + }, + + shadowSize: 0, + stack: true + }, + + grid: { + hoverable: true, + clickable: false, + tickColor: "#f9f9f9", + borderWidth: 1 + }, + + legend: { + labelBoxBorderColor: "#aaa" + }, + + xaxes: [ + { + mode: "time", + + tickSize: [60, "second"], + + tickFormatter: function (v, axis) { + var date = new Date(v); + + if (date.getSeconds() % 5 == 0) { + var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); + var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); + var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); + + return hours + ":" + minutes + ":" + seconds; + } else { + return ""; + } + } + } + ], + + yaxes: [ + { + min: 0, + tickFormatter: awit_flot_format_bandwidth + } + ] + } + + // Add additional yaxes if needed + if (options && options.yaxes && options.yaxes.length) { + for (k = 0; k < options.yaxes.length; k++) { + if (options.yaxes[k]) { + baseOptions.yaxes.push(options.yaxes[k]); + } + } + } + + // Load data from ajax + jQuery.ajax({ + url: options.url, + dataType: 'json', + + success: function(statsData) { + plot = null; + + for (i = 0; (i < statsData.length); i++) { + // Format time to match javascript's epoch in milliseconds + for (j = 0; j < statsData[i].data.length; j++) { + d = new Date(statsData[i].data[j][0] * 1000); + statsData[i].data[j][0] = statsData[i].data[j][0] * 1000; + } + // Loop with yaxes + for (k = 0; k < baseOptions.yaxes.length; k++) { + // Check if there are labels + if (baseOptions.yaxes[k].labels && baseOptions.yaxes[k].labels.length) { + // Loop through labels + for (l = 0; l < baseOptions.yaxes[k].labels.length; l++) { + // Check for match + if (statsData[i].label == baseOptions.yaxes[k].labels[l]) { + statsData[i].yaxis = k + 1; + } + } + } + } + } + + if (statsData.length > 0) { + plot = jQuery.plot(jQuery("#flotCanvas"), statsData, baseOptions); + } + } + }); +} + + +// vim: ts=4