-
Notifications
You must be signed in to change notification settings - Fork 2
/
read_rrd.php
38 lines (28 loc) · 880 Bytes
/
read_rrd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require __DIR__ . '/../vendor/autoload.php';
use RrdPhpReader\Rra\RraInfo;
use RrdPhpReader\RrdDs;
use RrdPhpReader\RrdReader;
use RrdPhpReader\RrdRowValue;
if (php_sapi_name() !== 'cli') {
echo 'Should be used only in command line interface';
exit(1);
}
// usage: php read_rrd.php --rrd="../tests/data/rrd_linux_x86_64.rrd"
$options = getopt('', ['rrd:', 'csv:']);
$rrdPath = $options['rrd'] ?? __DIR__ . '/../tests/data/rrd_linux_x86_64.rrd';
if (!file_exists($rrdPath)) {
echo 'Rrd file does not exist!';
exit(1);
}
$reader = RrdReader::createFromPath($rrdPath);
$traversable = $reader->getAll([
'ds' => 'value',
'row_filter_callback' => function (int $timestamp, float $value, RrdDs $ds, RraInfo $rra) {
return $value < 8;
}
]);
/** @var RrdRowValue $value */
foreach ($traversable as $value) {
echo $value . PHP_EOL;
}