Esempio n. 1
0
$extrahead = '';
$extrahead .= '<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../js/flot/excanvas.js"></script><![endif]-->';
$extrahead .= '<script language="javascript" type="text/javascript" src="../js/flot/jquery.js"></script>';
$extrahead .= '<script language="javascript" type="text/javascript" src="../js/flot/jquery.flot.js"></script>';
$extrahead .= '<script language="javascript" type="text/javascript" src="../js/flot/jquery.flot.time.js"></script>';
$extrahead .= '<script language="javascript" type="text/javascript" src="../js/flot/jquery.flot.selection.js"></script>';
$extrahead .= '<script language="javascript" type="text/javascript" src="../js/flot/jquery.flot.tooltip.js"></script>';
$extrahead .= '<script language="javascript" type="text/javascript" src="../js/flot/jquery.flot.byte.js"></script>';
$title = "Server Metrics";
require LIBWWWDIR . '/header.php';
requireAdmin();
echo "<h1>{$title}</h1>\n\n";
echo "<p>Metrics for the past 6 hours(averaged over 5minute intervals)</p>";
// Do this if it isn't done(for us it happens in init for the dynamodb session handler)
//require(__DIR__ . '/../../../aws_php_sdk/aws-autoloader.php');
$cw = Aws\CloudWatch\CloudWatchClient::factory(array('region' => 'us-east-1', 'version' => '2010-08-01'));
$plotnum = 0;
function get_metric_data($opts, $namespace, $metric, $metric_type, $unit_type, $dimensions = null)
{
    global $cw, $start_time, $end_time, $period;
    // http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-monitoring-2010-08-01.html#getmetricstatistics
    if ($dimensions == null) {
        $dimensions = [];
    } else {
        $dimensions = [$dimensions];
    }
    $datapoints = $cw->getMetricStatistics(['Namespace' => $namespace, 'MetricName' => $metric, 'Period' => $period, 'StartTime' => $start_time, 'EndTime' => $end_time, 'Statistics' => [$metric_type], 'Unit' => $unit_type, 'Dimensions' => $dimensions]);
    $d = array();
    foreach ($datapoints['Datapoints'] as $point) {
        // Create an array with all results with the timestamp as the key and the statistic as the value
        $time = strtotime($point['Timestamp'] . " UTC") * 1000;
Esempio n. 2
0
 /**
  * @param \DateTime $from
  * @param \DateTime $to
  * @param string $instanceId
  */
 public function getCpuUsageInfo($from, $to, $instanceId)
 {
     $cloudWatchClient = new Aws\CloudWatch\CloudWatchClient($this->config);
     return $cloudWatchClient->getMetricStatistics(array('Namespace' => 'AWS/EC2', 'MetricName' => 'CPUUtilization', 'Dimensions' => array(array('Name' => 'InstanceId', 'Value' => $instanceId)), 'StartTime' => $from->format('c'), 'EndTime' => $to->format('c'), 'Period' => 30 * 60, 'Statistics' => array('Average', 'Maximum', 'Minimum')))->get('Datapoints');
 }