all graphs to db*

git-svn-id: http://www.observium.org/svn/observer/trunk@2309 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-05-13 13:27:54 +00:00
parent 38cd6d58cb
commit 952ae3b365
13 changed files with 32 additions and 65 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
$device = device_by_id_cache($id); $device = device_by_id_cache($id);
$query = mysql_query("SELECT * FROM `mempools` where `device_id` = '".$id."'");
include("includes/graphs/common.inc.php"); include("includes/graphs/common.inc.php");
@ -10,7 +9,7 @@ $rrd_options .= " -u 100 -l 0 -E -b 1024 ";
$iter = "1"; $i=1; $iter = "1"; $i=1;
$rrd_options .= " COMMENT:' Min Cur Max\\n'"; $rrd_options .= " COMMENT:' Min Cur Max\\n'";
while ($mempool = mysql_fetch_assoc($query)) foreach(dbFetchRows("SELECT * FROM `mempools` where `device_id` = ?", array($id)) as $mempool)
{ {
# FIXME generic colour function # FIXME generic colour function
if ($iter=="1") { $colour="CC0000"; } elseif ($iter=="2") { $colour="008C00"; } elseif ($iter=="3") { $colour="4096EE"; } if ($iter=="1") { $colour="CC0000"; } elseif ($iter=="2") { $colour="008C00"; } elseif ($iter=="3") { $colour="4096EE"; }

View File

@ -1,7 +1,7 @@
<?php <?php
$device = device_by_id_cache($id); $device = device_by_id_cache($id);
$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".$id."'"); $procs = dbFetchRows("SELECT * FROM `processors` where `device_id` = ?", array($id));
if($config['os'][$device['os']]['processor_stacked'] == 1) if($config['os'][$device['os']]['processor_stacked'] == 1)
{ {

View File

@ -1,13 +1,8 @@
<?php <?php
#$device = device_by_id_cache($id);
#$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".$id."'");
$i = 0; $i = 0;
while ($proc = mysql_fetch_assoc($query)) foreach ($procs as $proc)
{ {
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd"); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd");

View File

@ -1,11 +1,8 @@
<?php <?php
#$device = device_by_id_cache($id);
#$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".$id."'");
$i = 0; $i = 0;
while ($proc = mysql_fetch_assoc($query)) foreach ($procs as $proc)
{ {
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd"); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd");

View File

@ -7,9 +7,9 @@ if ($_GET['width'] > "300") { $descr_len = "40"; } else { $descr_len = "22"; }
$rrd_options .= " -l 0 -E "; $rrd_options .= " -l 0 -E ";
$iter = "1"; $iter = "1";
$sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='".$class."' AND device_id = '$id' ORDER BY sensor_index");
$rrd_options .= " COMMENT:'".str_pad($unit_long,$descr_len)." Cur Min Max\\n'"; $rrd_options .= " COMMENT:'".str_pad($unit_long,$descr_len)." Cur Min Max\\n'";
while ($sensor = mysql_fetch_assoc($sql))
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? ORDER BY `sensor_index`", array($class, $id)) as $sensor)
{ {
# FIXME generic colour function # FIXME generic colour function
switch ($iter) switch ($iter)

View File

@ -8,10 +8,9 @@ include("includes/graphs/common.inc.php");
$device = device_by_id_cache($id); $device = device_by_id_cache($id);
$iter = "1"; $iter = "1";
$sql = mysql_query("SELECT * FROM storage where device_id = '$id'");
$rrd_options .= " COMMENT:' Size Used %age\\l'"; $rrd_options .= " COMMENT:' Size Used %age\\l'";
while ($storage = mysql_fetch_assoc($sql)) foreach (dbFetchRows("SELECT * FROM storage where device_id = ?", array($id)) as $storage)
{ {
# FIXME generic colour function # FIXME generic colour function
if ($iter=="1") { $colour="CC0000"; } elseif ($iter=="2") { $colour="008C00"; } elseif ($iter=="3") { $colour="4096EE"; } if ($iter=="1") { $colour="CC0000"; } elseif ($iter=="2") { $colour="008C00"; } elseif ($iter=="3") { $colour="4096EE"; }

View File

@ -6,9 +6,8 @@ $device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E "; $rrd_options .= " -l 0 -E ";
$iter = "1"; $iter = "1";
$sql = mysql_query("SELECT * FROM toner where device_id = '$id'");
$rrd_options .= " COMMENT:'Toner level Cur Min Max\\n'"; $rrd_options .= " COMMENT:'Toner level Cur Min Max\\n'";
while ($toner = mysql_fetch_assoc($sql)) foreach (dbFetchRows("SELECT * FROM toner where device_id = ?", array($id)) as $toner)
{ {
# FIXME generic colour function # FIXME generic colour function
switch ($iter) switch ($iter)

View File

@ -1,16 +1,5 @@
<?php <?php
if ($_GET['id']) { $id = $_GET['id']; }
$query = mysql_query("SELECT * FROM `ucd_diskio` AS U, `devices` AS D WHERE U.diskio_id = '".$id."' AND U.device_id = D.device_id");
$disk = mysql_fetch_assoc($query);
if (is_file($config['rrd_dir'] . "/" . $disk['hostname'] . "/ucd_diskio-" . safename($disk['diskio_descr'] . ".rrd")))
{
$rrd_filename = $config['rrd_dir'] . "/" . $disk['hostname'] . "/ucd_diskio-" . safename($disk['diskio_descr'] . ".rrd");
}
$rra_in = "reads"; $rra_in = "reads";
$rra_out = "writes"; $rra_out = "writes";

View File

@ -10,8 +10,7 @@ foreach (explode(",", $id) as $ifid)
$ifid = str_replace("!", "", $ifid); $ifid = str_replace("!", "", $ifid);
} }
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = '" . $ifid . "' AND I.device_id = D.device_id"); $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$int = mysql_fetch_row($query);
if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . safename($int[0] . ".rrd"))) if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . safename($int[0] . ".rrd")))
{ {
$rrd_filenames[$i] = $config['rrd_dir'] . "/" . $int[1] . "/port-" . safename($int[0] . ".rrd"); $rrd_filenames[$i] = $config['rrd_dir'] . "/" . $int[1] . "/port-" . safename($int[0] . ".rrd");

View File

@ -9,8 +9,7 @@ $i = 1;
foreach (explode(",", $_GET['id']) as $ifid) foreach (explode(",", $_GET['id']) as $ifid)
{ {
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = '" . mres($ifid) . "' AND I.device_id = D.device_id"); $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$int = mysql_fetch_row($query);
if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd")) if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd"))
{ {
$rrd_options .= " DEF:inoctets" . $i . "=" . $config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd:INOCTETS:AVERAGE"; $rrd_options .= " DEF:inoctets" . $i . "=" . $config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd:INOCTETS:AVERAGE";
@ -27,8 +26,7 @@ unset($seperator); unset($plus);
foreach (explode(",", $_GET['idb']) as $ifid) foreach (explode(",", $_GET['idb']) as $ifid)
{ {
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = '" . mres($ifid) . "' AND I.device_id = D.device_id"); $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$int = mysql_fetch_row($query);
if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd")) if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd"))
{ {
$rrd_options .= " DEF:inoctetsb" . $i . "=" . $config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd:INOCTETS:AVERAGE"; $rrd_options .= " DEF:inoctetsb" . $i . "=" . $config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd:INOCTETS:AVERAGE";

View File

@ -4,8 +4,7 @@ $i = 0;
foreach (explode(",", $id) as $ifid) foreach (explode(",", $id) as $ifid)
{ {
$query = mysql_query("SELECT * FROM `ports` AS I, devices as D WHERE I.interface_id = '" . mres($ifid) . "' AND I.device_id = D.device_id"); $port = dbFetchRow("SELECT * FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$port = mysql_fetch_assoc($query);
if (is_file($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"))) if (is_file($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd")))
{ {
$rrd_list[$i]['filename'] = $config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"); $rrd_list[$i]['filename'] = $config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd");

View File

@ -10,8 +10,7 @@ $i = 1;
foreach (explode(",", $_GET['id']) as $ifid) foreach (explode(",", $_GET['id']) as $ifid)
{ {
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = '" . mres($ifid) . "' AND I.device_id = D.device_id"); $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$int = mysql_fetch_row($query);
if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd")) if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd"))
{ {
if (strstr($inverse, "a")) { $in = "OUT"; $out = "IN"; } else { $in = "IN"; $out = "OUT"; } if (strstr($inverse, "a")) { $in = "OUT"; $out = "IN"; } else { $in = "IN"; $out = "OUT"; }
@ -30,8 +29,7 @@ unset($seperator); unset($plus);
foreach (explode(",", $_GET['idb']) as $ifid) foreach (explode(",", $_GET['idb']) as $ifid)
{ {
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = '" . mres($ifid) . "' AND I.device_id = D.device_id"); $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$int = mysql_fetch_row($query);
if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd")) if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd"))
{ {
if (strstr($inverse, "b")) { $in = "OUT"; $out = "IN"; } else { $in = "IN"; $out = "OUT"; } if (strstr($inverse, "b")) { $in = "OUT"; $out = "IN"; } else { $in = "IN"; $out = "OUT"; }
@ -50,8 +48,7 @@ unset($seperator); unset($plus);
foreach (explode(",", $_GET['idc']) as $ifid) foreach (explode(",", $_GET['idc']) as $ifid)
{ {
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = '" . mres($ifid) . "' AND I.device_id = D.device_id"); $int = dbFetchRow("SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.interface_id = ? AND I.device_id = D.device_id", array($ifid));
$int = mysql_fetch_row($query);
if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd")) if (is_file($config['rrd_dir'] . "/" . $int[1] . "/port-" . $int[0] . ".rrd"))
{ {
if (strstr($inverse, "c")) { $in = "OUT"; $out = "IN"; } else { $in = "IN"; $out = "OUT"; } if (strstr($inverse, "c")) { $in = "OUT"; $out = "IN"; } else { $in = "IN"; $out = "OUT"; }

View File

@ -34,40 +34,36 @@ if ($stat == "pkts")
} }
} }
$sql = "SELECT *, (M.cipMacHCSwitchedBytes_input_rate + M.cipMacHCSwitchedBytes_output_rate) AS bps, $accs = dbFetchRows("SELECT *, (M.cipMacHCSwitchedBytes_input_rate + M.cipMacHCSwitchedBytes_output_rate) AS bps,
(M.cipMacHCSwitchedPkts_input_rate + M.cipMacHCSwitchedPkts_output_rate) AS pps (M.cipMacHCSwitchedPkts_input_rate + M.cipMacHCSwitchedPkts_output_rate) AS pps
FROM `mac_accounting` AS M, `ports` AS I, `devices` AS D WHERE M.interface_id = '".$port."' FROM `mac_accounting` AS M, `ports` AS I, `devices` AS D WHERE M.interface_id = ?
AND I.interface_id = M.interface_id AND D.device_id = I.device_id ORDER BY $sort DESC LIMIT 0," . $topn; AND I.interface_id = M.interface_id AND D.device_id = I.device_id ORDER BY $sort DESC LIMIT 0," . $topn, array($port));
$query = mysql_query($sql);
$pluses = ""; $iter = '0'; $pluses = ""; $iter = '0';
$rrd_options .= " COMMENT:' In\: Current Maximum Total Out\: Current Maximum Total\\\\n'"; $rrd_options .= " COMMENT:' In\: Current Maximum Total Out\: Current Maximum Total\\\\n'";
while ($acc = mysql_fetch_assoc($query)) foreach ($accs as $acc)
{ {
$this_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); $this_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd");
if (is_file($this_rrd)) if (is_file($this_rrd))
{ {
$mac = formatmac($acc['mac']); $mac = formatmac($acc['mac']);
$name = $mac; $name = $mac;
$addy = mysql_fetch_assoc(mysql_query("SELECT * FROM ipv4_mac where mac_address = '".$acc['mac']."' AND interface_id = '".$acc['interface_id']."'")); $addy = dbFetchRow("SELECT * FROM ipv4_mac where mac_address = ? AND interface_id = ?", array($acc['mac'], $acc['interface_id']));
if ($addy) if ($addy)
{ {
$name = $addy['ipv4_address'] . " (".$mac.")"; $name = $addy['ipv4_address'] . " (".$mac.")";
$peer = mysql_fetch_assoc(mysql_query("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D $peer = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D
WHERE A.ipv4_address = '".$addy['ipv4_address']."' WHERE A.ipv4_address = ? AND I.interface_id = A.interface_id AND D.device_id = I.device_id", array($addy['ipv4_address']));
AND I.interface_id = A.interface_id AND D.device_id = I.device_id"));
if ($peer) if ($peer)
{ {
$name = $peer['hostname'] . " " . makeshortif($peer['ifDescr']) . " (".$mac.")"; $name = $peer['hostname'] . " " . makeshortif($peer['ifDescr']) . " (".$mac.")";
} }
if (mysql_result(mysql_query("SELECT count(*) FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = '". if (dbFetchCell("SELECT count(*) FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = ?", array($addy['ipv4_address'])),0))
$addy['ipv4_address']."'"),0))
{ {
$peer_query = mysql_query("SELECT * FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = '".$addy['ipv4_address']."'"); $peer_info = dbFetchRow("SELECT * FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($acc['device_id'], $addy['ipv4_address']));
$peer_info = mysql_fetch_assoc($peer_query);
$name .= " - AS".$peer_info['bgpPeerRemoteAs']; $name .= " - AS".$peer_info['bgpPeerRemoteAs'];
} }