Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
BallerBallerDillz
Jun 11, 2009

Cock, Rules, Everything, Around, Me
Scratchmo
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/:yayclod: 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.

I've attached copies of both working code for a generic metric along with the non-working code for the custom metric. I'm still learning PHP so I may just be making an obvious error, but I'd appreciate it if someone can take a look at it and see if that's the case. If it's just not possible that would be good to know too. Thank you very much.

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());
}

?>

This one doesn't
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());
}

?>

Adbot
ADBOT LOVES YOU

BallerBallerDillz
Jun 11, 2009

Cock, Rules, Everything, Around, Me
Scratchmo
:smithicide:

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.

BallerBallerDillz
Jun 11, 2009

Cock, Rules, Everything, Around, Me
Scratchmo

Acidian posted:

Also, in the server {} part, I only added the top line, but what is the second line for [::]:?
code:
 listen 80 default_server;
 listen [::]:80 default_server;


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.

BallerBallerDillz
Jun 11, 2009

Cock, Rules, Everything, Around, Me
Scratchmo
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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply