|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Logger\Processors\SysloadProcessor |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link http://github.com/appserver-io/logger |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Logger\Processors; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Logger\LogMessageInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Processor that adds the actual system load to the message context. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link http://github.com/appserver-io/logger |
|
32
|
|
|
* @link http://www.appserver.io |
|
33
|
|
|
*/ |
|
34
|
|
|
class SysloadProcessor implements ProcessorInterface |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Adds the actual system load to the log message context. |
|
39
|
|
|
* |
|
40
|
|
|
* @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to add the system load |
|
41
|
|
|
* |
|
42
|
|
|
* @return string The processed log message |
|
43
|
|
|
* @see \AppserverIo\Logger\Processors\ProcessorInterface::process() |
|
44
|
|
|
*/ |
|
45
|
|
|
public function process(LogMessageInterface $logMessage) |
|
46
|
|
|
{ |
|
47
|
|
|
|
|
48
|
|
|
// load the sysload values |
|
49
|
|
|
$values = sys_getloadavg(); |
|
50
|
|
|
|
|
51
|
|
|
// create an array |
|
52
|
|
|
$sysload = array( |
|
53
|
|
|
'system_load_1' => array_shift($values), |
|
54
|
|
|
'system_load_5' => array_shift($values), |
|
55
|
|
|
'system_load_15' => array_shift($values) |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
// merge the values with the actual context instance |
|
59
|
|
|
$logMessage->mergeIntoContext($sysload); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|