Ejemplo n.º 1
0
 /**
  * logMemoryUsageData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     /* 
     	grab this data directly from /proc/meminfo in a single call
     	egrep --color 'Mem|Cache|Swap' /proc/meminfo
     */
     //pulling Cached here gives us both Cached and SwapCached
     exec("egrep 'SwapCached|SwapTotal|SwapFree' /proc/meminfo | awk -F' ' '{print \$2}'", $sysmemory);
     /*
       [0]=> string(11) "SwapCached:"
       [1]=> string(10) "SwapTotal:"
       [2]=> string(9) "SwapFree:"
     */
     //calculate swap usage
     $swapcached = $sysmemory[0];
     $swaptotal = $sysmemory[1];
     $swapfree = $sysmemory[2];
     $swapused = $swaptotal - ($swapfree + $swapcached);
     $string = $timestamp . '|' . $swapcached . '|' . $swaptotal . '|' . $swapfree . '|' . $swapused . "\n";
     //echo 'DATA:'  . $string .  "\n" ;
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     //If alerts are enabled, check for alerts
     if (Alert::$alertStatus) {
         $this->checkAlerts($timestamp, $swapused, $swaptotal, $settings);
     }
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 2
0
 /**
  * logData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     $load = null;
     //use the php function if its there
     if (!function_exists('sys_getloadavg')) {
         $load = exec("cat /proc/loadavg | awk -F' ' '{print \$1\"|\"\$2\"|\"\$3}'");
     } else {
         $phpload = sys_getloadavg();
         $load = $phpload[0] . "|" . $phpload[1] . "|" . $phpload[2];
     }
     //if we want fancy formatting in logs we can always format them like this
     //$number = number_format((float)$number, 2, '.', '');
     $string = $timestamp . '|' . $load . "\n";
     //we can also add a switch to feed live data to server with no local logging
     //by just returning data
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     //If alerts are enabled, check for alerts
     //note: $phpload dont work on 4.0 needs fixing above
     if (Alert::$alertStatus) {
         $alertString = $this->checkAlerts($timestamp, $phpload, $settings);
     }
     //Based on API mode return data if need be
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 3
0
 /**
  * logDiskUsageData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *	 *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     //get process data here
     $ps_args = '-Ao %cpu,%mem,pid,user,comm,args';
     putenv('COLUMNS=1000');
     $string = shell_exec("ps {$ps_args}");
     //$string = explode("\n", trim ($processData));
     //get log location
     $logdirname = sprintf($this->logdir, date('Y-m-d'));
     $logpath = LOG_PATH . $logdirname;
     //echo "LOG_PATH : " . $logpath . " \n";
     $filename = sprintf($this->logfile, $logdirname, $timestamp);
     //echo "FILENAME : " . $filename . " \n";
     //great log folder if it doesnt exist
     if (!file_exists($logpath)) {
         mkdir($logpath, 0777);
     }
     //read me on encoding array to disk instead
     //https://www.safaribooksonline.com/library/view/php-cookbook/1565926811/ch05s08.html
     //write out process data to file
     LoadUtility::safefilerewrite($filename, $string, "w", true);
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 4
0
 /**
  * logDiskUsageData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *	 *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     $drive = $settings['settings']['drive'];
     if (is_dir($drive)) {
         $spaceBytes = disk_total_space($drive);
         $freeBytes = disk_free_space($drive);
         $usedBytes = $spaceBytes - $freeBytes;
         //$freeBytes = dataSize($Bytes);
         //$percentBytes = $freeBytes ? round($freeBytes / $totalBytes, 2) * 100 : 0;
     }
     $string = $timestamp . '|' . $usedBytes . '|' . $spaceBytes . "\n";
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     //If alerts are enabled, check for alerts
     if (Alert::$alertStatus) {
         $this->checkAlerts($timestamp, $usedBytes, $spaceBytes, $settings);
     }
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 5
0
 /**
  * logApacheUsageData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     //$url = "http://localhost/server-status";
     $url = $settings['settings']['serverstatus'];
     $parseUrl = $url . "/?auto";
     $locate = "CPULoad";
     //float $dataValue;
     $dataValue = $this->getApacheDataValue($parseUrl, $locate);
     //$dataValue = sscanf($dataValue, "%f")[0];
     //$dataValue = floatval($dataValue);
     //$dataValue = (float)$dataValue;
     //echo 'APACHE:' . $dataValue;
     //settype($dataValue, "float");
     if ($dataValue == null) {
         $dataValue = 0;
     }
     $string = time() . '|' . $dataValue . "\n";
     $filename = sprintf($this->logfile, date('Y-m-d'));
     //$this->safefilerewrite($filename,$string,"a",true);
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 6
0
 /**
  * updateModuleSettings
  *
  * Called by modulesettings to read settings back in after changes...
  *
  */
 public static function updateModuleSettings()
 {
     LoadModules::setSettings('general', parse_ini_file(APP_PATH . '/config/' . self::$settings_ini, true));
     //generate list of all modules
     LoadUtility::generateExtensionList('plugins', self::$_plugins);
     //load all charting modules that are enabled
     LoadUtility::loadExtensions('plugins', self::$_settings, self::$_classes, self::$_plugins);
 }
Ejemplo n.º 7
0
 /**
  * writeAlerts - writes alerts out to log file
  *
  */
 public function writeAlerts()
 {
     //hard coded for the moment
     if (isset(self::$alertDataArray) && is_array(self::$alertDataArray)) {
         $filename = LOG_PATH . "events_" . date('Y-m-d') . ".log";
         LoadUtility::safefilerewrite($filename, self::$alertDataArray, "a", true);
         return true;
     }
     return false;
 }
Ejemplo n.º 8
0
 /**
  * logData
  *
  * Retrives uptime data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *	 *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $uptime = exec("cat /proc/uptime | awk -F' ' '{print \$1\"|\"\$2}'");
     $string = time() . '|' . $uptime . "\n";
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 9
0
 /**
  * logMemoryUsageData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     /* 
     	grab this data directly from /proc/meminfo in a single call
     	egrep --color 'Mem|Cache|Swap' /proc/meminfo
     */
     //pulling Cached here gives us both Cached and SwapCached
     exec("egrep 'MemTotal|MemFree|Buffers|Cached|SwapTotal|SwapFree' /proc/meminfo | awk -F' ' '{print \$2}'", $sysmemory);
     /*
       [0]=> string(9) "MemTotal:"
       [1]=> string(8) "MemFree:"
       [2]=> string(8) "Buffers:"
       [3]=> string(7) "Cached:"
       [4]=> string(11) "SwapCached:"
       [5]=> string(10) "SwapTotal:"
       [6]=> string(9) "SwapFree:"
     */
     //calculate memory usage
     $memory = 0;
     $totalmemory = $sysmemory[0];
     $freememory = $sysmemory[1];
     $bufferedmemory = $sysmemory[2];
     $cachedmemory = $sysmemory[3];
     $memory = $totalmemory - ($freememory + $bufferedmemory + $cachedmemory);
     //calculate swap usage
     $swapcached = $sysmemory[4];
     $totalswap = $sysmemory[5];
     $freeswap = $sysmemory[6];
     $swap = $totalswap - ($freeswap + $swapcached);
     //pull log data togeather
     $string = $timestamp . '|' . $memory . '|' . $swap . '|' . $totalmemory . "\n";
     //append log data to log file
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     //If alerts are enabled, check for alerts
     if (Alert::$alertStatus) {
         $this->checkAlerts($timestamp, $memory, $totalmemory, $settings);
     }
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 10
0
 /**
  * logData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     $r = null;
     //grab server location and port
     $server = $settings['settings']['server'];
     $port = intval($settings['settings']['port']);
     //echo 'server : ' . $server;
     //echo ' port : ' . $port;
     //grab data from API
     $r = $this->request('summary', $server, $port);
     /*
     echo print_r($r["SUMMARY"]["MHS 1m"], true)."\n";
     echo print_r($r["SUMMARY"]["MHS 5m"], true)."\n";
     echo print_r($r["SUMMARY"]["MHS 15m"], true)."\n";
     */
     $load = $r["SUMMARY"]["MHS 1m"] . "|" . $r["SUMMARY"]["MHS 5m"] . "|" . $r["SUMMARY"]["MHS 15m"];
     //if we want fancy formatting in logs we can always format them like this
     //$number = number_format((float)$number, 2, '.', '');
     $string = $timestamp . '|' . $load . "\n";
     //we can also add a switch to feed live data to server with no local logging
     //by just returning data
     $filename = sprintf($this->logfile, date('Y-m-d'));
     LoadUtility::safefilerewrite($filename, $string, "a", true);
     //If alerts are enabled, check for alerts
     //note: $phpload dont work on 4.0 needs fixing above
     if (Alert::$alertStatus) {
         $alertString = $this->checkAlerts($timestamp, $r, $settings);
     }
     //Based on API mode return data if need be
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 11
0
        	<input type="submit" class="btn btn-primary" value="Save Settings">
    </div>

	<div class="separator bottom"></div>

    <!-- 
      * this is where we loop through all the modules
      * and deal with their individual settings
	-->	


        <?php 
    $plugins = LoadPlugins::$_plugins;
    foreach ($plugins as $plugin => $pluginName) {
        //grab settings data for module
        $pluginSettings = LoadUtility::getSettings($plugin, 'plugins');
        //var_dump ( $pluginSettings );
        ?>

		<div class="well">

			<div class="separator bottom"></div>
			<div class="row-fluid">

			    <div class="span3">
			            <h4> <?php 
        echo $plugin;
        ?>
 Plugin</h4>
			    </div>
Ejemplo n.º 12
0
 /**
  * logData
  *
  * Retrives data and logs it to file
  *
  * @param string $type type of logging default set to normal but it can be API too.
  * @return string $string if type is API returns data as string
  *
  */
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $timestamp = time();
     //need to collect data from multiple interfaces here
     $apiString = "";
     foreach (Logger::$_settings->general['network_interface'] as $interface => $value) {
         //echo 'NET: ' . $interface . "\n" ;
         //skip disabled interfaces - should be and / or not and ?
         if (!(isset(Logger::$_settings->general['network_interface'][$interface]) && Logger::$_settings->general['network_interface'][$interface] == "true")) {
             continue;
         }
         $logfile = sprintf($this->logfile, date('Y-m-d'), $interface);
         //echo 'PROCESSING:' . $logfile . "\n";
         $netdev = file_get_contents('/proc/net/dev');
         $pattern = "/^.*\\b({$interface})\\b.*\$/mi";
         preg_match($pattern, $netdev, $hits);
         $venet = '';
         if (isset($hits[0])) {
             $venet = trim($hits[0]);
             $venet = preg_replace("/ {1,99}/", " ", $venet);
             $venet = trim(str_replace("{$interface}:", "", $venet));
         }
         $parts = explode(" ", $venet);
         $recv = isset($parts[0]) ? $parts[0] : '';
         $trans = isset($parts[8]) ? $parts[8] : '';
         // $recv = exec("cat /proc/net/dev | grep ".$interface." | awk -F' ' '{print $2}'");
         // $trans = exec("cat /proc/net/dev | grep ".$interface." | awk -F' ' '{print $10}'");
         if ($logfile && file_exists($logfile)) {
             $elapsed = $timestamp - filemtime($logfile);
         } else {
             $elapsed = 0;
         }
         //meaning new logfile
         //used to help calculate the difference as network is thruput not value based
         //so is based on the difference between thruput before the current run
         //this data is stored in _net_latest_elapsed_
         // grab net latest location and elapsed
         $netlatestElapsed = 0;
         $netLatestLocation = dirname($logfile) . DIRECTORY_SEPARATOR . '_net_latest_' . $interface;
         // basically if netlatest elapsed is within reasonable limits (logger interval + 20%) then its from the day
         // before rollover so we can use it to replace regular elapsed
         // which is 0 when there is anew log file
         if (file_exists($netLatestLocation)) {
             $last = explode("|", file_get_contents($netLatestLocation));
             $netlatestElapsed = $timestamp - filemtime($netLatestLocation);
             //if its a new logfile check to see if there is previous netlatest data
             if ($elapsed == 0) {
                 //data needs to within the logging period limits to be accurate
                 $interval = $this->getLoggerInterval();
                 if (!$interval) {
                     $interval = 360;
                 } else {
                     $interval = $interval * 1.2;
                 }
                 if ($netlatestElapsed <= $interval) {
                     $elapsed = $netlatestElapsed;
                 }
             }
         }
         //if we were able to get last data from net latest above
         if (@$last && $elapsed) {
             $trans_diff = ($trans - $last[0]) / 1024;
             if ($trans_diff < 0) {
                 $trans_diff = (4294967296 + $trans - $last[0]) / 1024;
             }
             $trans_rate = round($trans_diff / $elapsed, 2);
             $recv_diff = ($recv - $last[1]) / 1024;
             if ($recv_diff < 0) {
                 $recv_diff = (4294967296 + $recv - $last[1]) / 1024;
             }
             $recv_rate = round($recv_diff / $elapsed, 2);
             $string = $timestamp . "|" . $trans_rate . "|" . $recv_rate . "\n";
         } else {
             //if this is the first value in the set and there is no previous data then its null
             $lastlogdata = "|0.0|0.0";
             $string = $timestamp . $lastlogdata . "\n";
         }
         //write out log data here
         LoadUtility::safefilerewrite($logfile, $string, "a", true);
         // write out last transfare and received bytes to latest
         $last_string = $trans . "|" . $recv;
         $fh = dirname($this->logfile) . DIRECTORY_SEPARATOR . "_net_latest_" . $interface;
         LoadUtility::safefilerewrite($fh, $last_string, "w", true);
         //If alerts are enabled, check for alerts
         if (@$last && $elapsed) {
             if (Alert::$alertStatus) {
                 $this->checkAlerts($timestamp, $trans_rate, $recv_rate, $settings);
             }
         }
         //figure out how to send back data for multiple interfaces here
         //echo "STRING:" . $string;
         $apiString[$interface] = $string;
         /*
         if ($apiString == "")
         else
         	$apiString += "|" . $string;
         */
     }
     if ($type == "api") {
         return $apiString;
     } else {
         return true;
     }
 }
Ejemplo n.º 13
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;
     }
 }
Ejemplo n.º 14
0
    }
    ?>
>Override</option>
				</select>
			</div>
		</div>

		<div class="row-fluid">
			<div class="span3">
				<strong>Override time-zone</strong>
			</div>
			<div class="span9 right">


			<?php 
    $timezones = LoadUtility::getTimezones();
    print '<select name="formsettings[settings][clienttimezone]" id="timezone">';
    foreach ($timezones as $region => $list) {
        print '<optgroup label="' . $region . '">' . "\n";
        foreach ($list as $thetimezone => $name) {
            print '<option name="' . $thetimezone . '"';
            $check = $settings['settings']['clienttimezone'];
            if ($check == $thetimezone) {
                print ' selected="selected"';
            }
            print '>' . $thetimezone . '</option>' . "\n";
        }
        print '<optgroup>' . "\n";
    }
    print '</select>';
    ?>
Ejemplo n.º 15
0
        }
    }
    ?>


	<div class="innerAll">
	    <div id="accordion" class="accordion">	
		<?php 
    //used for callbacks to main plugin to select timestamp to display
    $timeStamp = false;
    if (isset($_GET['timestamp'])) {
        $timeStamp = $_GET['timestamp'];
    }
    //set url for callback - see end of chartcore.php in lib.charts
    //get plugin url for callbacks - needs cleaning up
    $host_url = LoadUtility::get_module_url();
    //if we have a log file selected override callback
    if ($gotLogDate) {
        $callback = $host_url . 'page=Process&logdate=' . $logDate . '&timestamp=';
    } else {
        $callback = $host_url . 'page=Process&timestamp=';
    }
    //render chart
    //get plugin settings for chart to display
    $chartToShow = $pluginSettings['settings']['display_chart'];
    //contains args[] array from modules .ini file
    //echo 'showing ' . $showChart;
    //LoadModules::renderChart("Cpu", false, false, false, $callback, 770 );
    LoadModules::renderChart($chartToShow, false, false, false, $callback, 770);
    ?>
		</div>
Ejemplo n.º 16
0
 public function logData($type = false)
 {
     $class = __CLASS__;
     $settings = Logger::$_settings->{$class};
     $sshdLogFile['path'] = $settings['settings']['log_location'];
     //log data variables
     $logData['invalid_user'] = 0;
     $logData['failed_pass'] = 0;
     $logData['accepted'] = 0;
     //grab the logfile
     $logfile = sprintf($this->logfile, date('Y-m-d'));
     //check if log file exists and see time difference
     //stored in elapsed
     if ($logfile && file_exists($logfile)) {
         $elapsed = time() - filemtime($logfile);
     } else {
         $elapsed = 0;
     }
     //meaning new logfile
     //we need to read offset here
     //grab net latest location and figure out elapsed
     //zero out offset
     $sshdLogFile['offset'] = 0;
     $sshdLogFile['timestamp'] = 0;
     $sshlatestElapsed = 0;
     $sshLatestLocation = dirname($logfile) . DIRECTORY_SEPARATOR . '_ssh_latest';
     // basically if sshlatestElapsed is within reasonable limits (logger interval + 20%)
     // then its from the day before rollover so we can use it to replace regular elapsed
     // which is 0 when there is a new log file
     if (file_exists($sshLatestLocation)) {
         //if we want to add more data to return string we can use eplode below
         $last = explode("|", file_get_contents($sshLatestLocation));
         $sshdLogFile['offset'] = file_get_contents($sshLatestLocation);
         //$sshdLogFile['timestamp'] = file_get_contents(  $sshLatestLocation );
         //echo 'STORED OFFSET  : ' . $sshdLogFile['offset']   . "\n";
         $sshlatestElapsed = time() - filemtime($sshLatestLocation);
         //if its a new logfile check to see if whats up with the interval
         if ($elapsed == 0) {
             //data needs to within the logging period limits to be accurate
             $interval = $this->getLoggerInterval();
             if (!$interval) {
                 $interval = 360;
             } else {
                 $interval = $interval * 1.2;
             }
             if ($sshlatestElapsed <= $interval) {
                 $elapsed = $sshlatestElapsed;
             }
         }
     }
     // Reset offset if file size has reduced (truncated)
     // means logs have been rotated!
     // TODO :
     // if logs have been rotated we need to look for data in old log file
     // and add to new log file
     // however need to read a .gz to do this as old logs are compressed and soted by date
     // ie secure-20140427.gz
     $fileSize = filesize($sshdLogFile['path']);
     if ($fileSize < $sshdLogFile['offset']) {
         $sshdLogFile['offset'] = 0;
     }
     //read log file and get log data
     if (!$this->loadLogData($sshdLogFile, $logData)) {
         return false;
     }
     //if we were able to get last data from mysql latest above
     //figure out the difference as thats what we chart
     if (@$sshdLogFile['offset'] && $elapsed) {
         if ($logData['accepted'] < 0) {
             $logData['accepted'] = 0;
         }
         if ($logData['failed_pass'] < 0) {
             $logData['failed_pass'] = 0;
         }
         if ($logData['invalid_user'] < 0) {
             $logData['invalid_user'] = 0;
         }
         $string = time() . "|" . $logData['accepted'] . "|" . $logData['failed_pass'] . "|" . $logData['invalid_user'] . "\n";
         //echo 'DATA WRITE  : ' . $logData['accepted'] . '|' . $logData['failed_pass'] . '|' . $logData['invalid_user'] . "\n";
     } else {
         //if this is the first value in the set and there is no previous data then its null
         $lastlogdata = "|0|0|0";
         $string = time() . $lastlogdata . "\n";
     }
     //write out log data here
     LoadUtility::safefilerewrite($logfile, $string, "a", true);
     // write out filesize so we can pick up where we left off next time around
     LoadUtility::safefilerewrite($sshLatestLocation, $fileSize, "w", true);
     if ($type == "api") {
         return $string;
     } else {
         return true;
     }
 }
Ejemplo n.º 17
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;
     }
 }
Ejemplo n.º 18
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;
     }
 }
Ejemplo n.º 19
0
                            ?>
checked="checked"<?php 
                        }
                        ?>
							                    >

											</div>
										</div>
									<?php 
                    }
                    echo "<br><strong>Network Settings</strong><br><br>";
                }
                foreach ($moduleSettings['settings'] as $setting => $value) {
                    //filter out ui settings but keep data for POST
                    //limiting keywords are used for graph mode toggles
                    if (LoadUtility::endswith($setting, "limiting")) {
                        //ucwords(str_replace("_"," ",$setting));
                        //echo 'limiting : ' . $value;
                        ?>

                        			<?php 
                    } else {
                        ?>
		                        	
			                        	<div class="row-fluid">
			                        		<div class="span3">
			                        			<strong><?php 
                        echo ucwords(str_replace("_", " ", $setting));
                        ?>
</strong>
			                        		</div>
Ejemplo n.º 20
0
 /**
  * cleanUpInstaller
  *
  * Checks if is still installation progress and redirects if TRUE.
  *
  */
 public function cleanUpInstaller()
 {
     //location of core settings
     $settings_file = APP_PATH . '/config/settings.ini.php';
     //see if we can write to settings file
     //if ( $this->checkWritePermissions( $settings_file ) )
     if (LoadUtility::checkWritePermissions($settings_file)) {
         /* 
          * Create first log files for all active modules 
          * only executes if there are no log files
          */
         $this->createFirstLogs();
         /* 
          * clean up installation files
          */
         //if installer is not present (true) leave
         if ($this->checkInstaller()) {
             header("Location: index.php");
         } else {
             //clean up - try to delete installer if we have permissions
             $installer_file = HOME_PATH . "/install/index.php";
             $installer_loc = HOME_PATH . "/install/";
             unlink($installer_file);
             rmdir($installer_loc);
             //check again if it worked exit
             if ($this->checkInstaller()) {
                 header("Location: index.php");
             } else {
                 //if not throw a error and exit
                 require_once APP_PATH . '/layout/secure.php';
                 require_once APP_PATH . '/layout/footer.php';
                 exit;
             }
         }
     } else {
         header("Location: /install/index.php?step=1");
     }
 }
Ejemplo n.º 21
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;
     }
 }
Ejemplo n.º 22
0
$max = date('Y-m-d');
if (isset($_GET['logdate']) && !empty($_GET['logdate']) && $_GET['logdate'] !== date('Y-m-d')) {
    $min = $_GET['logdate'];
    $max = $_GET['logdate'];
}
if (isset($_GET['minDate']) && !empty($_GET['minDate']) && isset($_GET['maxDate']) && !empty($_GET['maxDate'])) {
    $min = $_GET['minDate'];
    $max = $_GET['maxDate'];
}
$min = strtotime($min);
$max = strtotime($max);
//timezone is taken from the server and UTC offset is recorded for normalization
//client timezone is used to offset browser via javascript only...
$phptimezone = date_default_timezone_get();
//normalize all server time to UTC
$timeoffset = LoadUtility::get_timezone_offset($phptimezone, 'UTC');
if ($timeoffset > 0) {
    $timeoffset = $timeoffset / (60 * 60);
} else {
    $timeoffset = 1;
}
?>

	///////////////////////////////////////////////////

	var today_min_php = <?php 
echo gmmktime(0, 0, 0, date("n", $min), date("j", $min), date("Y", $min)) * 1000;
?>
;	
	var today_max_php = <?php 
echo gmmktime(24, 0, 0, date("n", $max), date("j", $max), date("Y", $max)) * 1000;
Ejemplo n.º 23
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;
 }
Ejemplo n.º 24
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;
     }
 }
Ejemplo n.º 25
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;
     }
 }
Ejemplo n.º 26
0
    include 'login.php';
} else {
    ?>

<?php 
    if (isset($_POST['update_settings'])) {
        /////////////////////////////////////////////////////////////////////
        //updates the general settings here as api settings are stored there
        //we clean input here for items with checkbox values for some reason not sure if we still need to
        $_POST['formsettings']['settings']['apiserver'] = !isset($_POST['formsettings']['settings']['apiserver']) ? "false" : "true";
        // Loop throught settings
        $settings_file = APP_PATH . '/config/' . LoadAvg::$settings_ini;
        $settings = LoadAvg::$_settings->general;
        $postsettings = $_POST['formsettings'];
        $replaced_settings = LoadUtility::ini_merge($settings, $postsettings);
        LoadUtility::write_php_ini($replaced_settings, $settings_file);
        $settings = LoadAvg::$_settings->general;
        /////////////////////////////////////////////////////////////////////
        //test api connection done inline on reload for now need AJAX
        if (isset($_POST['Test_Settings'])) {
            header('Location: ' . strtok($_SERVER["REQUEST_URI"], '&') . '&test=true');
        } else {
            header('Location: ' . strtok($_SERVER["REQUEST_URI"], '&'));
        }
    }
    ?>

<form action="" method="post">

	<input type="hidden" name="update_settings" value="1" />
Ejemplo n.º 27
0
//get the display_limiting setting from the settings subsection for this module
$thedata = $modSettings['settings']['display_limiting'];
//if we are changing mode
if (isset($_GET['diskmode']) || !empty($_GET['diskmode'])) {
    $newmode = $_GET['diskmode'];
    switch ($newmode) {
        case "true":
            $mydata['settings']['display_limiting'] = "true";
            $mergedsettings = LoadUtility::ini_merge($modSettings, $mydata);
            LoadUtility::write_module_ini($mergedsettings, $module);
            header("Location: " . $links);
            break;
        case "false":
            $mydata['settings']['display_limiting'] = "false";
            $mergedsettings = LoadUtility::ini_merge($modSettings, $mydata);
            LoadUtility::write_module_ini($mergedsettings, $module);
            header("Location: " . $links);
            break;
    }
} else {
    //if not build the links
    switch ($thedata) {
        case "true":
            $links = $links . "diskmode=false";
            break;
        case "false":
            $links = $links . "diskmode=true";
            break;
    }
}
?>
Ejemplo n.º 28
0
 /**
  * getChartRenderData
  *
  * Function which gets the raw chart data from the module
  *
  * @param array @chart settings of the chart
  * @param array @functionSettings settings of the chart
  * @param string @module module to look up
  *
  */
 public function getChartRenderData($chart, $functionSettings, $module)
 {
     // find out main function from module args that generates chart data
     // in this module its getUsageData above
     $caller = $chart->function;
     $logfileStatus = false;
     $chartData = false;
     if (!empty($this->logfile)) {
         $logfileStatus = true;
         //call modules main function and pass over functionSettings
         if ($functionSettings) {
             $chartData = $this->{$caller}($functionSettings);
         } else {
             $chartData = $this->{$caller}();
         }
     }
     //if there is no logfile or error from the caller (stuff is false)
     //then we just return a empty chart
     if (!isset($chartData) || $chartData == false || $logfileStatus == false) {
         $moduleSettings = LoadModules::$_settings->{$module};
         $chartData = $this->parseInfo($moduleSettings['info']['line'], null, $module);
         $chartData['chart'] = LoadUtility::getEmptyChart();
     }
     return $chartData;
 }
Ejemplo n.º 29
0
						<?php 
                echo $errorMsg;
                ?>
					</ul>
					<?php 
            } else {
                ?>

					<h4>Installation Complete</h4>
					<div class="well">

					<?php 
                //need to move this over to loadavg core and not be writing settings files out directly here its messy
                // write settings file out
                //var_dump($settings);
                LoadUtility::write_php_ini($settings, $settings_file);
                //use safe write here ?
                $fh = fopen($settings_file, "a");
                fwrite($fh, "\n");
                fclose($fh);
                ?>

					<b>Thank you for installing LoadAvg <?php 
                echo $settings['settings']['version'];
                ?>
</b>
					<br><br>
					<p>
					LoadAvg records log data at the system level. For it to function correctly 
					you need to you need to set up the logger.
					</p>
Ejemplo n.º 30
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;
     }
 }