Commit 97b3dc1f authored by Ad Schellevis's avatar Ad Schellevis

(network insight) optimize api

parent aaf2cd1d
...@@ -70,13 +70,6 @@ class NetworkinsightController extends ApiControllerBase ...@@ -70,13 +70,6 @@ class NetworkinsightController extends ApiControllerBase
$resolution = $filter->sanitize($resolution, "int"); $resolution = $filter->sanitize($resolution, "int");
$field = $filter->sanitize($field, "string"); $field = $filter->sanitize($field, "string");
// map physical interfaces to description / name
$configObj = Config::getInstance()->object();
$allInterfaces = array();
foreach ($configObj->interfaces->children() as $key => $intf) {
$allInterfaces[(string)$intf->if] = empty($intf->descr) ? $key : (string)$intf->descr;
}
$result = array(); $result = array();
if ($this->request->isGet()) { if ($this->request->isGet()) {
$backend = new Backend(); $backend = new Backend();
...@@ -88,10 +81,10 @@ class NetworkinsightController extends ApiControllerBase ...@@ -88,10 +81,10 @@ class NetworkinsightController extends ApiControllerBase
if ($graph_data != null) { if ($graph_data != null) {
ksort($graph_data); ksort($graph_data);
$timeseries = array(); $timeseries = array();
foreach ($graph_data as $timeserie => $interfaces) { foreach ($graph_data as $timeserie => $timeserie_data) {
foreach ($interfaces as $interface => $payload) { foreach ($timeserie_data as $timeserie_key => $payload) {
if (!isset($timeseries[$interface])) { if (!isset($timeseries[$timeserie_key])) {
$timeseries[$interface] = array(); $timeseries[$timeserie_key] = array();
} }
// measure value // measure value
$measure_val = 0; $measure_val = 0;
...@@ -105,18 +98,29 @@ class NetworkinsightController extends ApiControllerBase ...@@ -105,18 +98,29 @@ class NetworkinsightController extends ApiControllerBase
$measure_val = $payload['packets'] / $payload['resolution']; $measure_val = $payload['packets'] / $payload['resolution'];
} }
// add to timeseries // add to timeseries
$timeseries[$interface][] = array((int)$timeserie*1000, $measure_val); $timeseries[$timeserie_key][] = array((int)$timeserie*1000, $measure_val);
} }
} }
foreach ($timeseries as $interface => $data) { foreach ($timeseries as $timeserie_key => $data) {
if (isset($allInterfaces[$interface])) { $result[] = array("key" => $timeserie_key, "values" => $data);
$result[] = array("key" => $allInterfaces[$interface], "values" => $data);
} else {
$result[] = array("key" => $interface, "values" => $data);
}
} }
} }
} }
return $result; return $result;
} }
/**
* return interface map (device / name)
* @return array interfaces
*/
public function getInterfacesAction()
{
// map physical interfaces to description / name
$configObj = Config::getInstance()->object();
$allInterfaces = array();
foreach ($configObj->interfaces->children() as $key => $intf) {
$allInterfaces[(string)$intf->if] = empty($intf->descr) ? $key : (string)$intf->descr;
}
return $allInterfaces;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment