Skip to content
This repository was archived by the owner on Apr 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added in-development/check_awsiops/aws.phar
Binary file not shown.
103 changes: 69 additions & 34 deletions in-development/check_awsiops/check_awsiops
Original file line number Diff line number Diff line change
@@ -1,49 +1,84 @@
#!/usr/bin/php -q
<?php
require 'vendor/autoload.php';


$options = getopt("K:S:i:v:r:");
if (!isset($options["K"])) { usage(); }
if (!isset($options["S"])) { usage(); }
if (!isset($options["v"]) && !isset($options["i"])) { usage(); }

$ebs_mode = isset($options["v"]);
$region = isset($options["r"]) ? $options["r"] : 'us-east-1';

define('AWS_KEY', $options["K"]);
define('AWS_SECRET_KEY', $options["S"]);

error_reporting(-1);

date_default_timezone_set('America/Denver');
$time_interval = date('o-m-d H:i:s', strtotime("10 minutes ago"));
$now = date('o-m-d H:i:s',time());


require 'aws.phar';
use Aws\CloudWatch\CloudWatchClient;
use Aws\Common\Enum\Region;



$cw = CloudWatchClient::factory(array(
//NED: 'key' => '1XA8TW1G8YTE3T98TZ02', 'secret' => 'ev3gmXmE7/QXllQY9YRy901DrwU5ylmhEuYN2bd8',
'key' => '0T7V2WEYKJGTQXF4AXG2', 'secret' => 'cy4ifN/0M1Ic+KMTcdxfmpY6opFTIYs9lJvyoyTu',
'region' => 'us-east-1',
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY,
'region' => $region
));

/*
$metrics = $cw->listMetrics(array(
'Namespace' => 'AWS/EC2',
// 'MetricName' => 'DiskReadOps',
// 'Dimensions' => array(array('Name' => 'InstanceId', 'Value' => 'i-f44f3e99')),
));
*/

$instanceid = 'i-e4c7dc8f';

$metrics = $cw->getMetricStatistics(array(
'Namespace' => 'AWS/EC2',
'MetricName' => 'DiskReadOps',
'Dimensions' => array(array(
'Name' => 'InstanceId', 'Value' => $instanceid
//'Name' => 'VolumeId', 'Value' => 'vol-116f9979'
)),
'StartTime' => '-1 hour',
'EndTime' => 'now',
'Period' => 300,
'Statistics' => array('Average', 'Sum'),
));

var_dump($metrics['Datapoints']);
if($ebs_mode){
$dimension = array('Name' => 'VolumeId', 'Value' => $options["v"]);
$metrics = array('VolumeReadBytes', 'VolumeWriteBytes','VolumeReadOps', 'VolumeWriteOps');
$namespace = 'AWS/EBS';
}
else{
$dimension = array('Name' => 'InstanceId', 'Value' => $options["i"]);
$metrics = array('DiskReadBytes', 'DiskWriteBytes','DiskReadOps', 'DiskWriteOps');
$namespace = 'AWS/EC2';
}

/*
DiskReadBytes
DiskWriteBytes
DiskReadOps
DiskWriteOps
*/
$metric_param = array(
'Namespace' => $namespace,
'MetricName' => 'CPUUtilization', //Dummy metric doesn't matter
'Dimensions' => array($dimension),
'StartTime' => $time_interval,
'EndTime' => $now,
'Period' => 60,
'Statistics' => array('SampleCount', 'Minimum', 'Maximum', 'Average', 'Sum')
);

echo "Instantant monthly IOPS \n";
$data_responses = array();

foreach ($metrics as $m ) {
$metric_param['MetricName'] = $m;
$data_responses[$m] = $cw->getMetricStatistics($metric_param)->get("Datapoints");
}

$output = "AWS IOPS OKAY; | ";
foreach ($metrics as $m) {
if ( isset($data_responses[$m][0]) ) {
$output .= $m . "=" . $data_responses[$m][0]["Sum"];
$output .= ($m == end($metrics)) ? "" : ";;;";
}
else{
$output .= $m . "=" . "0";
$output .= ($m == end($metrics)) ? "" : ";;;";
}
}

print_r($output);
exit(0);


function usage() {
print "\nusage: check_awsiops -K <accesskey> -S <secretkey> -v <volume-id> -i <instance-id> -r <aws-region> (optional)\n\n" .
"If given both a VolumeId and an InstanceId, this script get will metrics for the EBS volume (-v).";
exit(1);
}
5 changes: 0 additions & 5 deletions in-development/check_awsiops/composer.json

This file was deleted.

239 changes: 0 additions & 239 deletions in-development/check_awsiops/composer.lock

This file was deleted.

Binary file removed in-development/check_awsiops/composer.phar
Binary file not shown.
7 changes: 0 additions & 7 deletions in-development/check_awsiops/vendor/autoload.php

This file was deleted.

18 changes: 0 additions & 18 deletions in-development/check_awsiops/vendor/aws/aws-sdk-php/.gitignore

This file was deleted.

Loading