MyNixOS website logo
Description

Prometheus 'PromQL' Query Client for 'R'.

A native 'R' client library for querying the 'Prometheus' time-series database, using the 'PromQL' query language.

promr

promr is a PromQL query client for the Prometheus time-series database.

Installation

To install the development version using devtools:

devtools::install_github("domodwyer/promr")

Example

library(promr)

# Define your PromQL query
q <- "sum by (handler, result) (rate(dml_handler_write_duration_seconds_count{}[1m]))"

# And execute the query within the specified time range
df <- query_range(
  q,
  "2022-08-19T00:00:00Z",
  "2022-08-20T00:00:00Z"
)

Timestamps can be provided as rfc3339 strings, numerical unix timestamps, or POSIXct objects. Optionally timeout, and step parameters can be provided.

The output df contains all the returned series, with the measurements nested within. For this query, there are 10 series:

print(df)
## # A tibble: 10 × 3
##    handler              result  values              
##    <chr>                <chr>   <list>              
##  1 parallel_write       error   <tibble [8,641 × 2]>
##  2 parallel_write       success <tibble [8,641 × 2]>
##  3 partitioner          error   <tibble [8,641 × 2]>
##  4 partitioner          success <tibble [8,641 × 2]>
##  5 request              error   <tibble [8,641 × 2]>
##  6 request              success <tibble [8,641 × 2]>
##  7 schema_validator     error   <tibble [8,641 × 2]>
##  8 schema_validator     success <tibble [8,641 × 2]>
##  9 sharded_write_buffer error   <tibble [8,641 × 2]>
## 10 sharded_write_buffer success <tibble [8,641 × 2]>

The unnested data can be easily extracted using tidyr::unnest() (part of of the tidyverse), to produce a “long” tibble of measurements:

df |>
  tidyr::unnest(values) |>
  head()
## # A tibble: 6 × 4
##   handler        result timestamp           value
##   <chr>          <chr>  <dttm>              <dbl>
## 1 parallel_write error  2022-08-19 02:00:00     0
## 2 parallel_write error  2022-08-19 02:00:10     0
## 3 parallel_write error  2022-08-19 02:00:20     0
## 4 parallel_write error  2022-08-19 02:00:30     0
## 5 parallel_write error  2022-08-19 02:00:40     0
## 6 parallel_write error  2022-08-19 02:00:50     0

Which makes it easy to work on, and visualise the actual data:

library(ggplot2)
library(tidyverse)

df |>
  unnest(values) |>
  filter(handler == "partitioner") |>
  ggplot(aes(x = timestamp, y = value, colour = result)) +
  geom_line() +
  labs(
    title = "Partitioner Calls",
    x = "Time",
    y = "Requests per Second"
  )
Metadata

Version

0.1.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows