|
1
|
|
|
<?php |
|
2
|
|
|
namespace CloudWatchScript\Plugins; |
|
3
|
|
|
|
|
4
|
|
|
use CloudWatchScript\AbstractMonitoring; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Check Solr using ping URL. |
|
8
|
|
|
* Add and configure the folliwong lines to the config file |
|
9
|
|
|
* "Memory" : { |
|
10
|
|
|
* "name" : "Name of metric and alarm", |
|
11
|
|
|
* "maxUsed": 90, |
|
12
|
|
|
* "namespace": "Metric/Namespace", |
|
13
|
|
|
* "description": "Description" |
|
14
|
|
|
* } |
|
15
|
|
|
*/ |
|
16
|
|
|
class MemoryMonitoring extends AbstractMonitoring |
|
17
|
|
|
{ |
|
18
|
|
|
private $maxUsed; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param array $config |
|
22
|
|
|
* @param String $name |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct($config, $name) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($config, $name); |
|
27
|
|
|
$this->maxUsed = $this->config->maxUsed; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return integer Percentage of use memory |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getMetric() |
|
34
|
|
|
{ |
|
35
|
|
|
$free = shell_exec('free'); |
|
36
|
|
|
$free = (string)trim($free); |
|
37
|
|
|
$free_arr = explode("\n", $free); |
|
38
|
|
|
$mem = explode(" ", $free_arr[1]); |
|
39
|
|
|
$mem = array_filter($mem); |
|
40
|
|
|
$mem = array_merge($mem); |
|
41
|
|
|
// ( Memory used - cached ) / Total memory |
|
42
|
|
|
return ( $mem[2] - $mem[6] )/$mem[1]*100; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return string "None" |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getUnit() |
|
49
|
|
|
{ |
|
50
|
|
|
return "Percent"; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array Alarm max for memory used |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getAlarms() |
|
57
|
|
|
{ |
|
58
|
|
|
return array( |
|
59
|
|
|
array("ComparisonOperator" => "GreaterThanThreshold", |
|
60
|
|
|
"Threshold" => $this->maxUsed, |
|
61
|
|
|
"Name" => $this->name . " exceed " . $this->config->maxUsed . " %") |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|