GithubHelp home page GithubHelp logo

qpc-github / dogapi-rb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shopify/dogapi-rb

1.0 2.0 1.0 352 KB

Ruby client for DataDog's API

Home Page: http://www.datadoghq.com

License: Other

Ruby 100.00%

dogapi-rb's Introduction

Ruby Client for Datadog API

<img src=“https://badge.fury.io/rb/dogapi.png” alt=“Gem Version” />

<img src=“https://travis-ci.org/DataDog/dogapi-rb.png?branch=master” alt=“Build Status” />

The Ruby client is a library suitable for inclusion in existing Ruby projects or for development of standalone scripts. It provides an abstraction on top of Datadog’s raw HTTP interface for reporting events and metrics.

What’s new?

See CHANGELOG.md for details

Installation

From Source

Available at: github.com/DataDog/dogapi-rb

$ cd dogapi-rb
$ bundle
$ rake install

Using RubyGems

Gem page: rubygems.org/gems/dogapi

$ gem install dogapi

If you get a permission error, you might need to run the install process with sudo:

$ sudo gem install dogapi

If you get a LoadError, missing mkmf, you need to install the development packages for ruby.

# on ubuntu e.g.
$ sudo apt-get install ruby-dev

Usage

How to find your API and application keys

Go to your setup page.

A word about hosts and devices

Events and metric data points can be attached to hosts to take advantage of automatic tagging with the host’s tags.

If you want to attach events and points to a specific device on a host, simply specify the device when calling emit functions.

Submit an event to Datadog

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"

# submitting events doesn't require an application_key, so we don't bother setting it
dog = Dogapi::Client.new(api_key)

dog.emit_event(Dogapi::Event.new('Testing done, FTW'), :host => "my_host")

Tag a host in Datadog

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"
application_key = "fedcba654321"

dog = Dogapi::Client.new(api_key, application_key)

dog.add_tags("my_host", ["tagA", "tagB"])

Submit a metric to Datadog

You want to track a new metric called some.metric.name and have just sampled it from my_device on my_host. Its value is 50. Here is how you submit the value to Datadog.

require 'rubygems'
require 'dogapi'

api_key = "abcdef123456"

# submitting metrics doesn't require an application_key, so we don't bother setting it
dog = Dogapi::Client.new(api_key)

dog.emit_point('some.metric.name', 50.0, :host => "my_host", :device => "my_device")

Let us now assume that you have sampled the metric multiple times and you would like to submit the results. You can use the emit_points method (instead of emit_point). Since you are submitting more than one data point you will need to pass a list of Time, float pairs, instead of a simple float value.

require 'rubygems'
require 'dogapi'

# Actual sampling takes place
t1 = Time.now
val1 = 50.0

# some time elapses
t2 = Time.now
val2 = 51.0

# some more time elapses
t3 = Time.now
val3 = -60.0

api_key = "abcdef123456"

dog = Dogapi::Client.new(api_key)

dog.emit_points('some.metric.name', [[t1, val1], [t2, val2], [t3, val3]], :host => "my_host", :device => "my_device")

Get points from a Datadog metric

require 'rubygems'
require 'dogapi'

api_key = "abcd123"
application_key = "brec1252"

dog = Dogapi::Client.new(api_key, application_key)

# get points from the last hour
from = Time.now - 3600
to = Time.now

query = 'sum:metric.count{*}.as_count()'

dog.get_points(query, from, to)

dogapi-rb's People

Contributors

miketheman avatar alq666 avatar conorbranagan avatar yannmh avatar xcolour avatar clutchski avatar degemer avatar sethrosenblum avatar clofresh avatar talwai avatar yyuu avatar ansel1 avatar remh avatar pcockwell avatar darrenboyd avatar arielo avatar blakehilscher avatar iddl avatar byroot avatar kaixiang avatar allegrem avatar n0ts avatar rmoriz avatar treeder avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.