@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function addPattern($pattern, $isRegExp = false) |
| 62 | 62 | { |
| 63 | - $this->patterns[ $pattern ] = $isRegExp; |
|
| 63 | + $this->patterns[$pattern] = $isRegExp; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function removePattern($pattern) |
| 70 | 70 | { |
| 71 | - unset($this->patterns[ $pattern ]); |
|
| 71 | + unset($this->patterns[$pattern]); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | if ($matchedCount>0 && $this->diObj->getLogger()) { |
| 93 | 93 | $this->diObj->getLogger()->error( |
| 94 | 94 | 'FileWatch found matched line!' |
| 95 | - .' LINE >>> ' . $line . ' <<<' |
|
| 95 | + .' LINE >>> '.$line.' <<<' |
|
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | return $matchedCount; |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | { |
| 106 | 106 | try { |
| 107 | 107 | if (is_file($this->fileToWatch)===false) { |
| 108 | - throw new \Exception("File to watch \"". $this->fileToWatch ."\" not found!"); |
|
| 108 | + throw new \Exception("File to watch \"".$this->fileToWatch."\" not found!"); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | clearstatcache(true); |
| 112 | - $checkPointFile = $this->checkPointFile?:$this->fileToWatch . '.checkpoint'; |
|
| 113 | - $checkPoint = is_file($checkPointFile)?intval(file_get_contents($checkPointFile)):0; |
|
| 112 | + $checkPointFile = $this->checkPointFile ?: $this->fileToWatch.'.checkpoint'; |
|
| 113 | + $checkPoint = is_file($checkPointFile) ? intval(file_get_contents($checkPointFile)) : 0; |
|
| 114 | 114 | $fileSize = filesize($this->fileToWatch); |
| 115 | 115 | if ($fileSize==0) { |
| 116 | 116 | return [ |
@@ -122,17 +122,17 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | $fp = fopen($this->fileToWatch, 'r'); |
| 124 | 124 | if (!$fp) { |
| 125 | - throw new \Exception("File to watch \"". $this->fileToWatch ."\" could not opened for read!"); |
|
| 125 | + throw new \Exception("File to watch \"".$this->fileToWatch."\" could not opened for read!"); |
|
| 126 | 126 | } |
| 127 | 127 | $seekStatus = fseek($fp, $checkPoint); |
| 128 | 128 | if ($seekStatus==-1) { |
| 129 | - throw new \Exception("Seek to \"". $checkPoint ."\" failed for \"". $this->fileToWatch ."\"!"); |
|
| 129 | + throw new \Exception("Seek to \"".$checkPoint."\" failed for \"".$this->fileToWatch."\"!"); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $newCheckPoint = $checkPoint; |
| 133 | 133 | $foundPatternsCount = 0; |
| 134 | - while (($line = fgets($fp)) !== false) { |
|
| 135 | - if (($newCheckPoint+strlen($line))>$fileSize) { |
|
| 134 | + while (($line = fgets($fp))!==false) { |
|
| 135 | + if (($newCheckPoint + strlen($line))>$fileSize) { |
|
| 136 | 136 | break; |
| 137 | 137 | } |
| 138 | 138 | $foundPatternsCount += $this->checkLine($line); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | ]; |
| 147 | 147 | } catch (\Exception $e) { |
| 148 | 148 | if ($this->diObj->getLogger()) { |
| 149 | - $this->diObj->getLogger()->error('FileWatch thrown exception! ExcpMsg: ' . $e->getMessage()); |
|
| 149 | + $this->diObj->getLogger()->error('FileWatch thrown exception! ExcpMsg: '.$e->getMessage()); |
|
| 150 | 150 | } |
| 151 | 151 | return [ |
| 152 | 152 | $this->createNewMetric('FileWatchException', 'Count', 1) |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function setSwapCheckOn($swapCheckOn) |
| 23 | 23 | { |
| 24 | - $this->swapCheckOn = $swapCheckOn?true:false; |
|
| 24 | + $this->swapCheckOn = $swapCheckOn ? true : false; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -38,18 +38,18 @@ discard block |
||
| 38 | 38 | list($key, $val) = explode(':', $memInfoLine); |
| 39 | 39 | $key = trim($key); |
| 40 | 40 | $val = intval(trim($val)); |
| 41 | - $memInfo[ $key ] = $val; |
|
| 41 | + $memInfo[$key] = $val; |
|
| 42 | 42 | } |
| 43 | 43 | $memInfo['MemAvail'] = $memInfo['MemFree'] + $memInfo['Buffers'] + $memInfo['Cached']; |
| 44 | 44 | $memInfo['MemUsed'] = $memInfo['MemTotal'] - $memInfo['MemAvail']; |
| 45 | - $memInfo['MemUtil'] = $memInfo['MemTotal']>0?ceil((100*$memInfo['MemUsed']/$memInfo['MemTotal'])):100; |
|
| 45 | + $memInfo['MemUtil'] = $memInfo['MemTotal']>0 ? ceil((100*$memInfo['MemUsed']/$memInfo['MemTotal'])) : 100; |
|
| 46 | 46 | |
| 47 | - $metrics = [ $this->createNewMetric('MemoryUsage', 'Percent', $memInfo['MemUtil']) ]; |
|
| 47 | + $metrics = [$this->createNewMetric('MemoryUsage', 'Percent', $memInfo['MemUtil'])]; |
|
| 48 | 48 | |
| 49 | 49 | if ($this->isSwapCheckOn()) { |
| 50 | 50 | $memInfo['SwapUsed'] = $memInfo['SwapTotal'] - $memInfo['SwapFree']; |
| 51 | 51 | $memInfo['SwapUtil'] = $memInfo['SwapTotal']>0 |
| 52 | - ?ceil((100*$memInfo['SwapUsed']/$memInfo['SwapTotal'])) |
|
| 52 | + ? ceil((100*$memInfo['SwapUsed']/$memInfo['SwapTotal'])) |
|
| 53 | 53 | :100; |
| 54 | 54 | $metrics[] = $this->createNewMetric('SwapUsage', 'Percent', $memInfo['SwapUtil']); |
| 55 | 55 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | } else { |
| 59 | 59 | if ($this->diObj->getLogger()) { |
| 60 | 60 | $this->diObj->getLogger()->error( |
| 61 | - '/proc/meminfo parse failed!, RETVAL: ' . $retVal . ', OUT: ' . implode('|', $memInfoLines) |
|
| 61 | + '/proc/meminfo parse failed!, RETVAL: '.$retVal.', OUT: '.implode('|', $memInfoLines) |
|
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | 64 | return false; |
@@ -33,19 +33,19 @@ |
||
| 33 | 33 | $osName = $this->diObj->getCommandRunner()->getReturnValue(); |
| 34 | 34 | switch ($osName) { |
| 35 | 35 | case 'Darwin': |
| 36 | - $this->diObj->getCommandRunner()->execute('/bin/df -k -l ' . $this->mountPoint . " | awk '{print $8}'"); |
|
| 36 | + $this->diObj->getCommandRunner()->execute('/bin/df -k -l '.$this->mountPoint." | awk '{print $8}'"); |
|
| 37 | 37 | break; |
| 38 | 38 | case 'Linux': |
| 39 | - $this->diObj->getCommandRunner()->execute('/bin/df -k -l ' . $this->mountPoint . " | awk '{print $5}'"); |
|
| 39 | + $this->diObj->getCommandRunner()->execute('/bin/df -k -l '.$this->mountPoint." | awk '{print $5}'"); |
|
| 40 | 40 | break; |
| 41 | 41 | default: |
| 42 | - $this->diObj->getCommandRunner()->execute('/bin/df -k -l ' . $this->mountPoint . " | awk '{print $5}'"); |
|
| 42 | + $this->diObj->getCommandRunner()->execute('/bin/df -k -l '.$this->mountPoint." | awk '{print $5}'"); |
|
| 43 | 43 | break; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $diskUtil = intval($this->diObj->getCommandRunner()->getReturnValue()); |
| 47 | 47 | if ($diskUtil>0) { |
| 48 | - return [ $this->createNewMetric('DiskUsage', 'Percent', $diskUtil) ]; |
|
| 48 | + return [$this->createNewMetric('DiskUsage', 'Percent', $diskUtil)]; |
|
| 49 | 49 | } else { |
| 50 | 50 | return null; |
| 51 | 51 | } |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function __construct(DI $diObj, $namespace = null, $cronExpression = '') |
| 32 | 32 | { |
| 33 | - self::$equalsFunc = function ($string, $needle) { |
|
| 33 | + self::$equalsFunc = function($string, $needle) { |
|
| 34 | 34 | return $string==$needle; |
| 35 | 35 | }; |
| 36 | 36 | |
| 37 | - self::$containsFunc = function ($string, $needle) { |
|
| 37 | + self::$containsFunc = function($string, $needle) { |
|
| 38 | 38 | return strpos($string, $needle)!==false; |
| 39 | 39 | }; |
| 40 | 40 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function addHeader($header, $val) |
| 97 | 97 | { |
| 98 | - $this->headers[ $header ] = $val; |
|
| 98 | + $this->headers[$header] = $val; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function removeHeader($header) |
| 105 | 105 | { |
| 106 | - unset($this->headers[ $header ]); |
|
| 106 | + unset($this->headers[$header]); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | public function setBodyToCheck($bodyToCheck, $checkFunc = null) |
| 170 | 170 | { |
| 171 | 171 | $this->bodyToCheck = $bodyToCheck; |
| 172 | - $this->bodyCheckFunc = $checkFunc?$checkFunc:self::$equalsFunc; |
|
| 172 | + $this->bodyCheckFunc = $checkFunc ? $checkFunc : self::$equalsFunc; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | if (!$this->url || !$this->method) { |
| 234 | 234 | if ($this->diObj->getLogger()) { |
| 235 | 235 | $this->diObj->getLogger()->error( |
| 236 | - (!$this->url)?'Url is not defined to check!':'Method is not defined to check!' |
|
| 236 | + (!$this->url) ? 'Url is not defined to check!' : 'Method is not defined to check!' |
|
| 237 | 237 | ); |
| 238 | 238 | } |
| 239 | 239 | return false; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | 'http_errors' => false, |
| 246 | 246 | 'connect_timeout' => $this->timeout, |
| 247 | 247 | 'timeout' => $this->timeout, |
| 248 | - 'on_stats' => function (TransferStats $stats) { |
|
| 248 | + 'on_stats' => function(TransferStats $stats) { |
|
| 249 | 249 | $this->responseTime = $stats->getTransferTime(); |
| 250 | 250 | } |
| 251 | 251 | ]); |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | } catch (\Exception $e) { |
| 261 | 261 | if ($this->diObj->getLogger()) { |
| 262 | - $this->diObj->getLogger()->error('Guzzle Http client thrown exception! Msg: ' . $e->getMessage()); |
|
| 262 | + $this->diObj->getLogger()->error('Guzzle Http client thrown exception! Msg: '.$e->getMessage()); |
|
| 263 | 263 | } |
| 264 | 264 | return [$this->createNewMetric('HttpCheckFail', 'Count', 1)]; |
| 265 | 265 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function getServiceName() |
| 23 | 23 | { |
| 24 | - return $this->serviceName?:$this->server . ':' . $this->port; |
|
| 24 | + return $this->serviceName ?: $this->server.':'.$this->port; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | if ($fp) { |
| 75 | 75 | fclose($fp); |
| 76 | 76 | return [ |
| 77 | - $this->createNewMetric($this->getServiceName() . 'CheckFail', 'Count', 0) |
|
| 77 | + $this->createNewMetric($this->getServiceName().'CheckFail', 'Count', 0) |
|
| 78 | 78 | ]; |
| 79 | 79 | } |
| 80 | 80 | } catch (\Exception $e) { |
| 81 | 81 | if ($this->diObj->getLogger()) { |
| 82 | 82 | $this->diObj->getLogger()->error( |
| 83 | 83 | 'Service port check thrown exception!' |
| 84 | - .' Service:' . $this->getServiceName() . ', Msg: ' . $e->getMessage() |
|
| 84 | + .' Service:'.$this->getServiceName().', Msg: '.$e->getMessage() |
|
| 85 | 85 | ); |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | - return [$this->createNewMetric($this->getServiceName() . 'CheckFail', 'Count', 1)]; |
|
| 88 | + return [$this->createNewMetric($this->getServiceName().'CheckFail', 'Count', 1)]; |
|
| 89 | 89 | } |
| 90 | 90 | } |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | } |
| 103 | 103 | } catch (\Exception $e) { |
| 104 | 104 | if ($this->diObj->getLogger()) { |
| 105 | - $this->diObj->getLogger()->error('Memcached client thrown exception! ExcpMsg: ' . $e->getMessage()); |
|
| 105 | + $this->diObj->getLogger()->error('Memcached client thrown exception! ExcpMsg: '.$e->getMessage()); |
|
| 106 | 106 | } |
| 107 | 107 | return [ |
| 108 | 108 | $this->createNewMetric('MemcachedCheckFail', 'Count', 1) |
@@ -237,11 +237,11 @@ |
||
| 237 | 237 | 'MetricName' => $metric->getName(), |
| 238 | 238 | 'Unit' => $metric->getUnit(), |
| 239 | 239 | 'Value' => $metric->getValue(), |
| 240 | - 'Timestamp' => gmdate('Y-m-d') . 'T' . gmdate('H:i:s') . 'Z' |
|
| 240 | + 'Timestamp' => gmdate('Y-m-d').'T'.gmdate('H:i:s').'Z' |
|
| 241 | 241 | ]; |
| 242 | 242 | } |
| 243 | 243 | $this->cloudWatchClient->putMetricData([ |
| 244 | - 'Namespace' => $namespace?:$this->getNamespace(), |
|
| 244 | + 'Namespace' => $namespace ?: $this->getNamespace(), |
|
| 245 | 245 | 'MetricData' => $metricData |
| 246 | 246 | ]); |
| 247 | 247 | } |
@@ -6,16 +6,16 @@ |
||
| 6 | 6 | { |
| 7 | 7 | public function debug($msg) |
| 8 | 8 | { |
| 9 | - echo "[".date('Y-m-d H:i:s')."][DEBUG] " . $msg . "\n"; |
|
| 9 | + echo "[".date('Y-m-d H:i:s')."][DEBUG] ".$msg."\n"; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | public function info($msg) |
| 13 | 13 | { |
| 14 | - echo "[".date('Y-m-d H:i:s')."][INFO] " . $msg . "\n"; |
|
| 14 | + echo "[".date('Y-m-d H:i:s')."][INFO] ".$msg."\n"; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function error($msg) |
| 18 | 18 | { |
| 19 | - echo "[".date('Y-m-d H:i:s')."][ERROR] " . $msg . "\n"; |
|
| 19 | + echo "[".date('Y-m-d H:i:s')."][ERROR] ".$msg."\n"; |
|
| 20 | 20 | } |
| 21 | 21 | } |
@@ -28,10 +28,10 @@ |
||
| 28 | 28 | $action = substr($name, 0, 3); |
| 29 | 29 | $objName = substr($name, 3); |
| 30 | 30 | if ($action=='set') { |
| 31 | - $this->objList[ $objName ] = $arguments[0]; |
|
| 31 | + $this->objList[$objName] = $arguments[0]; |
|
| 32 | 32 | return true; |
| 33 | 33 | } else { |
| 34 | - return isset($this->objList[ $objName ])?$this->objList[ $objName ]:null; |
|
| 34 | + return isset($this->objList[$objName]) ? $this->objList[$objName] : null; |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | } |