How to log dimension like AWS CloudWatch bundled metric - php

Can anyone explain how to use the AWS PHP SDK to log the metric in the style like the above screen.
I use the following PHP code but the select menu is showing "ELB: AvaliabiltyZone", how to make it show "Aggregated by AvaliabiltyZone"? What is the logic used here?
$response = $cw->put_metric_data("ELB", array(
array(
"MetricName" => "Latency",
"Dimensions" => array(
array("Name" => "AvaliabiltyZone" , "Value" => "us-east-1c")
),
"Timestamp" => "now",
"Value" => 1,
"Unit" => "None"
),
));

AvaliabiltyZone
You misspelled "AvailabilityZone"
This maybe won't answer the question, but it might fix some things...

$cw = new AmazonCloudWatch();
$cw->set_region('monitoring.'.$region.'amazonaws.com');
$res1 = $CW->put_metric_data('Sys/RDS' ,
array(array('MetricName' => 'Uptime' ,
'Dimensions' => array(array('Name' => 'AvaliabiltyZone',
'Value' => 'us-east-1c')),
'Value' => $Uptime,
'Unit' => 'Seconds')));
Click Here

Related

Facebook Marketing API get campaign info

I'm using the code autogenerated by facebook to try and connect to the marketing API to get campaign stats. In doing so, I'm getting:
Uncaught FacebookAds\Http\Exception\AuthorizationException: (#100) results, actions:like, video_play_actions:video_view, video_avg_time_watched_actions:video_view, unique_actions:link_click are not valid for fields param.
$fields = array(
'results',
'reach',
'actions:like',
'video_play_actions:video_view',
'video_avg_time_watched_actions:video_view',
'unique_actions:link_click',
);
var_dump($fields);
$params = array(
'level' => 'campaign',
'filtering' => array(array('field' => 'campaign.delivery_info','operator' => 'IN','value' => array('active'))),
'breakdowns' => array(),
'time_range' => array('since' => '2017-05-19','until' => '2019-05-19'),
);
echo json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
Above I used campaign.delivery_info per this answer. I've also tried (per the auto-generated code):
'filtering' => array(array('field' => 'delivery_info','operator' => 'IN','value' => array('active')))
Seems you are asking for old values field, try this:
$fields = array(
'reach',
'actions',
'video_play_actions',
'video_avg_time_watched_actions',
'outbound_clicks',
);
Hope this help
NB: results field is not available

MongoDB -> DynamoDB Migration

All,
I am attempting to migrate roughly 6GB of Mongo data that is comprised of hundreds of collections to DynamoDB. I have written some scripts using the AWS PHP SDK and am able to port over very small collections but when I try ones that have more than 20k documents (still a very small collection all things considered) it either takes an outrageous amount of time or quietly fails.
Does anyone have some tips/tricks for taking data from Mongo (or any other NoSQL DB) and migrating it to Dynamo, or any other NoSQL DB. I feel like this should be relatively easy because the documents are extremely flat/simple.
Any thoughts/suggestions would be much appreciated!
Thanks!
header.php
<?
require './aws-autoloader.php';
require './MongoGet.php';
set_time_limit(0);
use \Aws\DynamoDb\DynamoDbClient;
$client = \Aws\DynamoDb\DynamoDbClient::factory(array(
'key' => 'MY_KEY',
'secret' => 'MY_SECRET',
'region' => 'MY_REGION',
'base_url' => 'http://localhost:8000'
));
$collection = "AccumulatorGasPressure4093_raw";
function nEcho($str) {
echo "{$str}<br>\n";
}
echo "<pre>";
test-store.php
<?
include('test-header.php');
nEcho("Creating table(s)...");
// create test table
$client->createTable(array(
'TableName' => $collection,
'AttributeDefinitions' => array(
array(
'AttributeName' => 'id',
'AttributeType' => 'N'
),
array(
'AttributeName' => 'count',
'AttributeType' => 'N'
)
),
'KeySchema' => array(
array(
'AttributeName' => 'id',
'KeyType' => 'HASH'
),
array(
'AttributeName' => 'count',
'KeyType' => 'RANGED'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20
)
));
$result = $client->describeTable(array(
'TableName' => $collection
));
nEcho("Done creating table...");
nEcho("Getting data from Mongo...");
// instantiate class and get data
$mGet = new MongoGet();
$results = $mGet->getData($collection);
nEcho ("Done retrieving Mongo data...");
nEcho ("Inserting data...");
$i = 0;
foreach($results as $result) {
$insertResult = $client->putItem(array(
'TableName' => $collection,
'Item' => $client->formatAttributes(array(
'id' => $i,
'date' => $result['date'],
'value' => $result['value'],
'count' => $i
)),
'ReturnConsumedCapacity' => 'TOTAL'
));
$i++;
}
nEcho("Done Inserting, script ending...");
I suspect that you are being throttled by DynamoDB, especially if your tables' throughputs are low. The SDK retries the requests, up to 11 times per request, but eventually, the requests fail, which should throw an exception.
You should take a look at the WriteRequestBatch object. This object is basically a queue of items that get sent in batches, but any items that fail to transfer are re-queued automatically. Should provide a more robust solution for what you are doing.

php fedex set signature Label ADULT

I am working on wordpress site and using woocommerce extension http://www.woothemes.com/products/fedex-shipping-module/
I am Passing the values Signature value to adults. But it is not working
Please correct me where i am wrong
$request['RequestedShipment']['RateRequestTypes'] = $this->request_type;
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
$request['RequestedShipment']['SpecialServicesRequested'][] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
`
Do i need to change something from the from the RateService_v13.wsdl file
Please suggest
Thanks
I resolved this issue
For further user having the same issue can resolve this by below code
$item['SpecialServicesRequested'] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
$request['RequestedShipment']['RequestedPackageLineItems'][] = $item;
If Suppose anyone is using Fedex Integration with Laravel you may use below code.
In place of _DIRECT you may use _ADULT or any other option.
$packageLineItem1 = new FedexShipServiceCT\RequestedPackageLineItem();
$packageLineItem1
->setSequenceNumber(1)
->setItemDescription('Product')
->setSpecialServicesRequested(new FedexShipServiceCT\PackageSpecialServicesRequested(array(
'SignatureOptionDetail' => new FedexShipServiceCT\SignatureOptionDetail(array(
'OptionType' => FedexShipServiceST\SignatureOptionType::_DIRECT
))
)))
->setDimensions(new FedexShipServiceCT\Dimensions(array(
'Width' => 1,
'Height' => 1,
'Length' => 1,
'Units' => FedexShipServiceST\LinearUnits::_IN
)))
->setWeight(new FedexShipServiceCT\Weight(array(
'Value' => 1,
'Units' => FedexShipServiceST\WeightUnits::_LB
)));
Thanks

Medoo - Updating table row matching field

I am using Medoo but know very little php, the update below works fine but I only want it to update when the clientId matches what is posted:
$database->update("clientInfo", array(
"businessName" => $_POST['businessName'],
"contactName" => $_POST['contactName'],
"businessEmail" => $_POST['businessEmail'],
"businessPhone" => $_POST['businessPhone'],
"businessWebsite" => $_POST['businessWebsite'],
"businessAddress" => $_POST['businessAddress'],
"businessAddress2" => $_POST['businessAddress2'],
"businessCity" => $_POST['businessCity'],
"businessState" => $_POST['businessState'],
"businessZip" => $_POST['businessZip']
));
//$_POST["clientId"];
I am using a newer version of PHP and am a little confused on the syntax, here is how it is with older versions of PHP
http://medoo.in/api/update
I assume you have clientId field in that table, you can try:
$database->update("clientInfo", array(
"businessName" => $_POST['businessName'],
"contactName" => $_POST['contactName'],
"businessEmail" => $_POST['businessEmail'],
"businessPhone" => $_POST['businessPhone'],
"businessWebsite" => $_POST['businessWebsite'],
"businessAddress" => $_POST['businessAddress'],
"businessAddress2" => $_POST['businessAddress2'],
"businessCity" => $_POST['businessCity'],
"businessState" => $_POST['businessState'],
"businessZip" => $_POST['businessZip']
), array(
"clientId" => $_POST['clientId']
));
Hope it helps.

Improving/editing JSON from CakePHP 2 for Ext-JS 4

Ok guys, I've got this from CakePHP:
array(
(int) 0 => array(
'Worker' => array(
'id' => '1',
'username' => 'davorlozic',
'first_name' => 'Davor',
'last_name' => 'Lozic',
'active' => true,
'created' => '2012-05-12 10:39:05',
'modified' => '2012-05-12 10:39:05'
)
),
(int) 1 => array(
'Worker' => array(
'id' => '2',
'username' => 'markomarkovic',
'first_name' => 'Marko',
'last_name' => 'Markovic',
'active' => true,
'created' => '2012-05-12 10:39:20',
'modified' => '2012-05-12 10:39:20'
)
So, when I encode it with JSON_ENCODE I get this:
BUT I NEED TO GET THIS: HOW? (this shape, not these data)
{
"success": true,
"Workers": [
{"id": 1, "name": 'Ed', "email": "ed#sencha.com"},
{"id": 2, "name": 'Tommy', "email": "tommy#sencha.com"}
]
}
Can I do something with the FIRST array? Some shifting or something? Thank you! :)
your current problem is that CakePHP and ExtJS use different data structures for read requests. You will probably later figure out that there are a lot more issues, and it can become quite tricky. I have had many CakePHP and ExtJS projects always facing these problems, it also gets really annoying to have to create custom json views for each request type and controller.
That's why I started together with some colleges Bancha, which automates all these things for you. The best place is to start at banchaproject.org and see the samples and docs.
For any questions feel free to write to support#banchaproject.org
Best regards
Roland

Categories