public static function doLog($logmethod, array $data, &$output)
 {
     $log = new Logger('ezperflogger');
     // constructor args for the specific handler can be set via ini
     /// @todo how to create resources instead?
     foreach (eZPerfLoggerINI::variable('MonologSettings', 'LogHandlers') as $handlerName) {
         $handlerClass = 'Monolog\\Handler\\' . $handlerName . "Handler";
         if (eZPerfLoggerINI::hasVariable('MonologSettings', 'LogHandler_' . $handlerName)) {
             $r = new ReflectionClass($handlerClass);
             $handler = $r->newInstanceArgs(eZPerfLoggerINI::variable('MonologSettings', 'LogHandler_' . $handlerName));
         } else {
             $handler = new $handlerClass();
         }
         $log->pushHandler($handler);
     }
     // the default severity level: taken from config file
     $level = (int) eZPerfLoggerINI::variable('MonologSettings', 'SeverityLevel');
     // either coalesce messages or not: taken from config file
     if (eZPerfLoggerINI::variable('MonologSettings', 'Coalescevariables') == 'enabled') {
         /// @todo allow via ini file the specification of custom formatters?
         $msg = array();
         foreach ($data as $varname => $value) {
             $msg[] = "{$varname}: {$value}";
         }
         $log->addRecord($level, implode(', ', $msg));
     } else {
         foreach ($data as $varname => $value) {
             $log->addRecord($level, "{$varname}: {$value}");
         }
     }
 }
 /**
  * For statsd, we use a different logic than for other loggers:
  * in the name of the KPI we embed some variable data, such as f.e.
  * content-class name. This allows better grouping and filtering of data
  * in the Graphite console.
  *
  * @see ezperformancelogger.ini
  *
  * We cache internally prefix and postfix for optimal performances
  */
 public static function transformVarName($var, $default = null)
 {
     if (self::$prefix === null || self::$postfix === null) {
         $strip = eZPerfLoggerINI::variable('StatsdSettings', 'RemoveEmptyTokensInVariable') == 'enabled';
         foreach (array(eZPerfLoggerINI::variable('StatsdSettings', 'VariablePrefix'), eZPerfLoggerINI::variable('StatsdSettings', 'VariablePostfix')) as $i => $string) {
             if (strpos($string, '$') !== false) {
                 $tokens = explode('.', $string);
                 foreach ($tokens as $j => &$token) {
                     if (strlen($token) && $token[0] == '$') {
                         $token = str_replace('.', '_', eZPerfLogger::getModuleData(substr($token, 1), $default));
                         if ($strip && $token == '') {
                             unset($tokens[$j]);
                         }
                     }
                 }
                 $string = implode('.', $tokens);
             }
             if ($i) {
                 self::$postfix = $string;
             } else {
                 self::$prefix = $string;
             }
         }
     }
     return self::$prefix . $var . self::$postfix;
 }
 public static function shouldLog(array $data, $output)
 {
     if (!isset($data['mem_usage']) || $data['mem_usage'] >= eZPerfLoggerINI::variable('LogFilterSettings', 'MemoryhungrypagesFilter')) {
         return true;
     }
     return false;
 }
 public static function shouldLog(array $data, $output)
 {
     if (!isset($data['execution_time']) || $data['execution_time'] >= eZPerfLoggerINI::variable('LogFilterSettings', 'SlowpagesFilterLimit')) {
         return true;
     }
     return false;
 }
 public static function shouldLog(array $data, $output)
 {
     if (rand(0, eZPerfLoggerINI::variable('LogFilterSettings', 'MemoryhungrypagesFilter')) <= 1) {
         return true;
     }
     return false;
 }
 public static function resetStats()
 {
     self::$statsCount = 0;
     self::$stats = array();
     foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $var) {
         self::$stats[$var] = array('total' => 0);
     }
 }
 protected static function generateJSEventsFunctionCalls($data)
 {
     $prefix = eZPerfLoggerINI::variable('OdoscopeSettings', 'VariablePrefix');
     $text = "";
     foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $var) {
         /// @todo proper js escaping; do not add quotes for numeric values?
         $text .= "osc.evt( '" . $prefix . urlencode($var) . "', '" . urlencode($data[$var]) . "' );\n";
     }
     return $text;
 }
 /**
  * Difference from base class: do not obey php.ini but eZ config instead
  */
 static function flush($script_name = null)
 {
     $struct = static::get_packet_info($script_name);
     $message = prtbfr::encode($struct, self::$message_proto);
     $server = eZPerfLoggerINI::variable('pinbaSettings', 'Server');
     $port = 30002;
     if (count($parts = explode(':', $server)) > 1) {
         $port = $server[1];
         $server = $server[0];
     }
     $fp = fsockopen("udp://{$server}", $port, $errno, $errstr);
     if ($fp) {
         fwrite($fp, $message);
         fclose($fp);
     }
 }
 public static function parseLogLine($line, $counters = array(), $excludeRegexps = array())
 {
     $countersCount = count($counters);
     $separator = eZPerfLoggerINI::variable('csvSettings', 'Separator');
     $logPartArray = explode($separator, $line, $countersCount + 6);
     if (count($logPartArray) < $countersCount + 6) {
         return false;
     }
     $url = rtrim($logPartArray[$countersCount + 5], "\n");
     foreach ($excludeRegexps as $regexp) {
         if (preg_match($regexp, $url)) {
             return true;
         }
     }
     return array('url' => $url, 'time' => $logPartArray[0], 'ip' => $logPartArray[$countersCount + 2], 'response_status' => $logPartArray[$countersCount + 3], 'response_size' => $logPartArray[$countersCount + 4], 'counters' => array_slice($logPartArray, 1, $countersCount));
 }
Ejemplo n.º 10
0
 /**
  * This method gets called by self::filter()
  */
 public static function doLog($method, array $values, &$output)
 {
     switch ($method) {
         case 'apache':
             foreach ($values as $varName => $value) {
                 /// @todo should remove any " or space chars in the value for proper parsing by updateperfstats.php
                 apache_note($varName, $value);
             }
             break;
         case 'piwik':
             $text = '';
             foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $i => $var) {
                 $text .= "\npiwikTracker.setCustomVariable( {$i}, \"{$var}\", \"{$values[$var]}\", \"page\" );";
             }
             $text .= "\npiwikTracker.trackPageView();";
             $output = preg_replace('/piwikTracker\\.trackPageView\\( *\\);?/', $text, $output);
             break;
         case 'googleanalytics':
             $text = '';
             foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $i => $var) {
                 $text .= "\n_gaq.push([{$i}, '{$var}', '{$values[$var]}', 3]);";
             }
             $text .= "\n_gaq.push(['_trackPageview']);";
             $output = preg_replace("/_gaq.push\\( *[ *['\"]_trackPageview['\"] *] *\\);?/", $text, $output);
             break;
         case 'logfile':
         case 'syslog':
             /// same format as Apache "combined" by default
             $size = self::$outputSize;
             if ($size == 0) {
                 $size = '-';
             }
             $text = eZPerfLoggerApacheLogger::apacheLogLine('combined', $size, self::$returnCode) . ' ';
             foreach ($values as $value) {
                 // do same as apache does: replace nulls with "-"
                 if ((string) $value === '') {
                     $text .= "- ";
                 } else {
                     /// @todo should remove any " or space chars in the value for proper parsing by updateperfstats.php
                     $text .= $value . " ";
                 }
             }
             if ($method == 'logfile') {
                 $text .= "\n";
                 file_put_contents(eZPerfLoggerINI::variable('logfileSettings', 'FileName'), $text, FILE_APPEND);
             } else {
                 // syslog: we use apache log format for lack of a better idea...
                 openlog("eZPerfLog", LOG_PID, LOG_USER);
                 syslog(LOG_INFO, $text);
             }
             break;
         case 'headers':
             $prefix = eZPerfLoggerINI::variable('HeadersSettings', 'HeaderPrefix');
             foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $i => $var) {
                 header($prefix . str_replace(array('(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', "\t"), '-', $var) . ': ' . $values[$var]);
             }
             break;
         case 'database':
         case 'csv':
         case 'storage':
             if ($method == 'csv') {
                 $storageClass = 'eZPerfLoggerCSVStorage';
             } else {
                 if ($method == 'database') {
                     $storageClass = 'eZPerfLoggerDBStorage';
                 } else {
                     $storageClass = eZPerfLoggerINI::variable('ParsingSettings', 'StorageClass');
                 }
             }
             /// @todo log error if storage class does not implement correct interface
             // when we deprecate php 5.2, we will be able to use $storageClass::insertStats...
             call_user_func(array($storageClass, 'insertStats'), array(array('url' => isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : $_SERVER["PHP_SELF"], 'ip' => is_callable('eZSys::clientIP') ? eZSys::clientIP() : eZSys::serverVariable('REMOTE_ADDR'), 'time' => time(), 'response_status' => self::$returnCode, 'response_size' => self::$outputSize, 'counters' => $values)));
             break;
             /// @todo !important log a warning for default case (unhandled log format)
     }
 }
Ejemplo n.º 11
0
 /**
  * Not too sure if it's gonna be needed... in which case do we want external code to allow to refresh the configResolver?
  * @param $resolver
  * @throws RuntimeException
  */
 public static function setConfigResolver($resolver)
 {
     if (!is_a($resolver, 'eZ\\Publish\\Core\\MVC\\ConfigResolverInterface')) {
         throw new RuntimeException('resolver object does not implement desired interface');
     }
     self::$configResolver = $resolver;
 }
 /**
  * Reads the data previously saved in the token file
  * @return mixed string|false
  */
 protected static function readUpdateToken($tokenFile)
 {
     $sys = eZSys::instance();
     $updateViewLogPath = $sys->varDirectory() . "/" . eZPerfLoggerINI::variable('FileSettings', 'LogDir', 'site.ini') . "/" . $tokenFile;
     if (is_file($updateViewLogPath)) {
         // nb: we need the newline at the end of the saved line for a proper comparison
         $lines = file($updateViewLogPath, FILE_SKIP_EMPTY_LINES);
         return isset($lines[2]) ? $lines[2] : false;
     }
     return false;
 }