mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fixes to billing. add realtime graphs for port bits.
git-svn-id: http://www.observium.org/svn/observer/trunk@2424 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@ -1,13 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ($_GET['debug'])
|
ini_set('allow_url_fopen', 0);
|
||||||
|
ini_set('display_errors', 0);
|
||||||
|
|
||||||
|
if (strpos($_SERVER['REQUEST_URI'], "debug"))
|
||||||
{
|
{
|
||||||
|
$debug = "1";
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
ini_set('log_errors', 1);
|
||||||
|
ini_set('error_reporting', E_ALL);
|
||||||
|
} else {
|
||||||
|
$debug = FALSE;
|
||||||
|
ini_set('display_errors', 0);
|
||||||
ini_set('display_startup_errors', 0);
|
ini_set('display_startup_errors', 0);
|
||||||
ini_set('log_errors', 0);
|
ini_set('log_errors', 0);
|
||||||
ini_set('allow_url_fopen', 0);
|
ini_set('error_reporting', 0);
|
||||||
ini_set('error_reporting', E_ALL);
|
}
|
||||||
} else { ini_set('display_errors', 0); }
|
|
||||||
|
|
||||||
include("../includes/defaults.inc.php");
|
include("../includes/defaults.inc.php");
|
||||||
include("../config.php");
|
include("../config.php");
|
||||||
@ -47,17 +56,21 @@ $dur = $end - $start;
|
|||||||
|
|
||||||
if ($type == "date") { $date_format = "%d %b %H:%i"; $tickinterval = "2"; } else { $date_format = "%H"; $tickinterval = "1"; }
|
if ($type == "date") { $date_format = "%d %b %H:%i"; $tickinterval = "2"; } else { $date_format = "%H"; $tickinterval = "1"; }
|
||||||
|
|
||||||
$datefrom = date('Ymt', $start) . "000000";
|
$datefrom = date('Ymthis', $start);
|
||||||
$dateto = date('Ymt', $end) . "235959";
|
$dateto = date('Ymthis', $end);
|
||||||
|
|
||||||
$datefrom = dbFetchCell("SELECT FROM_UNIXTIME($start, '%Y%m%d')") . "000000";
|
#echo("$start || $end || ");
|
||||||
$dateto = dbFetchCell("SELECT FROM_UNIXTIME($end, '%Y%m%d')") . "235959";
|
|
||||||
|
#echo("$datefrom || $dateto");
|
||||||
|
|
||||||
|
#$datefrom = dbFetchCell("SELECT FROM_UNIXTIME($start, '%Y%m%d')") . "000000";
|
||||||
|
#$dateto = dbFetchCell("SELECT FROM_UNIXTIME($end, '%Y%m%d')") . "235959";
|
||||||
|
|
||||||
$rate_data = getRates($bill_id,$datefrom,$dateto);
|
$rate_data = getRates($bill_id,$datefrom,$dateto);
|
||||||
$rate_95th = $rate_data['rate_95th'] * 1000;
|
$rate_95th = $rate_data['rate_95th'] * 1000;
|
||||||
$rate_average = $rate_data['rate_average'] * 1000;
|
$rate_average = $rate_data['rate_average'] * 1000;
|
||||||
|
|
||||||
$bi_a = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id)");
|
$bi_a = dbFetchRow("SELECT * FROM bills WHERE bill_id = ?", array($bill_id));
|
||||||
$bill_name = $bi_a['bill_name'];
|
$bill_name = $bi_a['bill_name'];
|
||||||
|
|
||||||
$counttot = dbFetchCell("SELECT count(`delta`) FROM `bill_data` WHERE `bill_id` = ? AND `timestamp` >= ? AND `timestamp` <= ?", array($bill_id, $datefrom, $dateto));
|
$counttot = dbFetchCell("SELECT count(`delta`) FROM `bill_data` WHERE `bill_id` = ? AND `timestamp` >= ? AND `timestamp` <= ?", array($bill_id, $datefrom, $dateto));
|
||||||
@ -150,6 +163,9 @@ foreach (dbFetch("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bil
|
|||||||
#print_r($ticks);
|
#print_r($ticks);
|
||||||
#print_r($tot_data);
|
#print_r($tot_data);
|
||||||
|
|
||||||
|
#echo("<pre>");
|
||||||
|
#print_r($in_data);
|
||||||
|
|
||||||
$graph_name = date('M j g:ia', $start) . " - " . date('M j g:ia', $last);
|
$graph_name = date('M j g:ia', $start) . " - " . date('M j g:ia', $last);
|
||||||
|
|
||||||
$n = count($ticks);
|
$n = count($ticks);
|
||||||
|
38
html/data.php
Normal file
38
html/data.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
# $debug = TRUE;
|
||||||
|
# ini_set('display_errors', 1);
|
||||||
|
# ini_set('display_startup_errors', 0);
|
||||||
|
# ini_set('log_errors', 0);
|
||||||
|
# ini_set('error_reporting', E_ALL);
|
||||||
|
|
||||||
|
|
||||||
|
include_once("../includes/defaults.inc.php");
|
||||||
|
include_once("../config.php");
|
||||||
|
include_once("../includes/common.php");
|
||||||
|
include_once("../includes/dbFacile.php");
|
||||||
|
include_once("../includes/rewrites.php");
|
||||||
|
include_once("includes/functions.inc.php");
|
||||||
|
include_once("includes/authenticate.inc.php");
|
||||||
|
|
||||||
|
include_once("../includes/snmp.inc.php");
|
||||||
|
|
||||||
|
if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id'])))
|
||||||
|
{
|
||||||
|
$port = get_port_by_id($_GET['id']);
|
||||||
|
$device = device_by_id_cache($port['device_id']);
|
||||||
|
$title = generate_device_link($device);
|
||||||
|
$title .= " :: Port ".generate_port_link($port);
|
||||||
|
$auth = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$in = snmp_get($device, "ifInOctets.".$port['ifIndex'], "-OUqnv", "IF-MIB");
|
||||||
|
$out = snmp_get($device, "ifOutOctets.".$port['ifIndex'], "-OUqnv", "IF-MIB");
|
||||||
|
|
||||||
|
$time = time();
|
||||||
|
|
||||||
|
printf("%lf|%u|%u\n", time(), $in, $out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
354
html/graph-realtime.php
Executable file
354
html/graph-realtime.php
Executable file
@ -0,0 +1,354 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
part of m0n0wall (http://m0n0.ch/wall)
|
||||||
|
|
||||||
|
Copyright (C) 2004-2006 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
|
||||||
|
and Jonathan Watt <jwatt@jwatt.org>.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
header("Content-type: image/svg+xml");
|
||||||
|
|
||||||
|
/********** HTTP GET Based Conf ***********/
|
||||||
|
$ifnum=@$_GET["ifnum"]; // BSD / SNMP interface name / number
|
||||||
|
$ifname=@$_GET["ifname"]?$_GET["ifname"]:"Interface $ifnum"; //Interface name that will be showed on top right of graph
|
||||||
|
|
||||||
|
/********* Other conf *******/
|
||||||
|
$scale_type="follow"; //Autoscale default setup : "up" = only increase scale; "follow" = increase and decrease scale according to current graphed datas
|
||||||
|
$nb_plot=240; //NB plot in graph
|
||||||
|
if(is_numeric($_GET['interval'])) {
|
||||||
|
$time_interval=$_GET['interval'];
|
||||||
|
} else {
|
||||||
|
$time_interval=1; //Refresh time Interval
|
||||||
|
}
|
||||||
|
$fetch_link = "data.php?id=".$_GET[id];
|
||||||
|
|
||||||
|
//SVG attributes
|
||||||
|
$attribs['axis']='fill="black" stroke="black"';
|
||||||
|
$attribs['in']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
|
||||||
|
$attribs['out']='fill="#8092B3" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
|
||||||
|
$attribs['graph_in']='fill="none" stroke="green" stroke-opacity="0.8"';
|
||||||
|
$attribs['graph_out']='fill="none" stroke="blue" stroke-opacity="0.8"';
|
||||||
|
$attribs['legend']='fill="black" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
|
||||||
|
$attribs['graphname']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="8"';
|
||||||
|
$attribs['grid_txt']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"';
|
||||||
|
$attribs['grid']='stroke="gray" stroke-opacity="0.5"';
|
||||||
|
$attribs['switch_unit']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
|
||||||
|
$attribs['switch_scale']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
|
||||||
|
$attribs['error']='fill="blue" font-family="Arial" font-size="4"';
|
||||||
|
$attribs['collect_initial']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
|
||||||
|
|
||||||
|
//Error text if we cannot fetch data : depends on which method is used
|
||||||
|
$error_text = "Cannot get data about interface $ifnum";
|
||||||
|
|
||||||
|
$height=100; //SVG internal height : do not modify
|
||||||
|
$width=200; //SVG internal width : do not modify
|
||||||
|
|
||||||
|
/********* Graph DATA **************/
|
||||||
|
print('<?xml version="1.0" encoding="iso-8859-1"?>' . "\n");?>
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 <?=$width?> <?=$height?>" preserveAspectRatio="none" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onload="init(evt)">
|
||||||
|
<g id="graph">
|
||||||
|
<rect id="bg" x1="0" y1="0" width="100%" height="100%" fill="white"/>
|
||||||
|
<line id="axis_x" x1="0" y1="0" x2="0" y2="100%" <?=$attribs['axis']?>/>
|
||||||
|
<line id="axis_y" x1="0" y1="100%" x2="100%" y2="100%" <?=$attribs['axis']?>/>
|
||||||
|
<path id="graph_out" d="M0 <?=$height?> L 0 <?=$height?>" <?=$attribs['graph_out']?>/>
|
||||||
|
<path id="graph_in" d="M0 <?=$height?> L 0 <?=$height?>" <?=$attribs['graph_in']?>/>
|
||||||
|
<path id="grid" d="M0 <?=$height/4*1?> L <?=$width?> <?=$height/4*1?> M0 <?=$height/4*2?> L <?=$width?> <?=$height/4*2?> M0 <?=$height/4*3?> L <?=$width?> <?=$height/4*3?>" <?=$attribs['grid']?>/>
|
||||||
|
<text id="grid_txt1" x="<?=$width?>" y="<?=$height/4*1?>" <?=$attribs['grid_txt']?> text-anchor="end"> </text>
|
||||||
|
<text id="grid_txt2" x="<?=$width?>" y="<?=$height/4*2?>" <?=$attribs['grid_txt']?> text-anchor="end"> </text>
|
||||||
|
<text id="grid_txt3" x="<?=$width?>" y="<?=$height/4*3?>" <?=$attribs['grid_txt']?> text-anchor="end"> </text>
|
||||||
|
<text id="graph_in_lbl" x="5" y="8" <?=$attribs['in']?>>In</text>
|
||||||
|
<text id="graph_out_lbl" x="5" y="16" <?=$attribs['out']?>>Out</text>
|
||||||
|
<text id="graph_in_txt" x="20" y="8" <?=$attribs['in']?>> </text>
|
||||||
|
<text id="graph_out_txt" x="20" y="16" <?=$attribs['out']?>> </text>
|
||||||
|
<text id="ifname" x="<?=$width?>" y="8" <?=$attribs['graphname']?> text-anchor="end"><?=$ifname?></text>
|
||||||
|
<text id="switch_unit" x="<?=$width*0.55?>" y="5" <?=$attribs['switch_unit']?>>Switch to bytes/s</text>
|
||||||
|
<text id="switch_scale" x="<?=$width*0.55?>" y="11" <?=$attribs['switch_scale']?>>AutoScale (<?=$scale_type?>)</text>
|
||||||
|
<text id="datetime" x="<?=$width*0.33?>" y="5" <?=$attribs['legend']?>> </text>
|
||||||
|
<text id="graphlast" x="<?=$width*0.55?>" y="17" <?=$attribs['legend']?>>Graph shows last <?=$time_interval*$nb_plot?> seconds</text>
|
||||||
|
<polygon id="axis_arrow_x" <?=$attribs['axis']?> points="<?=($width) . "," . ($height)?> <?=($width-2) . "," . ($height-2)?> <?=($width-2) . "," . $height?>"/>
|
||||||
|
<text id="error" x="<?=$width*0.5?>" y="<?=$height*0.5?>" visibility="hidden" <?=$attribs['error']?> text-anchor="middle"><?=$error_text?></text>
|
||||||
|
<text id="collect_initial" x="<?=$width*0.5?>" y="<?=$height*0.5?>" visibility="hidden" <?=$attribs['collect_initial']?> text-anchor="middle">Collecting initial data, please wait...</text>
|
||||||
|
</g>
|
||||||
|
<script type="text/ecmascript">
|
||||||
|
<![CDATA[
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getURL is a proprietary Adobe function, but it's simplicity has made it very
|
||||||
|
* popular. If getURL is undefined we spin our own by wrapping XMLHttpRequest.
|
||||||
|
*/
|
||||||
|
if (typeof getURL == 'undefined') {
|
||||||
|
getURL = function(url, callback) {
|
||||||
|
if (!url)
|
||||||
|
throw 'No URL for getURL';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (typeof callback.operationComplete == 'function')
|
||||||
|
callback = callback.operationComplete;
|
||||||
|
} catch (e) {}
|
||||||
|
if (typeof callback != 'function')
|
||||||
|
throw 'No callback function for getURL';
|
||||||
|
|
||||||
|
var http_request = null;
|
||||||
|
if (typeof XMLHttpRequest != 'undefined') {
|
||||||
|
http_request = new XMLHttpRequest();
|
||||||
|
}
|
||||||
|
else if (typeof ActiveXObject != 'undefined'){
|
||||||
|
try {
|
||||||
|
http_request = new ActiveXObject('Msxml2.XMLHTTP');
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
http_request = new ActiveXObject('Microsoft.XMLHTTP');
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!http_request)
|
||||||
|
throw 'Both getURL and XMLHttpRequest are undefined';
|
||||||
|
|
||||||
|
http_request.onreadystatechange = function() {
|
||||||
|
if (http_request.readyState == 4) {
|
||||||
|
callback( { success : true,
|
||||||
|
content : http_request.responseText,
|
||||||
|
contentType : http_request.getResponseHeader("Content-Type") } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http_request.open('GET', url, true);
|
||||||
|
http_request.send(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var SVGDoc = null;
|
||||||
|
var last_ifin = 0;
|
||||||
|
var last_ifout = 0;
|
||||||
|
var last_ugmt = 0;
|
||||||
|
var max = 0;
|
||||||
|
var plot_in = new Array();
|
||||||
|
var plot_out = new Array();
|
||||||
|
|
||||||
|
var max_num_points = <?=$nb_plot?>; // maximum number of plot data points
|
||||||
|
var step = <?=$width?> / max_num_points ;
|
||||||
|
var unit = 'bits';
|
||||||
|
var scale_type = '<?=$scale_type?>';
|
||||||
|
|
||||||
|
function init(evt) {
|
||||||
|
SVGDoc = evt.target.ownerDocument;
|
||||||
|
SVGDoc.getElementById("switch_unit").addEventListener("mousedown", switch_unit, false);
|
||||||
|
SVGDoc.getElementById("switch_scale").addEventListener("mousedown", switch_scale, false);
|
||||||
|
|
||||||
|
fetch_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
function switch_unit(event)
|
||||||
|
{
|
||||||
|
SVGDoc.getElementById('switch_unit').firstChild.data = 'Switch to ' + unit + '/s';
|
||||||
|
unit = (unit == 'bits') ? 'bytes' : 'bits';
|
||||||
|
}
|
||||||
|
|
||||||
|
function switch_scale(event)
|
||||||
|
{
|
||||||
|
scale_type = (scale_type == 'up') ? 'follow' : 'up';
|
||||||
|
SVGDoc.getElementById('switch_scale').firstChild.data = 'AutoScale (' + scale_type + ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetch_data() {
|
||||||
|
getURL('<?=$fetch_link?>', plot_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function plot_data(obj) {
|
||||||
|
// Show datetimelegend
|
||||||
|
var now = new Date();
|
||||||
|
var datetime = (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear() + ' ' +
|
||||||
|
LZ(now.getHours()) + ":" + LZ(now.getMinutes()) + ":" + LZ(now.getSeconds());
|
||||||
|
SVGDoc.getElementById('datetime').firstChild.data = datetime;
|
||||||
|
|
||||||
|
if (!obj.success)
|
||||||
|
return handle_error(); // getURL failed to get data
|
||||||
|
|
||||||
|
var t = obj.content.split("|");
|
||||||
|
var ugmt = parseFloat(t[0]); // ugmt is an unixtimestamp style
|
||||||
|
var ifin = parseInt(t[1]); // number of bytes received by the interface
|
||||||
|
var ifout = parseInt(t[2]); // number of bytes sent by the interface
|
||||||
|
var scale;
|
||||||
|
|
||||||
|
if (!isNumber(ifin) || !isNumber(ifout))
|
||||||
|
return handle_error();
|
||||||
|
|
||||||
|
var diff_ugmt = ugmt - last_ugmt;
|
||||||
|
var diff_ifin = ifin - last_ifin;
|
||||||
|
var diff_ifout = ifout - last_ifout;
|
||||||
|
|
||||||
|
if (diff_ugmt == 0)
|
||||||
|
diff_ugmt = 1; /* avoid division by zero */
|
||||||
|
|
||||||
|
last_ugmt = ugmt;
|
||||||
|
last_ifin = ifin;
|
||||||
|
last_ifout = ifout;
|
||||||
|
|
||||||
|
switch (plot_in.length) {
|
||||||
|
case 0:
|
||||||
|
SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'visible');
|
||||||
|
plot_in[0] = diff_ifin / diff_ugmt;
|
||||||
|
plot_out[0] = diff_ifout / diff_ugmt;
|
||||||
|
setTimeout('fetch_data()',<?=1000*$time_interval?>);
|
||||||
|
return;
|
||||||
|
case 1:
|
||||||
|
SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'hidden');
|
||||||
|
break;
|
||||||
|
case max_num_points:
|
||||||
|
// shift plot to left if the maximum number of plot points has been reached
|
||||||
|
var i = 0;
|
||||||
|
while (i < max_num_points) {
|
||||||
|
plot_in[i] = plot_in[i+1];
|
||||||
|
plot_out[i] = plot_out[++i];
|
||||||
|
}
|
||||||
|
plot_in.length--;
|
||||||
|
plot_out.length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
plot_in[plot_in.length] = diff_ifin / diff_ugmt;
|
||||||
|
plot_out[plot_out.length]= diff_ifout / diff_ugmt;
|
||||||
|
var index_plot = plot_in.length - 1;
|
||||||
|
|
||||||
|
SVGDoc.getElementById('graph_in_txt').firstChild.data = formatSpeed(plot_in[index_plot], unit);
|
||||||
|
SVGDoc.getElementById('graph_out_txt').firstChild.data = formatSpeed(plot_out[index_plot], unit);
|
||||||
|
|
||||||
|
/* determine peak for sensible scaling */
|
||||||
|
if (scale_type == 'up') {
|
||||||
|
if (plot_in[index_plot] > max)
|
||||||
|
max = plot_in[index_plot];
|
||||||
|
if (plot_out[index_plot] > max)
|
||||||
|
max = plot_out[index_plot];
|
||||||
|
}
|
||||||
|
else if (scale_type == 'follow') {
|
||||||
|
i = 0;
|
||||||
|
max = 0;
|
||||||
|
while (i < plot_in.length) {
|
||||||
|
if (plot_in[i] > max)
|
||||||
|
max = plot_in[i];
|
||||||
|
if (plot_out[i] > max)
|
||||||
|
max = plot_out[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var rmax; // max, rounded up
|
||||||
|
|
||||||
|
if (unit == 'bits') {
|
||||||
|
/* round up max, such that
|
||||||
|
100 kbps -> 200 kbps -> 400 kbps -> 800 kbps -> 1 Mbps -> 2 Mbps -> ... */
|
||||||
|
rmax = 12500;
|
||||||
|
i = 0;
|
||||||
|
while (max > rmax) {
|
||||||
|
i++;
|
||||||
|
if (i && (i % 4 == 0))
|
||||||
|
rmax *= 1.25;
|
||||||
|
else
|
||||||
|
rmax *= 2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* round up max, such that
|
||||||
|
10 KB/s -> 20 KB/s -> 40 KB/s -> 80 KB/s -> 100 KB/s -> 200 KB/s -> 400 KB/s -> 800 KB/s -> 1 MB/s ... */
|
||||||
|
rmax = 10240;
|
||||||
|
i = 0;
|
||||||
|
while (max > rmax) {
|
||||||
|
i++;
|
||||||
|
if (i && (i % 4 == 0))
|
||||||
|
rmax *= 1.25;
|
||||||
|
else
|
||||||
|
rmax *= 2;
|
||||||
|
|
||||||
|
if (i == 8)
|
||||||
|
rmax *= 1.024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scale = <?=$height?> / rmax;
|
||||||
|
|
||||||
|
/* change labels accordingly */
|
||||||
|
SVGDoc.getElementById('grid_txt1').firstChild.data = formatSpeed(3*rmax/4,unit);
|
||||||
|
SVGDoc.getElementById('grid_txt2').firstChild.data = formatSpeed(2*rmax/4,unit);
|
||||||
|
SVGDoc.getElementById('grid_txt3').firstChild.data = formatSpeed(rmax/4,unit);
|
||||||
|
|
||||||
|
var path_in = "M 0 " + (<?=$height?> - (plot_in[0] * scale));
|
||||||
|
var path_out = "M 0 " + (<?=$height?> - (plot_out[0] * scale));
|
||||||
|
for (i = 1; i < plot_in.length; i++)
|
||||||
|
{
|
||||||
|
var x = step * i;
|
||||||
|
var y_in = <?=$height?> - (plot_in[i] * scale);
|
||||||
|
var y_out = <?=$height?> - (plot_out[i] * scale);
|
||||||
|
path_in += " L" + x + " " + y_in;
|
||||||
|
path_out += " L" + x + " " + y_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
SVGDoc.getElementById('error').setAttributeNS(null, 'visibility', 'hidden');
|
||||||
|
SVGDoc.getElementById('graph_in').setAttributeNS(null, 'd', path_in);
|
||||||
|
SVGDoc.getElementById('graph_out').setAttributeNS(null, 'd', path_out);
|
||||||
|
|
||||||
|
setTimeout('fetch_data()',<?=1000*$time_interval?>);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_error() {
|
||||||
|
SVGDoc.getElementById("error").setAttributeNS(null, 'visibility', 'visible');
|
||||||
|
setTimeout('fetch_data()',<?=1000*$time_interval?>);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isNumber(a) {
|
||||||
|
return typeof a == 'number' && isFinite(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSpeed(speed, unit) {
|
||||||
|
if (unit == 'bits')
|
||||||
|
return formatSpeedBits(speed);
|
||||||
|
if (unit == 'bytes')
|
||||||
|
return formatSpeedBytes(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSpeedBits(speed) {
|
||||||
|
// format speed in bits/sec, input: bytes/sec
|
||||||
|
if (speed < 125000)
|
||||||
|
return Math.round(speed / 125) + " Kbps";
|
||||||
|
if (speed < 125000000)
|
||||||
|
return Math.round(speed / 1250)/100 + " Mbps";
|
||||||
|
// else
|
||||||
|
return Math.round(speed / 1250000)/100 + " Gbps"; /* wow! */
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSpeedBytes(speed) {
|
||||||
|
// format speed in bytes/sec, input: bytes/sec
|
||||||
|
if (speed < 1048576)
|
||||||
|
return Math.round(speed / 10.24)/100 + " KB/s";
|
||||||
|
if (speed < 1073741824)
|
||||||
|
return Math.round(speed / 10485.76)/100 + " MB/s";
|
||||||
|
// else
|
||||||
|
return Math.round(speed / 10737418.24)/100 + " GB/s"; /* wow! */
|
||||||
|
}
|
||||||
|
|
||||||
|
function LZ(x) {
|
||||||
|
return (x < 0 || x > 9 ? "" : "0") + x;
|
||||||
|
}
|
||||||
|
|
||||||
|
]]>
|
||||||
|
</script>
|
||||||
|
</svg>
|
@ -194,9 +194,11 @@ if (bill_permitted($bill_id))
|
|||||||
$li .= "&width=715&height=200&total=1'>";
|
$li .= "&width=715&height=200&total=1'>";
|
||||||
|
|
||||||
|
|
||||||
# $di = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
$di = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
|
||||||
# $di = $di . "&from=" . $yesterday . "&to=" . $rightnow . "&x=715&y=250";
|
$di = $di . "&from=" . $unix_prev_from . "&to=" . $unix_prev_to . "&x=715&y=250";
|
||||||
# $di = $di . "$type'>";
|
$di = $di . "$type'>";
|
||||||
|
|
||||||
|
echo("$di");
|
||||||
|
|
||||||
$di = "<img src='graph.php?type=bill_bits&id=" . $bill_id;
|
$di = "<img src='graph.php?type=bill_bits&id=" . $bill_id;
|
||||||
$di .= "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'];
|
$di .= "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'];
|
||||||
|
@ -55,6 +55,12 @@ if ($_GET['optb'] == "graphs" || !$_GET['optb']) { echo("<span class='pagemenu-s
|
|||||||
echo("<a href='".$config['base_url']."/device/" . $device['device_id'] . "/port/".$interface['interface_id']."/'>Graphs</a>");
|
echo("<a href='".$config['base_url']."/device/" . $device['device_id'] . "/port/".$interface['interface_id']."/'>Graphs</a>");
|
||||||
if ($_GET['optb'] == "graphs" || !$_GET['optb']) { echo("</span>"); }
|
if ($_GET['optb'] == "graphs" || !$_GET['optb']) { echo("</span>"); }
|
||||||
|
|
||||||
|
echo(" | ");
|
||||||
|
|
||||||
|
if ($_GET['optb'] == "realtime" || !$_GET['optb']) { echo("<span class='pagemenu-selected'>"); }
|
||||||
|
echo("<a href='".$config['base_url']."/device/" . $device['device_id'] . "/port/".$interface['interface_id']."/realtime/'>Real Time</a>");
|
||||||
|
if ($_GET['optb'] == "realtime" || !$_GET['optb']) { echo("</span>"); }
|
||||||
|
|
||||||
|
|
||||||
if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `interface_id` = '".$interface['interface_id']."'") )
|
if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `interface_id` = '".$interface['interface_id']."'") )
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,6 @@ function only_alphanumeric($string)
|
|||||||
function logfile($string)
|
function logfile($string)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$fd = fopen($config['log_file'],'a');
|
$fd = fopen($config['log_file'],'a');
|
||||||
fputs($fd,$string . "\n");
|
fputs($fd,$string . "\n");
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
|
@ -20,65 +20,53 @@ function CollectData($bill_id)
|
|||||||
{
|
{
|
||||||
foreach (dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.interface_id = P.port_id AND D.device_id = I.device_id", array($bill_id)) as $port_data)
|
foreach (dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.interface_id = P.port_id AND D.device_id = I.device_id", array($bill_id)) as $port_data)
|
||||||
{
|
{
|
||||||
unset($port_in_measurement);
|
|
||||||
unset($port_in_delta);
|
|
||||||
unset($last_port_in_measurement);
|
|
||||||
unset($last_port_in_delta);
|
|
||||||
unset($port_out_measurement);
|
|
||||||
unset($port_out_delta);
|
|
||||||
unset($last_port_out_measurement);
|
|
||||||
unset($last_port_out_delta);
|
|
||||||
|
|
||||||
$port_id = $port_data['port_id'];
|
$port_id = $port_data['port_id'];
|
||||||
$host = $port_data['hostname'];
|
$host = $port_data['hostname'];
|
||||||
$port = $port_data['port'];
|
$port = $port_data['port'];
|
||||||
|
|
||||||
echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n");
|
echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n");
|
||||||
|
|
||||||
$port_in_measurement = getValue($host, $port, $port_data['ifIndex'], "In");
|
$port_data['in_measurement'] = getValue($host, $port, $port_data['ifIndex'], "In");
|
||||||
$port_out_measurement = getValue($host, $port, $port_data['ifIndex'], "Out");
|
$port_data['out_measurement'] = getValue($host, $port, $port_data['ifIndex'], "Out");
|
||||||
|
|
||||||
$now = dbFetchCell("SELECT NOW()");
|
$now = dbFetchCell("SELECT NOW()");
|
||||||
|
|
||||||
$last_data = getLastPortCounter($port_id,in);
|
$last_data = getLastPortCounter($port_id,in);
|
||||||
if ($last_data[state] == "ok")
|
if ($last_data[state] == "ok")
|
||||||
{
|
{
|
||||||
$last_port_in_measurement = $last_data[counter];
|
$port_data['last_in_measurement'] = $last_data[counter];
|
||||||
$last_port_in_delta = $last_data[delta];
|
$port_data['last_in_delta'] = $last_data[delta];
|
||||||
if ($port_in_measurement > $last_port_in_measurement)
|
if ($port_data['in_measurement'] > $port_data['last_in_measurement'])
|
||||||
{
|
{
|
||||||
$port_in_delta = $port_in_measurement - $last_port_in_measurement;
|
$port_data['in_delta'] = $port_data['in_measurement'] - $port_data['last_in_measurement'];
|
||||||
} else {
|
} else {
|
||||||
$port_in_delta = $last_port_in_delta;
|
$port_data['in_delta'] = $port_data['last_in_delta'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$port_in_delta = '0';
|
$port_data['in_delta'] = '0';
|
||||||
}
|
}
|
||||||
dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_in_measurement, 'delta' => $port_in_delta), 'port_in_measurements');
|
dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['in_measurement'], 'delta' => $port_data['in_delta']), 'port_in_measurements');
|
||||||
|
|
||||||
unset($last_data, $last_port_in_measurement, $last_port_in_delta);
|
|
||||||
|
|
||||||
$last_data = getLastPortCounter($port_id,out);
|
$last_data = getLastPortCounter($port_id,out);
|
||||||
if ($last_data[state] == "ok")
|
if ($last_data[state] == "ok")
|
||||||
{
|
{
|
||||||
$last_port_out_measurement = $last_data[counter];
|
$port_data['last_out_measurement'] = $last_data[counter];
|
||||||
$last_port_out_delta = $last_data[delta];
|
$port_data['last_out_delta'] = $last_data[delta];
|
||||||
if ($port_out_measurement > $last_port_out_measurement)
|
if ($port_data['out_measurement'] > $port_data['last_out_measurement'])
|
||||||
{
|
{
|
||||||
$port_out_delta = $port_out_measurement - $last_port_out_measurement;
|
$port_data['out_delta'] = $port_data['out_measurement'] - $port_data['last_out_measurement'];
|
||||||
} else {
|
} else {
|
||||||
$port_out_delta = $last_port_out_delta;
|
$port_data['out_delta'] = $port_data['last_out_delta'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$port_out_delta = '0';
|
$port_data['out_delta'] = '0';
|
||||||
}
|
}
|
||||||
dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_out_measurement, 'delta' => $port_out_delta), 'port_out_measurements');
|
dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['out_measurement'], 'delta' => $port_data['out_delta']), 'port_out_measurements');
|
||||||
unset($last_data, $last_port_in_measurement, $last_port_in_delta);
|
|
||||||
|
|
||||||
$delta = $delta + $port_in_delta + $port_out_delta;
|
$delta = $delta + $port_data['in_delta'] + $port_data['out_delta'];
|
||||||
$in_delta = $in_delta + $port_in_delta;
|
$in_delta = $in_delta + $port_data['in_delta'];
|
||||||
$out_delta = $out_delta + $port_out_delta;
|
$out_delta = $out_delta + $port_data['out_delta'];
|
||||||
unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$last_data = getLastMeasurement($bill_id);
|
$last_data = getLastMeasurement($bill_id);
|
||||||
@ -104,7 +92,12 @@ function CollectData($bill_id)
|
|||||||
$out_delta = $prev_out_delta;
|
$out_delta = $prev_out_delta;
|
||||||
|
|
||||||
}
|
}
|
||||||
dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data');
|
|
||||||
|
if($period < "0") {
|
||||||
|
logfile("BILLING: negative period! id:$bill_id period:$period delta:$delta in_delta:$in_delta out_delta:$out_delta");
|
||||||
|
} else {
|
||||||
|
dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($argv[1]) { CollectData($argv[1]); }
|
if ($argv[1]) { CollectData($argv[1]); }
|
||||||
|
Reference in New Issue
Block a user