promR

Build status Coverage status lifecycle

R library for reading and analysing metrics stored on a Prometheus server.

Installation

You can install promR using devtools:

if (requireNamespace("devtools", quietly = TRUE)) {
    devtools::install_github('glenn-m/promR')
} else {
    install.packages("devtools")
    devtools::install_github('glenn-m/promR')
}

Usage

Instant Query

To retrieve the value of the go_goroutines metric 60 seconds ago.

library(promR)
prom <- Prometheus$new(host = "http://demo.robustperception.io", port = 9090)
# Timestamps can be in rfc3339 or unix format
metrics_instant <- prom$query(query = "go_goroutines", time = as.POSIXct(Sys.time() - 60))

Output:

knitr::kable(head(metrics_instant))

Range Query

library(promR)
prom <- Prometheus$new(host = "http://demo.robustperception.io", port = 9090)
metrics_range <- prom$rangeQuery(
  query = "go_goroutines",
  start = as.numeric(as.POSIXct(Sys.time() - 600)),
  end = as.numeric(as.POSIXct(Sys.time())),
  step = "10s"
)

Output:

head(metrics_range, n = 1)

Metadata Query

Get metadata for all node exporter metrics.

library(promR)
prom <- Prometheus$new(host = "http://demo.robustperception.io", port = 9090)
metrics_metadata <- prom$metadataQuery(match_target = '{job="node"}')

Output:

knitr::kable(head(metrics_metadata))

Get metadata for all metrics.

library(promR)
prom <- Prometheus$new(host = "http://demo.robustperception.io", port = 9090)
metrics_metadata <- prom$metadataQuery(match_target = '{job=~".+"}')

Output:

knitr::kable(head(metrics_metadata))

Contributing

  1. Fork it ( https://github.com/glenn-m/promR/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes
  4. Run devtools::test() to ensure tests are passing.
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

Contributors



glenn-m/promR documentation built on March 22, 2023, 8:49 p.m.