forked from aldas/rrd-php-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrrd_to_csv.php
More file actions
34 lines (24 loc) · 693 Bytes
/
rrd_to_csv.php
File metadata and controls
34 lines (24 loc) · 693 Bytes
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
<?php
require __DIR__ . '/../vendor/autoload.php';
use RrdPhpReader\RrdReader;
if (php_sapi_name() !== 'cli') {
echo 'Should be used only in command line interface';
exit(1);
}
// usage: php rrd_to_csv.php --rrd="../tests/data/rrd_linux_x86_64.rrd" --csv=output.csv
$options = getopt('', [
'rrd:',
'csv:',
]);
$rrdPath = $options['rrd'] ?? __DIR__ . '/../tests/data/rrd_linux_x86_64.rrd';
$csvPath = $options['csv'] ?? __DIR__ . '/output.csv';
if (!file_exists($rrdPath)) {
echo 'Rrd file does not exist!';
exit(1);
}
$reader = RrdReader::createFromPath($rrdPath);
$fp = fopen($csvPath, 'wb');
$reader->outputAsCsv($fp, [
'ds' => 'value'
]);
fclose($fp);