• This repository has been archived on 11/Dec/2023
  • Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    Ruby
  • License
    Other
  • Created about 13 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby wrapper to make it easy to interact with Librato's API.

Librato Metrics

Gem Version Build Status Code Climate

A convenient Ruby wrapper for the Librato Metrics API.


Important note on breaking change

NOTE: Starting with version 2.1.0 librato-metrics requires a Librato account that supports tagged metrics. If your Librato account doesn't yet support tagged metrics please use the 1.6.1 version.


This gem provides granular control for scripting interactions with the Metrics core API. It is well suited for integrations, scripts, workers & background jobs. If you want to submit from a web app, take at look at librato-rails and/or librato-rack.

Installation

In your shell:

gem install librato-metrics

Then, in your application or script:

require 'librato/metrics'

Optional steps

For best performance we recommend installing yajl-ruby:

gem install yajl-ruby

If you are using jruby, you need to ensure jruby-openssl is available:

gem install jruby-openssl

Quick Start

If you are looking for the quickest possible route to getting a data into Metrics, you only need two lines:

Librato::Metrics.authenticate 'email', 'api_key'
Librato::Metrics.submit my_metric: { value: 42, tags: { host: 'localhost' } }

While this is all you need to get started, if you are sending a number of metrics regularly a queue may be easier/more performant so read on...

Authentication

Make sure you have an account for Librato and then authenticate with your email and API key (on your account page):

Librato::Metrics.authenticate 'email', 'api_key'

Sending Measurements

A measurement includes a metric name, value, and one or more tags. Tags include a name/value pair that describe a particular data stream. Each unique tag set creates an individual metric stream which can later be filtered and aggregated along.

Queue up a simple metric named temperature:

queue = Librato::Metrics::Queue.new
queue.add temperature: {value: 77, tags: { city: 'oakland' }}
queue.submit

Top-Level Tags

You can initialize Queue and/or Aggregator with top-level tags that will be applied to every measurement:

queue = Librato::Metrics::Queue.new(tags: { service: 'auth', environment: 'prod', host: 'auth-prod-1' })
queue.add my_metric: 10
queue.submit

Per-Measurement Tags

Optionally, you can submit per-measurement tags by passing a tags Hash when adding measurements:

queue.add my_other_metric: { value: 25, tags: { db: 'rr1' } }
queue.submit

For more information, visit the API documentation.

Querying Metrics

Get name and properties for all metrics you have in the system:

metrics = Librato::Metrics.metrics

Get only metrics whose name includes time:

metrics = Librato::Metrics.metrics name: 'time'

Retrieving Measurements

Get the series for exceptions in production grouped by sum within the last hour:

query = {
  resolution: 1,
  duration: 3600,
  group_by: "environment",
  group_by_function: "sum",
  tags_search: "environment=prod*"
}
Librato::Metrics.get_series :exceptions, query

For more information, visit the API documentation.

Aggregate Measurements

If you are measuring something very frequently e.g. per-request in a web application (order mS) you may not want to send each individual measurement, but rather periodically send a single aggregate measurement, spanning multiple seconds or even minutes. Use an Aggregator for this.

Aggregate a simple gauge metric named response_latency:

aggregator = Librato::Metrics::Aggregator.new
aggregator.add response_latency: 85.0
aggregator.add response_latency: 100.5
aggregator.add response_latency: 150.2
aggregator.add response_latency: 90.1
aggregator.add response_latency: 92.0

Which would result in a gauge measurement like:

{name: "response_latency", count: 5, sum: 517.8, min: 85.0, max: 150.2}

You can specify a source during aggregate construction:

aggregator = Librato::Metrics::Aggregator.new(tags: { service: 'auth', environment: 'prod', host: 'auth-prod-1' })

You can aggregate multiple metrics at once:

aggregator.add app_latency: 35.2, db_latency: 120.7

Send the currently aggregated metrics to Metrics:

aggregator.submit

Benchmarking

If you have operations in your application you want to record execution time for, both Queue and Aggregator support the #time method:

aggregator.time :my_measurement do
  # do work...
end

The difference between the two is that Queue submits each timing measurement individually, while Aggregator submits a single timing measurement spanning all executions.

If you need extra attributes for a Queue timing measurement, simply add them on:

queue.time :my_measurement do
  # do work...
end

Annotations

Annotation streams are a great way to track events like deploys, backups or anything else that might affect your system. They can be overlaid on any other metric stream so you can easily see the impact of changes.

At a minimum each annotation needs to be assigned to a stream and to have a title. Let's add an annotation for deploying v45 of our app to the deployments stream:

Librato::Metrics.annotate :deployments, 'deployed v45'

There are a number of optional fields which can make annotations even more powerful:

Librato::Metrics.annotate :deployments, 'deployed v46', source: 'frontend',
    start_time: 1354662596, end_time: 1354662608,
    description: 'Deployed 6f3bc6e67682: fix lotsa bugs…'

You can also automatically annotate the start and end time of an action by using annotate's block form:

Librato::Metrics.annotate :deployments, 'deployed v46' do
  # do work..
end

More fine-grained control of annotations is available via the Annotator object:

annotator = Librato::Metrics::Annotator.new

# list annotation streams
streams = annotator.list

# fetch a list of events in the last hour from a stream
annotator.fetch :deployments, start_time: (Time.now.to_i-3600)

# delete an event
annotator.delete_event 'deployments', 23

See the documentation of Annotator for more details and examples of use.

Auto-Submitting Metrics

Both Queue and Aggregator support automatically submitting measurements on a given time interval:

# submit once per minute
timed_queue = Librato::Metrics::Queue.new(autosubmit_interval: 60)

# submit every 5 minutes
timed_aggregator = Librato::Metrics::Aggregator.new(autosubmit_interval: 300)

Queue also supports auto-submission based on measurement volume:

# submit when the 400th measurement is queued
volume_queue = Librato::Metrics::Queue.new(autosubmit_count: 400)

These options can also be combined for more flexible behavior.

Both options are driven by the addition of measurements. If you are adding measurements irregularly (less than once per second), time-based submission may lag past your specified interval until the next measurement is added.

If your goal is to collect metrics every x seconds and submit them, check out this code example.

Setting Metric Properties

Setting custom properties on your metrics is easy:

# assign a period and default color
Librato::Metrics.update_metric :temperature, period: 15, attributes: { color: 'F00' }

Deleting Metrics

If you ever need to remove a metric and all of its measurements, doing so is easy:

# delete the metrics 'temperature' and 'humidity'
Librato::Metrics.delete_metrics :temperature, :humidity

You can also delete using wildcards:

# delete metrics that start with cpu. except for cpu.free
Librato::Metrics.delete_metrics names: 'cpu.*', exclude: ['cpu.free']

Note that deleted metrics and their measurements are unrecoverable, so use with care.

Using Multiple Accounts Simultaneously

If you need to use metrics with multiple sets of authentication credentials simultaneously, you can do it with Client:

joe = Librato::Metrics::Client.new
joe.authenticate 'email1', 'api_key1'

mike = Librato::Metrics::Client.new
mike.authenticate 'email2', 'api_key2'

All of the same operations you can call directly from Librato::Metrics are available per-client:

# list Joe's metrics
joe.metrics

There are two ways to associate a new queue with a client:

# these are functionally equivalent
joe_queue = Librato::Metrics::Queue.new(client: joe)
joe_queue = joe.new_queue

Once the queue is associated you can use it normally:

joe_queue.add temperature: { value: 65.2, tags: { city: 'san francisco' } }
joe_queue.submit

Thread Safety

The librato-metrics gem currently does not do internal locking for thread safety. When used in multi-threaded applications, please add your own mutexes for sensitive operations.

More Information

librato-metrics is sufficiently complex that not everything can be documented in the README. Additional options are documented regularly in the codebase. You are encouraged to take a quick look through the source for more.

We also maintain a set of examples of common uses and appreciate contributions if you have them.

Contribution

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project and submit a pull request from a feature or bugfix branch.
  • Please review our code conventions.
  • Please include specs. This is important so we don't break your changes unintentionally in a future version.
  • Please don't modify the gemspec, Rakefile, version, or changelog. If you do change these files, please isolate a separate commit so we can cherry-pick around it.

Copyright

Copyright (c) 2011-2017 Solarwinds, Inc. See LICENSE for details.

More Repositories

1

librato-rails

Report key app statistics to the Librato Metrics service and easily track your own custom metrics
Ruby
160
star
2

statsd-librato-backend

A StatsD backend that sends metrics to Librato Metrics
JavaScript
76
star
3

python-librato

A Python wrapper for the Librato Metrics API.
Python
72
star
4

metrics-librato

Librato reporter for dropwizard/metrics
Java
51
star
5

collectd-librato

Collectd Plugin for Librato Metrics
Python
38
star
6

salt-state-test

A script to test whether salt states can be rendered for testing, CI, etc. purposes
Python
34
star
7

librato-rack

Easily use Librato Metrics with your rack application
Ruby
33
star
8

statsd-cookbook

Chef cookbook to install Statsd
Ruby
26
star
9

librato-java

Java language bindings for the Librato API
Java
24
star
10

librato-storm-kafka

Publish metrics from Storm+Kafka setups to Librato
Ruby
23
star
11

disco-java

Service discovery through Zookeeper for Java
Java
21
star
12

librato-services

Services for Librato Metrics
Ruby
14
star
13

rollout-java

Java
13
star
14

watchconf

A library for watching service configuration from various sources on the JVM
Java
13
star
15

librato-metrics-taps

Tap scripts for pumping external metrics sources to Librato
Ruby
12
star
16

librato-metrics-memcached

Pull stats from memcached and push them to Librato Metrics
Ruby
11
star
17

librato-spark

Command line interface to generate sparklines of your Librato metrics
Shell
11
star
18

taxonomy

Source Repo for the "Monitoring Taxonomy" marketing project
Shell
11
star
19

librato-collectd-docker

Collectd plugin for Docker cgroup metrics
Python
9
star
20

librato-propane

A patch for the Propane Campfire application that expands links to Librato instruments into live, auto-refreshing charts.
JavaScript
9
star
21

librato-annotate

Map third-party service POST hooks to Librato Annotations
Ruby
8
star
22

metrics-rails

Report key app statistics to the Librato Metrics service and easily track your own custom metrics
Ruby
8
star
23

dropwizard-librato

Send metrics from your Dropwizard application to Librato Metrics
Java
8
star
24

agent

Librato Agent
5
star
25

collectd-librato-cookbook

DEPRECATED: Chef cookbook to install the Librato Collectd Plugin
Ruby
5
star
26

ec2-cookbook

Collection of EC2 recipes
Ruby
5
star
27

librato-logreporter

Write Librato metrics to your logs with a convenient interface
Ruby
5
star
28

silverline-cookbook

Chef cookbook for installing/configuring Librato Silverline
Ruby
4
star
29

librato-python-web

Report key app statistics to the Librato Metrics service
Python
4
star
30

ansible-librato

HTML
4
star
31

kafka-cookbook

Chef cookbook for Apache Kafka (from: https://github.com/ExactTargetDev/open-cookbooks)
Ruby
4
star
32

collectd-cookbook

Extracts collectd cookbook from https://github.com/AtariTech/cookbooks
Ruby
3
star
33

zk-recipes

ZooKeeper recipes
Ruby
3
star
34

rack-statsd-sinatra-example

Example Sinatra application that uses rack-statsd for metrics.
Ruby
3
star
35

nodejs-cookbook

Extracted nodejs cookbook from @mdxp here: https://github.com/mdxp/cookbooks/tree/master/nodejs
Ruby
2
star
36

raspberry-tv-driver

Raspberry Pi setup to drive dashboards on TVs using Iceweasel as the browser
Shell
2
star
37

tablesnap-cookbook

Cookbook to setup and install tablesnap
Ruby
2
star
38

octoglass

Serving up fresh git mirrors.
JavaScript
2
star
39

api-docs

Librato API Docs
CSS
2
star
40

rollout-go

Golang library for ZK-based rollout
Go
2
star
41

librato-rack-source_prefix

Automatic source prefixing for measurements logged through librato-rack
Ruby
1
star
42

Sync-Amazon-SNS-Ruby

Non-EM version of Amazon-SNS-Ruby
Ruby
1
star
43

postfix-cookbook

Setup Postfix to forward mail to an external SMTP. Useful in cloud environments with no mail delivery.
Ruby
1
star
44

zkpresenced-cookbook

Chef cookbook for ZK presence daemon
Ruby
1
star
45

puppet-librato

Puppet
1
star
46

misc-cookbook

Misc. Chef recipes
Ruby
1
star
47

chef-librato

Chef config for Librato Agent
Ruby
1
star
48

sinatratest

Example application to submit Librato Metrics from EY
Ruby
1
star
49

rsyslog-cookbook

Installs the latest rsyslog 5.8.x release from source. Based off opscode version.
Ruby
1
star