README.md

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:

| name | instance | job | timestamp | port | |:---------------|:-------------------------|:-------------|:---------------|-----:| | go_goroutines | demo.robustperception.io | prometheus | 1600355179.603 | 9090 | | go_goroutines | demo.robustperception.io | pushgateway | 1600355179.603 | 9091 | | go_goroutines | demo.robustperception.io | alertmanager | 1600355179.603 | 9093 | | go_goroutines | demo.robustperception.io | node | 1600355179.603 | 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 value 1 go_goroutines demo.robustperception.io prometheus 9090 1600354640.016 74

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_disk_read_time_seconds_total | counter | The total number of seconds spent by all reads. | | demo.robustperception.io:9100 | node | | node_memory_PageTables_bytes | gauge | Memory information field PageTables_bytes. | | demo.robustperception.io:9100 | node | | node_network_transmit_packets_total | counter | Network device statistic transmit_packets. | | demo.robustperception.io:9100 | node | | node_sockstat_UDPLITE_inuse | gauge | Number of UDPLITE sockets in state inuse. | | demo.robustperception.io:9100 | node | | node_vmstat_pswpout | unknown | /proc/vmstat information field pswpout. | | demo.robustperception.io:9100 | node | | node_netstat_Udp_SndbufErrors | unknown | Statistic UdpSndbufErrors. | | 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_mcache_sys_bytes | gauge | Number of bytes used for mcache structures obtained from system. | | demo.robustperception.io:9091 | pushgateway | | go_memstats_mspan_sys_bytes | gauge | Number of bytes used for mspan structures obtained from system. | | demo.robustperception.io:9091 | pushgateway | | go_threads | gauge | Number of OS threads created. | | demo.robustperception.io:9091 | pushgateway | | go_gc_duration_seconds | summary | A summary of the pause duration of garbage collection cycles. | | demo.robustperception.io:9091 | pushgateway | | go_memstats_gc_cpu_fraction | gauge | The fraction of this program’s available CPU time used by the GC since the program started. | | demo.robustperception.io:9091 | pushgateway | | go_memstats_heap_alloc_bytes | gauge | Number of heap bytes allocated and still in use. | | 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

Contributors



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