datadogr

Travis-CI Build Status AppVeyor Build Status CRAN_Status_Badge

About

datadogr is a simple package for querying data from Datadog.

Installation

datadogr is on CRAN now. You can install the released version from CRAN:

install.packages("datadogr")

Or the the development version from GitHub:

# install.packages("devtools")
devtools::install_github("yutannihilation/K9")

Usage

Authentication

You must have an API key for Datadog to use APIs. Follow the instruction on the official document: http://docs.datadoghq.com/api/#authentication

datadogr package uses DATADOG_API_KEY environmental variable for the API key. You can set this by:

Get List of Metrics

k9_list_metrics()

Get Metrics Values

A query can be specified with query argument using a query string:

k9_get_metrics(
  query = "system.cpu.idle{role:db,environment:test}by{host,region}",
  from  = Sys.time() - 3600,
  to    = Sys.time()
)

Or, the same thing can be done with metric, scope and by separetely:

k9_get_metrics(
  metric = "system.cpu.idle",
  scope = list(role = "db", environment = "test"),
  by    = c("host", "region"),
  from  = Sys.time() - 3600,
  to    = Sys.time()
)

The result will look like this:

#> # A tibble: 2 x 8
#>             timestamp    value          metric    display_name query_index interval                     host
#> *              <dttm>    <dbl>           <chr>           <chr>       <int>    <int>                    <chr>
#> 1 2015-04-29 21:50:00 98.19376 system.cpu.idle system.cpu.idle           0      600 vagrant-ubuntu-trusty-64
#> 2 2015-04-29 22:00:00 99.85857 system.cpu.idle system.cpu.idle           0      600 vagrant-ubuntu-trusty-64
#> # ... with 3 more variables: environment <chr>, role <chr>, region <chr>, expression <chr>

Get Events

(This function is a but experimental.)

k9_get_events(start = Sys.Date() - 7, end = Sys.Date(), tags = list(role = "db"))