PHP code example of alexvergara / laravel-aws-timestream
1. Go to this page and download the library: Download alexvergara/laravel-aws-timestream library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alexvergara / laravel-aws-timestream example snippets
use AlexVergara\AwsTimestream\TimestreamService;
use AlexVergara\AwsTimestream\TimestreamBuilder;
use AlexVergara\AwsTimestream\Dto\TimestreamReaderDto;
public function overview(TimestreamService $timestreamService)
{
$queryBuilder = TimestreamBuilder::query()
->select('*')
->from("database-name", 'table-name')
->whereAgo('time', '24h', '>=')
->whereNotIn('measure_value::varchar', ['reviewer', 'open', 'closed'])
->orderBy('time', 'desc');
TimestreamReaderDto::make($queryBuilder);
// response from Aws timestream
return $timestreamService->query($timestreamReader)
}
use AlexVergara\AwsTimestream\TimestreamService;
use AlexVergara\AwsTimestream\TimestreamBuilder;
use AlexVergara\AwsTimestream\Dto\TimestreamReaderDto;
public function overview(TimestreamService $timestreamService)
{
$queryBuilder = TimestreamBuilder::query()
->select('*')
->whereAgo('time', '24h', '>=')
->whereNotIn('measure_value::varchar', ['reviewer', 'open', 'closed'])
->orderBy('time', 'desc');
TimestreamReaderDto::make($queryBuilder, 'table-name');
// response from Aws timestream
return $timestreamService->query($timestreamReader)
}
use AlexVergara\AwsTimestream\TimestreamService;
use AlexVergara\AwsTimestream\Dto\TimestreamWriterDto;
use AlexVergara\AwsTimestream\TimestreamBuilder;
public function ingest(TimestreamService $timestreamService)
{
$metrics = [
'measure_name' => 'cpu_usage',
'measure_value' => 80,
'time' => Carbon::now(),
'dimensions' => [
'mac_address' => 'randomstring',
'ref' => 'refs',
],
];
$payload = TimestreamBuilder::payload(
$metrics['measure_name'],
$metrics['measure_value'],
$metrics['time'],
'VARCHAR',
$metrics['dimensions'],
)->toArray();
$timestreamWriter = TimestreamWriterDto::make($payload)->forTable('table-name');
return $timestreamService->write($timestreamWriter);
}