Skip to content

Commit

Permalink
Merge pull request #1 from aldas/improve_api
Browse files Browse the repository at this point in the history
improve api, cleanup and many other things
  • Loading branch information
aldas committed Nov 10, 2018
2 parents 729b684 + 3e6d8ba commit 8c8d86e
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 355 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cache:
- $HOME/.composer/cache

php:
- 7.0
- 7.1
- 7.2

Expand Down
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Pure PHP RRDtool file reader
[![Build Status](https://travis-ci.org/aldas/rrd-php-reader.svg?branch=master)](https://travis-ci.org/aldas/rrd-php-reader)
[![codecov](https://codecov.io/gh/aldas/rrd-php-reader/branch/master/graph/badge.svg)](https://codecov.io/gh/aldas/rrd-php-reader)


> Because on windows php ext-rrd can not read rrd files created on unix and vice versa.
> See https://github.com/oetiker/rrdtool-1.x/issues/759
Expand All @@ -7,31 +10,46 @@ This library supports reading:
* rrds created on 64bit linux from 64bit Windows
* rrds created on 64bit Windows from 64bit Linux

**Only meant to export/dump data out of rrd file. No support for consolidation function etc**
**Only meant to export/dump data out of rrd file.**

Original repository: http://javascriptrrd.sourceforge.net/
This library is based on [javascriptRRD](http://javascriptrrd.sourceforge.net/)

## Example

Convert RRD to CSV: [rrd_to_csv.php](examples/rrd_to_csv.php)
```
$reader = RrdReader::createFromPath('path/to/my_rrd.rrd');
$fp = fopen('output.csv', 'wb');
$reader->outputAsCsv($fp, [
'ds' => 'value'
]);
fclose($fp);
```
use RrdPhpReader\RrdReader;


Filter rrd: [read_rrd.php](examples/read_rrd.php)
```
$reader = RrdReader::createFromPath('path/to/my_rrd.rrd');
$data = $reader->setDs('value')->setRraIndex(0)->getAsArray();
$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;
}
```

`$data` structure would be
Output would be:
```
[
'value' => [ <--- datasource as first level keys
0 => [ <--- rra index as key
1521054891 => 6, <--- timestamp => value
1521054892 => 7,
1521054893 => 8,
1521054894 => 9,
]
]
];
timestamp=1521054891, value=6.000000, cf=AVERAGE, ds=value, step=1
timestamp=1521054892, value=7.000000, cf=AVERAGE, ds=value, step=1
timestamp=1521054891, value=6.000000, cf=MAX, ds=value, step=1
timestamp=1521054892, value=7.000000, cf=MAX, ds=value, step=1
```

0 comments on commit 8c8d86e

Please sign in to comment.