Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrie/rrd
R package for working with .rrd files
https://github.com/andrie/rrd
r r-package rrd rrdtool rstats
Last synced: about 2 months ago
JSON representation
R package for working with .rrd files
- Host: GitHub
- URL: https://github.com/andrie/rrd
- Owner: andrie
- License: other
- Created: 2018-06-09T15:16:19.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-08-18T17:07:19.000Z (over 2 years ago)
- Last Synced: 2024-08-13T07:11:54.306Z (4 months ago)
- Topics: r, r-package, rrd, rrdtool, rstats
- Language: R
- Homepage: https://andrie.github.io/rrd/
- Size: 12.9 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - andrie/rrd - R package for working with .rrd files (R)
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# rrd
[![R build status](https://github.com/andrie/rrd/workflows/R-CMD-check/badge.svg)](https://github.com/andrie/rrd/actions) [![CRAN status](https://www.r-pkg.org/badges/version/rrd)](https://cran.r-project.org/package=rrd) [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html) [![](http://www.r-pkg.org/badges/version/rrd)](https://www.r-pkg.org:443/pkg/rrd) [![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/rrd)](https://www.r-pkg.org:443/pkg/rrd) [![Codecov test coverage](https://codecov.io/gh/andrie/rrd/branch/main/graph/badge.svg)](https://app.codecov.io/gh/andrie/rrd?branch=main)
The `rrd` package allows you to read data from an [RRD](https://oss.oetiker.ch/rrdtool/) Round Robin Database.
## Installation
### System requirements
In order to build the package from source you need [librrd](https://oss.oetiker.ch/rrdtool/doc/librrd.en.html). Installing [RRDtool](https://oss.oetiker.ch/rrdtool/) from your package manager will usually also install the library.
| Platform | Installation |
|-----------------|------------------------------|
| Debian / Ubuntu | `apt-get install librrd-dev` |
| RHEL / CentOS | `yum install rrdtool-devel` |
| Fedora | `yum install rrdtool-devel` |
| Solaris / CSW | Install `rrdtool` |
| OSX | `brew install rrdtool` |
| Windows | Not available |Note: on OSX you may have to update `xcode`, using `xcode-select --install`.
### Package installation
You can install the stable version of the package from CRAN:
``` r
install.packages("rrd")
```And the development version from [GitHub](https://github.com/):
``` r
# install.packages("remotes")
remotes::install_github("andrie/rrd")
```## About RRD and RRDtool
The `rrd` package is a wrapper around `RRDtool`. Internally it uses [librrd](https://oss.oetiker.ch/rrdtool/doc/librrd.en.html) to import the binary data directly into R without exporting it to an intermediate format first.
For an introduction to RRD database, see
## Example
The package contains some example RRD files that originated in an instance of RStudio Connect. In this example, you analyze CPU data in the file `cpu-0.rrd`.
Load the package and assign the location of the `cpu-0.rrd` file to a variable:
```{r load}
library(rrd)
rrd_cpu_0 <- system.file("extdata/cpu-0.rrd", package = "rrd")
```To describe the contents of an RRD file, use `describe_rrd()`:
```{r describe}
describe_rrd(rrd_cpu_0)
```To read an entire RRD file, i.e. all of the RRA archives, use `read_rrd()`. This returns a list of `tibble` objects:
```{r rrd}
cpu <- read_rrd(rrd_cpu_0)str(cpu, max.level = 1)
```Since the resulting object is a list of `tibble`s, you can easily work with individual data frames:
```{r inspect-rrd}
names(cpu)cpu[[1]]
tail(cpu$AVERAGE60$sys)
```To read a single RRA archive from an RRD file, use `read_rra()`. To use this function, you must specify several arguments that define the specific data to retrieve. This includes the consolidation function (e.g. "AVERAGE") and time step (e.g. 60), the `end` time. You must also specifiy either the `start` time, or the number of steps, `n_steps`.
In this example, you extract the average for 1 minute periods (`step = 60`), for one entire day (`n_steps = 24 * 60`):
```{r rra}
end_time <- as.POSIXct("2018-05-02") # timestamp with data in example
avg_60 <- read_rra(rrd_cpu_0, cf = "AVERAGE", step = 60, n_steps = 24 * 60,
end = end_time)avg_60
```And you can easily plot using your favourite packages:
```{r plot, out.width="90%", fig.height=3, fig.width=8}
library(ggplot2)
ggplot(avg_60, aes(x = timestamp, y = user)) +
geom_line() +
stat_smooth(method = "loess", span = 0.125, se = FALSE) +
ggtitle("CPU0 usage, data read from RRD file")
```## More information
For more information on `rrdtool` and the `rrd` format please refer to the official [rrdtool documentation](https://oss.oetiker.ch/rrdtool/doc/index.en.html) and [tutorials](https://oss.oetiker.ch/rrdtool/tut/index.en.html).
You can also read a more in-depth description of the package in an [R Views](https://rviews.rstudio.com/) blog post [Reading and analyzing log files in the RRD database format](https://rviews.rstudio.com/2018/06/20/reading-rrd-files/).