PHP code example of harout-itology / laravel-aws-timestream
1. Go to this page and download the library: Download harout-itology/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/ */
harout-itology / laravel-aws-timestream example snippets
use HaroutItology\AwsTimestream\TimestreamService;
use HaroutItology\AwsTimestream\TimestreamBuilder;
use HaroutItology\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 HaroutItology\AwsTimestream\TimestreamService;
use HaroutItology\AwsTimestream\TimestreamBuilder;
use HaroutItology\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 HaroutItology\AwsTimestream\TimestreamService;
use HaroutItology\AwsTimestream\Dto\TimestreamWriterDto;
use HaroutItology\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);
}