Exemplo n.º 1
0
 /**
  * getUsageData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData($logfile)
 {
     $class = __CLASS__;
     $settings = LoadPlugins::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($logfile, $contents);
     //echo '<pre> :: '; var_dump ($contents); echo '</pre>';
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     $chartData = array();
     //delimiter is based on logger type used to explode data
     $delimiter = LoadUtility::getDelimiter();
     $delimiter = "|";
     //takes the log file and parses it into chartable data
     //echo '<pre> :: <br>';
     if ($logStatus) {
         //$this->getChartData ($chartArray, $contents,  false );
         $totalContents = (int) count($contents);
         for ($i = 0; $i < $totalContents; ++$i) {
             //grab the first dataset
             $data = explode($delimiter, $contents[$i]);
             //echo $data[0] . " " . $data[1] . " " . $data[2] . "<br>";
             $chartData[$i] = $data;
         }
     }
     return $chartData;
 }
Exemplo n.º 2
0
 /**
  * getData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @param string $switch with switch data to populate return array
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData($switch)
 {
     $class = __CLASS__;
     $settings = LoadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //display switch used to switch between view modes - data or percentage
     //switches between fixed and fitted view modes
     $displayMode = $settings['settings']['display_limiting'];
     //define datasets
     $dataArrayLabel[0] = 'Hash';
     $dataArrayLabel[1] = 'Low Hash';
     $dataArrayLabel[2] = 'High Hash';
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             // clean data for missing values
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //used to filter out redline data from usage data as it skews it
             if (!$redline) {
                 $usage[$switch][] = $data[$switch];
             }
             //time data
             $timedata = (int) $data[0];
             $time[$switch][$data[$switch]] = date("H:ia", $timedata);
             //chart arrays
             $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", '" . $data[$switch] . "']";
             if ($data[$switch] <= $settings['settings']['overload_1'] && $settings['settings']['overload_1'] != -1) {
                 $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", '" . $data[$switch] . "']";
             }
             if ($data[$switch] >= $settings['settings']['overload_2'] && $settings['settings']['overload_2'] != -1) {
                 $dataArray[2][$data[0]] = "[" . $data[0] * 1000 . ", '" . $data[$switch] . "']";
             }
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $cpu_high = max($usage[$switch]);
         $cpu_high_time = $time[$switch][$cpu_high];
         $cpu_low = min($usage[$switch]);
         $cpu_low_time = $time[$switch][$cpu_low];
         $cpu_mean = array_sum($usage[$switch]) / count($usage[$switch]);
         $cpu_latest = $usage[$switch][count($usage[$switch]) - 1];
         if ($displayMode == 'true') {
             $ymin = $cpu_low;
             $ymax = $settings['settings']['display_cutoff'];
         } else {
             //give high and low a 5% buffer for charts
             if ($cpu_low == 0) {
                 $ymin = 0;
             } else {
                 $ymin = $cpu_low * (95 / 100);
             }
             if ($cpu_high == 0) {
                 $ymax = 0;
             } else {
                 $ymax = $cpu_high * (105 / 100);
             }
         }
         $variables = array('cpu_high' => number_format((double) $cpu_high, 3), 'cpu_high_time' => $cpu_high_time, 'cpu_low' => number_format($cpu_low, 3), 'cpu_low_time' => $cpu_low_time, 'cpu_mean' => number_format($cpu_mean, 3), 'cpu_latest' => number_format($cpu_latest, 3));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         //parse, clean and sort dataArray to necesary depth
         $depth = 3;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $cpu_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 /**
  * getApacheUsageData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData()
 {
     $class = __CLASS__;
     $settings = loadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //define datasets
     $dataArrayLabel[0] = 'CPU Usage';
     $dataArrayLabel[1] = 'Overload';
     //display switch used to switch between view modes - data or percentage
     // true - show MB
     // false - show percentage
     $displayMode = $settings['settings']['display_limiting'];
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             // clean data for missing values
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //used to filter out redline data from usage data as it skews it
             //usage is used to calculate view perspectives
             if (!$redline) {
                 $usage[] = $data[1];
             }
             $timedata = (int) $data[0];
             $time[$data[1]] = date("H:ia", $timedata);
             //////// remove long here to fix bug
             $usageCount[] = $data[0] * 1000;
             $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] . "]";
             if ((double) $data[1] > $settings['settings']['overload']) {
                 $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] . "]";
             }
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $apache_high = max($usage);
         $apache_low = min($usage);
         $apache_mean = array_sum($usage) / count($usage);
         //to scale charts
         $ymax = $apache_high;
         $ymin = $apache_low;
         $apache_high_time = $time[max($usage)];
         $apache_low_time = $time[min($usage)];
         $apache_latest = $usage[count($usage) - 1];
         $variables = array('apache_high' => number_format($apache_high, 4), 'apache_high_time' => $apache_high_time, 'apache_low' => number_format($apache_low, 4), 'apache_low_time' => $apache_low_time, 'apache_mean' => number_format($apache_mean, 4), 'apache_latest' => number_format($apache_latest, 4));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 2;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $apache_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 /**
  * getUsageData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData()
 {
     $class = __CLASS__;
     $settings = LoadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //display switch used to switch between view modes - data or percentage
     // true - show MB
     // false - show percentage
     $displayMode = $settings['settings']['display_limiting'];
     //define datasets
     $dataArrayLabel[0] = 'Uptime';
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     //takes the log file and parses it into chartable data
     if ($logStatus) {
         $this->getChartData($chartArray, $contents, false);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         //get the size of the disk we are charting - need to calculate percentages
         //$diskSize = $this->getDiskSize($chartArray, $sizeofChartArray);
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             //we skip all redline data for this module
             $redline = false;
             //usage is used to calculate view perspectives
             //check for when first data is 0 here
             if (!$redline) {
                 $usage[] = $data[1] / 86400;
             }
             $timedata = (int) $data[0];
             $time[$data[1] / 86400] = date("H:ia", $timedata);
             $usageCount[] = $data[0] * 1000;
             // display data using MB
             $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] / 86400 . "]";
         }
         //echo '<pre>PRESETTINGS</pre>';
         //echo '<pre>';var_dump($usage);echo'</pre>';
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $uptime_high = max($usage);
         $uptime_low = min($usage);
         $uptime_mean = array_sum($usage) / count($usage);
         //to scale charts
         $ymax = $uptime_high;
         $ymin = $uptime_low;
         $uptime_high_time = $time[max($usage)];
         $uptime_low_time = $time[min($usage)];
         $uptime_latest = $usage[count($usage) - 1];
         $variables = array('uptime_high' => number_format($uptime_high, 4), 'uptime_high_time' => $uptime_high_time, 'uptime_low' => number_format($uptime_low, 4), 'uptime_low_time' => $uptime_low_time, 'uptime_mean' => number_format($uptime_mean, 4), 'uptime_latest' => number_format($uptime_latest, 4));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 2;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $uptime_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel, 'overload' => $settings['settings']['overload']);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 5
0
 /**
  * getData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @param string $switch with switch data to populate return array
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData($switch = 1)
 {
     $class = __CLASS__;
     $settings = loadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //display switch used to switch between view modes - data or percentage
     $displayMode = $settings['settings']['display_limiting'];
     //define datasets
     $dataArrayLabel[0] = $this->getChartLabel($switch);
     $dataArrayLabel[1] = 'Failed';
     $dataArrayLabel[2] = 'Invalid User';
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             // clean data for missing values
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //used to filter out redline data from usage data as it skews it
             if (!$redline) {
                 $usage[1][] = $data[1];
                 $usage[2][] = $data[2];
                 $usage[3][] = $data[3];
             }
             $timedata = (int) $data[0];
             $time[$data[1]] = date("H:ia", $timedata);
             $usageCount[] = $data[0] * 1000;
             //dirty hack here as we arent using switch across the board
             //rather using switch mode 1 as a default
             if ($displayMode == "true") {
                 // display data accepted
                 $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[$switch] . "]";
             } else {
                 // display data accepted
                 $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] . "]";
                 // display data failed
                 $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[2] . "]";
                 // display data invalid user
                 $dataArray[2][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[3] . "]";
             }
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $ssh_accept = array_sum($usage[1]);
         $ssh_failed = array_sum($usage[2]);
         $ssh_invalid = array_sum($usage[3]);
         //set zoom based on all data or some data
         if ($displayMode == "true") {
             $ssh_high = max($usage[$switch]);
         } else {
             $ssh_high = max(max($usage[1]), max($usage[2]), max($usage[3]));
         }
         //really needs to be max across data 1, data 2 and data 3
         $ymax = $ssh_high;
         $ymin = 0;
         //need to really clean up this module!
         //as when no attemtps to access ssh logs time still has data ?
         //we can only do this if there is more than 1 in usage array?
         if (count($time) > 1) {
             $ssh_latest_login = $time[$usage[1][count($usage) - 1]];
         } else {
             if (isset($usage[1][1]) && isset($time[$usage[1][1]])) {
                 $ssh_latest_login = $time[$usage[1][1]];
             } else {
                 $ssh_latest_login = 0;
             }
         }
         $variables = array('ssh_accept' => $ssh_accept, 'ssh_failed' => $ssh_failed, 'ssh_invalid' => $ssh_invalid, 'ssh_latest_login' => $ssh_latest_login);
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 3;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'stack', 'ymin' => $ymin, 'ymax' => $ymax, 'xmin' => date("Y/m/d 00:00:01"), 'xmax' => date("Y/m/d 23:59:59"), 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel, 'overload' => $settings['settings']['overload'], 'variables' => $variables);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 /**
  * getDiskUsageData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData()
 {
     $class = __CLASS__;
     $settings = LoadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //display switch used to switch between view modes - data or percentage
     // true - show MB
     // false - show percentage
     $displayMode = $settings['settings']['display_limiting'];
     //define datasets
     $dataArrayLabel[0] = 'Disk Usage';
     $dataArrayLabel[1] = 'Overload';
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     //takes the log file and parses it into chartable data
     if ($logStatus) {
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         //get the size of the disk we are charting
         $diskSize = $this->getDiskSize($chartArray, $sizeofChartArray);
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             //echo '<pre>data'; var_dump ($data); echo '</pre>';
             // clean data for missing values
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //remap data if it needs mapping based on different loggers
             if (LOGGER == "collectd") {
                 $this->reMapData($data);
             }
             //usage is used to calculate view perspectives
             if (!$redline) {
                 $usage[] = $data[1] / 1048576;
                 if ($data[2] > 0) {
                     $percentage_used = $data[1] / $data[2] * 100;
                 } else {
                     $percentage_used = 0;
                 }
             } else {
                 $percentage_used = 0;
             }
             $timedata = (int) $data[0];
             $time[$data[1] / 1048576] = date("H:ia", $timedata);
             $usageCount[] = $data[0] * 1000;
             if ($displayMode == 'true') {
                 // display data using MB
                 $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] / 1048576 . "]";
                 if ($percentage_used > $settings['settings']['overload_1']) {
                     $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] / 1048576 . "]";
                 }
             } else {
                 // display data using percentage
                 $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $percentage_used . "]";
                 if ($percentage_used > $settings['settings']['overload_1']) {
                     $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", " . $percentage_used . "]";
                 }
             }
         }
         //echo '<pre>PRESETTINGS</pre>';
         //echo '<pre>';var_dump($usage);echo'</pre>';
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         if ($displayMode == 'true') {
             $disk_high = max($usage);
             $disk_low = min($usage);
             $disk_mean = array_sum($usage) / count($usage);
             //to scale charts
             $ymax = $disk_high;
             $ymin = $disk_low;
         } else {
             $disk_high = max($usage) / $diskSize * 100;
             $disk_low = min($usage) / $diskSize * 100;
             $disk_mean = array_sum($usage) / count($usage) / $diskSize * 100;
             //these are the min and max values used when drawing the charts
             //can be used to zoom into datasets
             $ymin = 0;
             $ymax = 100;
         }
         $disk_high_time = $time[max($usage)];
         $disk_low_time = $time[min($usage)];
         $disk_latest = $usage[count($usage) - 1];
         $disk_total = $diskSize;
         $disk_free = $disk_total - $disk_latest;
         $variables = array('disk_high' => number_format($disk_high, 2), 'disk_high_time' => $disk_high_time, 'disk_low' => number_format($disk_low, 2), 'disk_low_time' => $disk_low_time, 'disk_mean' => number_format($disk_mean, 2), 'disk_total' => number_format($disk_total, 1), 'disk_free' => number_format($disk_free, 1), 'disk_latest' => number_format($disk_latest, 1));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 2;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $disk_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 7
0
 /**
  * getMemoryUsageData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @return array $return data retrived from logfile
  *
  */
 public function getUsageData()
 {
     $class = __CLASS__;
     $settings = LoadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     $swap = array();
     //display switch used to switch between view modes - data or percentage
     // true - show MB
     // false - show percentage
     $displayMode = $settings['settings']['display_limiting'];
     //define datasets
     $dataArrayLabel[0] = 'Memory Usage';
     $dataArrayLabel[1] = 'Overload';
     $dataArrayLabel[2] = 'Swap';
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         //get the size of memory we are charting
         $memorySize = $this->getMemorySize($chartArray, $sizeofChartArray);
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             //check for redline
             // clean data for missing values
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //remap data if it needs mapping based on different loggers
             if (LOGGER == "collectd") {
                 $this->reMapData($data);
             }
             //if (  (!$data[1]) ||  ($data[1] == null) || ($data[1] == "")  )
             //	$data[1]=0.0;
             //used to filter out redline data from usage data as it skews it
             if (!$redline) {
                 $usage[] = $data[1] / 1024;
                 if ($data[3] > 0) {
                     $percentage_used = $data[1] / $data[3] * 100;
                 } else {
                     $percentage_used = 0;
                 }
             } else {
                 $percentage_used = 0;
             }
             $timedata = (int) $data[0];
             $time[$data[1] / 1024] = date("H:ia", $timedata);
             $usageCount[] = $data[0] * 1000;
             if ($displayMode == 'true') {
                 // display data using MB
                 $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] / 1024 . "]";
                 if ($percentage_used > $settings['settings']['overload_1']) {
                     $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[1] / 1024 . "]";
                 }
                 //swapping
                 if (isset($data[2])) {
                     $dataArray[2][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[2] / 1024 . "]";
                     $swap[] = $data[2] / 1024;
                 }
             } else {
                 // display data using percentage
                 $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $percentage_used . "]";
                 if ($percentage_used > $settings['settings']['overload_1']) {
                     $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", " . $percentage_used . "]";
                 }
                 //swapping
                 if (isset($data[2])) {
                     if (!$redline && $data[3] > 0) {
                         $swap_percentage = $data[2] / $data[3] * 100;
                     } else {
                         $swap_percentage = 0;
                     }
                     $dataArray[2][$data[0]] = "[" . $data[0] * 1000 . ", " . $swap_percentage . "]";
                     $swap[] = $swap_percentage;
                 }
             }
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         //echo $percentage_used; die;
         end($swap);
         $swapKey = key($swap);
         $swap = $swap[$swapKey];
         if ($displayMode == 'true') {
             $mem_high = max($usage);
             $mem_low = min($usage);
             $mem_mean = array_sum($usage) / count($usage);
             if ($swap > 1) {
                 $ymax = $mem_high * 1.05;
                 $ymin = $swap / 2;
             } else {
                 $ymax = $mem_high;
                 $ymin = $mem_low;
             }
         } else {
             //fix for division by zero
             if ($memorySize > 0) {
                 $mem_high = max($usage) / $memorySize * 100;
                 $mem_low = min($usage) / $memorySize * 100;
                 $mem_mean = array_sum($usage) / count($usage) / $memorySize * 100;
             } else {
                 $mem_high = $mem_low = $mem_mean = 0;
             }
             //these are the min and max values used when drawing the charts
             //can be used to zoom into datasets
             $ymin = 1;
             $ymax = 100;
         }
         $mem_high_time = $time[max($usage)];
         $mem_low_time = $time[min($usage)];
         $mem_latest = $usage[count($usage) - 1];
         //TODO need to get total memory here
         //as memory can change dynamically in todays world!
         $mem_total = $memorySize;
         $mem_free = $mem_total - $mem_latest;
         // values used to draw the legend
         $variables = array('mem_high' => number_format($mem_high, 2), 'mem_high_time' => $mem_high_time, 'mem_low' => number_format($mem_low, 2), 'mem_low_time' => $mem_low_time, 'mem_mean' => number_format($mem_mean, 2), 'mem_latest' => number_format($mem_latest, 2), 'mem_total' => number_format($mem_total, 2), 'mem_swap' => number_format($swap, 2));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 3;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $mem_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 8
0
 /**
  * getData
  *
  * Gets transfer data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @mode int processing mode, 1 is Transfer and 2 is Receive 
  * @return array $return data retrived from logfile
  *
  */
 public function getData($mode = 1)
 {
     $class = __CLASS__;
     $settings = loadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //$dataArrayOver = $dataArrayOver_2 = array();
     //$dataArraySwap = array();
     //display switch used to switch between view modes
     switch ($mode) {
         case 1:
             $threshold = $settings['settings']['overload_transfer'];
             $limiting = $settings['settings']['transfer_limiting'];
             $cutoff = $settings['settings']['transfer_cutoff'];
             $dataArrayLabel[0] = "Transmit";
             $dataArrayLabel[1] = "Overload";
             break;
         case 2:
             $threshold = $settings['settings']['overload_receive'];
             $limiting = $settings['settings']['receive_limiting'];
             $cutoff = $settings['settings']['receive_cutoff'];
             $dataArrayLabel[0] = "Receive";
             $dataArrayLabel[1] = "Overload";
             break;
     }
     $displayMode = $limiting;
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             //check for redline
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             // clean data for missing values
             //if (  (!$data[$mode]) ||  ($data[$mode] == null) || ($data[$mode] == "") || (int)$data[$mode] < 0)
             //	$data[$mode]=0;
             $net_rate = $data[$mode];
             $timedata = (int) $data[0];
             $time[$net_rate] = date("H:ia", $timedata);
             $rate[] = $net_rate;
             $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", '" . $net_rate . "']";
             if ($net_rate > $threshold) {
                 $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", '" . $net_rate . "']";
             }
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $net_high = max($rate);
         $net_high_time = $time[$net_high];
         $net_low = min($rate);
         $net_low_time = $time[$net_low];
         $net_latest = $rate[count($rate) - 1];
         $net_mean = number_format(array_sum($rate) / count($rate), 2);
         $net_estimate = round($net_mean * 60 * 60 * 24 / 1024);
         if ($net_estimate >= 1024) {
             $net_estimate = round($net_estimate / 1024, 1);
             $net_estimate_units = "GB";
         } else {
             $net_estimate_units = "MB";
         }
         if ($displayMode == 'true') {
             $ymin = 0;
             //$ymax = 16;
             $ymax = (int) $cutoff;
         } else {
             $ymin = $net_low;
             $ymax = $net_high;
         }
         $variables = array('net_high' => $net_high, 'net_high_time' => $net_high_time, 'net_low' => $net_low, 'net_low_time' => $net_low_time, 'net_mean' => $net_mean, 'net_latest' => $net_latest, 'net_estimate' => $net_estimate, 'net_estimate_units' => $net_estimate_units);
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 3;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $net_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 9
0
 public function getUsageData($switch)
 {
     $class = __CLASS__;
     $settings = loadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataArrayLabel = array();
     $dataRedline = $usage = array();
     //$dataArray = $dataRedline = $usage = array();
     //$dataArrayOver = $dataArrayOver_2 = array();
     //$dataArraySwap = array();
     //used to limit display data from being sqewed by overloads
     $displayMode = $settings['settings']['display_limiting'];
     //define datasets
     $dataArrayLabel[0] = 'User';
     $dataArrayLabel[1] = 'Nice';
     $dataArrayLabel[2] = 'System';
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             //if bad data point skip it
             if ($data == null) {
                 continue;
             }
             // clean data for missing values
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //if (  (!$data[1]) ||  ($data[1] == null) || ($data[1] == "")  )
             //	$data[1]=0.0;
             //used to filter out redline data from usage data as it skews it
             //for us this means add 3 arrays togeather
             if (!$redline) {
                 //switch = 2/3/4 if just showing one dataset
                 $usage[$switch][] = $data[$switch];
                 //switch= 1 / showing combination chart so usage is sum all usage!
                 //$usage[$switch][] = $data[$switch];
                 //$usage[$switch][] = $data[$switch];
             }
             $timedata = (int) $data[0];
             $time[$switch][$data[$switch]] = date("H:ia", $timedata);
             //we have 3 datasets to plot
             $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", '" . $data[1] . "']";
             $dataArray[1][$data[0]] = "[" . $data[0] * 1000 . ", '" . $data[2] . "']";
             $dataArray[2][$data[0]] = "[" . $data[0] * 1000 . ", '" . $data[3] . "']";
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $processor_high = max($usage[$switch]);
         $processor_high_time = $time[$switch][$processor_high];
         $processor_low = min($usage[$switch]);
         $processor_low_time = $time[$switch][$processor_low];
         //$cpu_mean = (float)number_format(array_sum($usage[$switch]) / count($usage[$switch]), 3);
         $processor_mean = array_sum($usage[$switch]) / count($usage[$switch]);
         $processor_latest = $usage[$switch][count($usage[$switch]) - 1];
         if ($displayMode == 'true') {
             $ymin = 0;
             $ymax = 100;
         } else {
             $ymin = $processor_low;
             $ymax = $processor_high;
         }
         $variables = array('processor_high' => number_format($processor_high, 3), 'processor_high_time' => $processor_high_time, 'processor_low' => number_format($processor_low, 3), 'processor_low_time' => $processor_low_time, 'processor_mean' => number_format($processor_mean, 3), 'processor_latest' => number_format($processor_latest, 3));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 3;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         //build chart object
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'mean' => $processor_mean, 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 10
0
 /**
  * getData
  *
  * Gets data from logfile, formats and parses it to pass it to the chart generating function
  *
  * @return array $return data retrived from logfile
  *
  */
 public function getData($switch = 1)
 {
     $class = __CLASS__;
     $settings = loadModules::$_settings->{$class};
     //define some core variables here
     $dataArray = $dataRedline = $usage = array();
     $dataArraySwap = array();
     //display switch used to switch between view modes - data or percentage
     //$displayMode =	$settings['settings']['display_limiting'];
     //mode specific data is set up here
     $dataArrayLabel[0] = $this->getChartLabel($switch);
     /*
      * grab the log file data needed for the charts as array of strings
      * takes logfiles(s) and gives us back contents
      */
     $contents = array();
     $logStatus = LoadUtility::parseLogFileData($this->logfile, $contents);
     /*
      * build the chartArray array here as array of arrays needed for charting
      * takes in contents and gives us back chartArray
      */
     $chartArray = array();
     $sizeofChartArray = 0;
     if ($logStatus) {
         //takes the log file and parses it into chartable data
         $this->getChartData($chartArray, $contents);
         $sizeofChartArray = (int) count($chartArray);
     }
     /*
      * now we loop through the dataset and build the chart
      * uses chartArray which contains the dataset to be charted
      */
     if ($sizeofChartArray > 0) {
         // main loop to build the chart data
         for ($i = 0; $i < $sizeofChartArray; ++$i) {
             $data = $chartArray[$i];
             if ($data == null) {
                 continue;
             }
             //check for redline
             $redline = false;
             if (isset($data['redline']) && $data['redline'] == true) {
                 $redline = true;
             }
             //when showing send and receive its bytes to MB
             //when showing queries, mode 3, its 1 to 1
             if ($switch == 3) {
                 $divisor = 1;
             } else {
                 $divisor = 1024;
             }
             //used to filter out redline data from usage data as it skews it
             if (!$redline) {
                 $usage[] = $data[$switch] / $divisor;
             }
             $timedata = (int) $data[0];
             $time[$data[$switch] / $divisor] = date("H:ia", $timedata);
             $usageCount[] = $data[0] * 1000;
             // received
             $dataArray[0][$data[0]] = "[" . $data[0] * 1000 . ", " . $data[$switch] / $divisor . "]";
         }
         /*
          * now we collect data used to build the chart legend 
          * 
          */
         $mysql_high = max($usage);
         $mysql_low = min($usage);
         $mysql_mean = array_sum($usage) / count($usage);
         $ymax = $mysql_high;
         $ymin = $mysql_low;
         $mysql_high_time = $time[max($usage)];
         $mysql_low_time = $time[min($usage)];
         $mysql_latest = $usage[count($usage) - 1];
         // values used to draw the legend
         $variables = array('mysql_high' => number_format($mysql_high, 0), 'mysql_high_time' => $mysql_high_time, 'mysql_low' => number_format($mysql_low, 0), 'mysql_low_time' => $mysql_low_time, 'mysql_mean' => number_format($mysql_mean, 0), 'mysql_latest' => number_format($mysql_latest, 0));
         /*
          * all data to be charted is now cooalated into $return
          * and is returned to be charted
          * 
          */
         $return = array();
         // get legend layout from ini file
         $return = $this->parseInfo($settings['info']['line'], $variables, __CLASS__);
         //parse, clean and sort data
         $depth = 1;
         //number of datasets
         $this->buildChartDataset($dataArray, $depth);
         $return['chart'] = array('chart_format' => 'line', 'chart_avg' => 'avg', 'ymin' => $ymin, 'ymax' => $ymax, 'xmin' => date("Y/m/d 00:00:01"), 'xmax' => date("Y/m/d 23:59:59"), 'mean' => $mysql_mean, 'avg' => "stack", 'dataset' => $dataArray, 'dataset_labels' => $dataArrayLabel);
         return $return;
     } else {
         return false;
     }
 }