npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

librato-api

v1.2.9

Published

A Librato backend API client library and a simple CLI tool.

Downloads

34

Readme

librato-api

npm version Build Status Coverage Status Dependencies Status

This package allows you to manage your Librato backend configuration and query time series data, but it is not intended to submit metric data. There are other packages doing that in a better way.

For a full description of the Librato API see the official Librato API documentation.

At the moment support for the following sections is implemented: Authentication, Pagination, Metrics, Spaces, Charts, Alerts, Services, Sources. Note the official API does not expose visual layout of spaces yet, only contents.

Explicit support for the following sections is missing: Annotations, API Tokens, Jobs, Snapshots and Measurements Beta. This is easy to fix, pull requests are welcome.

Examples

// the package is a ready to use client,
// using LIBRATO_USER and LIBRATO_TOKEN from the process environment
const libratoApi = require('librato-api')

// it's also possible to create a client with custom config (all properties are optional)
const LibratoApi = require('librato-api').LibratoAPI
const libratoApi = new LibratoAPI({
    serviceUrl: 'https://...',
    auth: { user: '...', pass: '...' },
    logger: ...,
    request: ...
})

// all methods return Promises
libratoApi.getMetrics().then(console.log)

// most methods support an options object which is passed to request-promise
libratoApi.getMetrics({ qs: { offset: 200, limit: 100 } })

// iterates over pagination
libratoApi.getAllMetrics()

// get a metric definition
libratoApi.getMetric('router.bytes')

// retrieve one page of time series data for metric and time frame
libratoApi.getMetric('router.bytes', { qs: { start_time: date1, end_time: date2 }})

// retrieve all pages of time series data for metric and time frame
libratoApi.getAllMeasurements('router.bytes', { qs: { start_time: date1, end_time: date2 }})

// update metric definition
libratoApi.putMetric('customers', { 'period': 3600 })

// use custom space finder (getSpace requires id)
libratoApi.findSpaceByName('myspace')

// update chart definition in a space
libratoApi.putChart(myspace.id, mychartId, mychart)

// not everything is explicitly supported yet, but generic api requests are easy to do
libratoApi.apiRequest(['annotation', 'backup'], { method: 'PUT', body: { ... } })

CLI Tool

This package installs a CLI tool named "librato" into your global or package bin-dir.

You have to export LIBRATO_USER and LIBRATO_TOKEN for authentication to work.

export LIBRATO_USER='...'
export LIBRATO_TOKEN='...'
librato help
librato list-metrics
...

Warning

This tool is quite new and still a bit rough regarding command line parsing, integrated help, etc. To see what it's doing it may be helpful to set LOG_LEVEL to verbose or debug.

Configuration Directory Support

Apart from functions which model single API calls, the tool can take a local directory containing json or js files in a certain structure and apply the contained elements to a Librato account with the "update-from-dir" command. The repository contains an example directory "example-config" which demonstrates this feature.

Note that all elements are referenced by their name (or title for alerts), even if the API usually handles them with a numeric id. This way generic configuration can be applied to multiple Librato accounts, but uniquness of names etc. is assumed.

There is a simple templating feature to create serieses of similar metrics. The "show-config-dir" command can be used to debug templating easily.

In general this will leave alone (not delete) server side elements which are not defined in the config dir, but it can remove elements which are explicitly enumerated in the outdated.json file.