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:

name instance job timestamp value port
go_goroutines demo.robustperception.io prometheus 1565524845.295 295 9090
go_goroutines demo.robustperception.io pushgateway 1565524845.295 121 9091
go_goroutines demo.robustperception.io alertmanager 1565524845.295 36 9093
go_goroutines demo.robustperception.io node 1565524845.295 8 9100

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: name instance job port timestamp 1 go_goroutines demo.robustperception.io prometheus 9090 1565524306.048 value 1 295

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:

metric type help unit instance job
node_memory_SwapTotal_bytes gauge Memory information field SwapTotal_bytes. demo.robustperception.io:9100 node
node_netstat_Udp_InErrors unknown Statistic UdpInErrors. demo.robustperception.io:9100 node
node_network_address_assign_type gauge address_assign_type value of /sys/class/net/. demo.robustperception.io:9100 node
node_timex_tick_seconds gauge Seconds between clock ticks. demo.robustperception.io:9100 node
node_netstat_Udp6_NoPorts unknown Statistic Udp6NoPorts. demo.robustperception.io:9100 node
node_network_dormant gauge dormant value of /sys/class/net/. demo.robustperception.io:9100 node

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:

metric type help unit instance job
go_memstats_gc_sys_bytes gauge Number of bytes used for garbage collection system metadata. demo.robustperception.io:9091 pushgateway
go_memstats_lookups_total counter Total number of pointer lookups. demo.robustperception.io:9091 pushgateway
go_memstats_stack_sys_bytes gauge Number of bytes obtained from system for stack allocator. demo.robustperception.io:9091 pushgateway
process_virtual_memory_bytes gauge Virtual memory size in bytes. demo.robustperception.io:9091 pushgateway
promhttp_metric_handler_requests_total counter Total number of scrapes by HTTP status code. demo.robustperception.io:9091 pushgateway
go_goroutines gauge Number of goroutines that currently exist. demo.robustperception.io:9091 pushgateway

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