|
I'm not sure if this should really go here since it might be more of an AWS question, but I don't see an AWS/ thread so maybe one of you fine folks have an answer for me. My AWS forum post posted:I'm attempting to pull a custom metric from the Cloudwatch API via PHP and haven't been able to get it working properly. I can pull standard metrics just fine, so it's not an issue with improperly configured IAM roles or anything. I think maybe the actual statistic I'm requesting is wrong but I think I've tried it with every statistic option available. I'm trying to get the custom DiskSpaceUtilization metric in the System/Linux namespace. I have the Cloudwatch perl scripts installed on my instance and they're reporting disk statistics every 5 minutes via a cron job that I can see just fine via the Cloudwatch GUI. Requesting the custom metric via the API doesn't give me an error, it just return an empty Datapoints array. This one works php:<?php require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php'; use Aws\CloudWatch\CloudWatchClient; use Aws\Exception\AwsException; $client = new CloudWatchClient([ 'region' => 'us-west-2', 'version' => 'latest' ]); try { $result = $client->getMetricStatistics(array( 'Namespace' => 'AWS/EC2', 'MetricName' => 'NetworkPacketsOut', 'Dimensions' => array( array( 'Name' => 'InstanceId', 'Value' => 'i-093348c63a21c8068' ), ), 'StartTime' => strtotime('-6 hours'), 'EndTime' => strtotime('now'), 'Period' => 60, 'Statistics' => array('Average'), )); echo '<pre>'; var_dump($result); echo '</pre>'; } catch (AwsException $e) { error_log($e->getMessage()); } ?> php:<?php require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php'; use Aws\CloudWatch\CloudWatchClient; use Aws\Exception\AwsException; $client = new CloudWatchClient([ 'region' => 'us-west-2', 'version' => 'latest' ]); try { $result = $client->getMetricStatistics(array( 'Namespace' => 'System/Linux', 'MetricName' => 'DiskSpaceUtilization', 'Dimensions' => array( array( 'Name' => 'InstanceId', 'Value' => 'i-093348c63a21c8068' ), array( 'Name' => 'MounthPath', 'Value' => '/' ), array( 'Name' => 'Filesystem', 'Value' => '/dev/xda1/' ), ), 'StartTime' => strtotime('-6 hours'), 'EndTime' => strtotime('now'), 'Period' => 60, 'Statistics' => array('Maximum', 'Minimum', 'Average', 'Sum', 'SampleCount'), )); echo '<pre>'; var_dump($result); echo '</pre>'; } catch (AwsException $e) { error_log($e->getMessage()); } ?>
|
# ¿ Oct 14, 2017 00:14 |
|
|
# ¿ May 15, 2024 02:09 |
|
Well thank you for pointing that out, I'm a dummy, but unfortunately fixing it didn't actually fix the issue (and I'm actually pretty sure I had tried it the right way at some point but screwed it up when I was copy/pasting things in and out of that dimensions array). I may just move on to something else, building a bespoke AWS dashboard seemed like a fun way to learn php but I'm not doing anything that isn't already done much better by the Cloudwatch dashboard anyway. I learned how to install/use the AWS PHP SDK, maybe I should just build a page that will let me provision/destroy hosts from a single page. Thanks for taking a look at it.
|
# ¿ Oct 14, 2017 17:42 |
|
Acidian posted:Also, in the server {} part, I only added the top line, but what is the second line for [::]:? I'll let php experts answer the other parts, but as for this, it's just setting it to listen on both ipv4 and ipv6. It's usually considered best practice to remove ipv6 if you're sure you won't need it as it reduces attack surface, but for a test server with basic configurations it's probably not really necessary.
|
# ¿ Mar 14, 2018 20:37 |
|
You can pay someone for a certificate or you can use Let's Encrypt for free. I'd recommend LE unless you need something more exotic like a wildcard cert or extended validation.
|
# ¿ Apr 22, 2018 21:30 |