fauguste /
cloudwatch-script-php
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | * "Disk" : { |
||
| 10 | * "name" : "Name of metric and alarm", |
||
| 11 | * "partition" : "/" |
||
| 12 | * "maxUtil": 90, |
||
| 13 | * "namespace": "Metric/Namespace", |
||
| 14 | * "description": "Description" |
||
| 15 | * } |
||
| 16 | */ |
||
| 17 | class DiskMonitoring extends AbstractMonitoring |
||
| 18 | { |
||
| 19 | private $maxUtil; |
||
| 20 | private $partition; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param array $config |
||
| 24 | * @param String $name |
||
| 25 | */ |
||
| 26 | public function __construct($config, $name) |
||
| 27 | { |
||
| 28 | parent::__construct($config, $name); |
||
| 29 | $this->maxUtil = $this->config->maxUtil; |
||
| 30 | $this->partition = $this->config->partition; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return integer Percentage of use disk space |
||
| 35 | */ |
||
| 36 | public function getMetric() |
||
| 37 | { |
||
| 38 | return 100 - intval(100 * ( disk_free_space($this->partition) / disk_total_space($this->partition))); |
||
| 39 | |||
| 40 | } |
||
| 41 | /** |
||
| 42 | * @return string "None" |
||
| 43 | */ |
||
| 44 | public function getUnit() |
||
| 45 | { |
||
| 46 | return "Percent"; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return array Alarm min and max for number of apache process |
||
| 51 | */ |
||
| 52 | View Code Duplication | public function getAlarms() |
|
|
0 ignored issues
–
show
|
|||
| 53 | { |
||
| 54 | return array( |
||
| 55 | array("ComparisonOperator" => "GreaterThanThreshold", |
||
| 56 | "Threshold" => $this->maxUtil, |
||
| 57 | "Name" => $this->name . " exceed " . $this->config->maxUtil . " %") |
||
| 58 | ); |
||
| 59 | } |
||
| 60 | } |
||
| 61 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.