skip to navigation
skip to content

Not Logged In

densli 1.0.2

CLI tool for working with the ServerDensity.com API

Latest Version: 1.0.3

About densli

densli is a command line client for accessing the Server Density API with the following features:

  • Store authentication details in a config file, or pass them as command options
  • Extensive error checking
  • Display metric ranges as a sparklines graph
  • Pretty TERM colours!
  • Outputs JSON in an indented human readable (but still machine readable) format
  • Can accept data to send as JSON via piped stdin
  • Suppress none JSON data output via option to pipe data to other processes
  • Flexible ways to define API endpoints and data to send (different API path formats and add data via stdin, named options or as extra unnamed arguments)

Installation

The app can be installed from PyPi using pip:

pip install densli

Or cloned from Github using git:

git clone git://github.com/serverdensity/densli.git
cd densli
python setup.py install

Usage

densli uses a JSON config file to store authentication info (account / username / passord), and other options. To create an example config file you can edit with your SD details just run densli for the first time, it will report where it has created the config file (this is usually in a standard location for configurations for your operating system, e.g. under $HOME/Library/Application Support/Densli under OS X).

DENSLI_HOME environment variable

The location for this config file can be changed using the environment variable DENSLI_HOME, e.g.:

DENSLI_HOME=~/.densli
export DENSLI_HOME
densli ...

Any or all of the auth details can be overridden as options passed to densli, this is useful for running from scripts where you don't want to keep your auth details stored in a file, e.g.:

densli --username=myusername --password=mypassword --account=myaccount.serverdensity.com ...

--help

You can get a list/descrption of all the available options using -h or --help options.

API endpoints

You can use densli to get results back from any of the Server Density API endpoints, for example to access the devices list:

densli devices list

The above format "<section> <method>" can also be represented using a '/' or '.', e.g.:

  • devices.list
  • devices/list

data

Data to send to an endpoint can be defined as name-value pairs (seperated by an equals sign =) using multiple -d or --data options, as piped in JSON, or as trailing name-value pair arguements, e.g. these are all the same:

densli metrics getLatest -d deviceId=4e95d575160ba0212b003356

densli metrics getLatest --data=deviceId=4e95d575160ba0212b003356

densli metrics getLatest deviceId=4e95d575160ba0212b003356

echo '{ "deviceId": "4e95d575160ba0212b003356" }' | densli metrics getLatest

--quiet

densli is rather vocal about picking up settings and how it handles things (via STDOUT), or about errors (via STDERR), you might not want anything sent to STDOUT if you're piping densli's output to another process, to silence non-API output use the -q or -quiet options.

--spark

The default output for densli commands is human-readable JSON (indented with 4 spaces, regardless of the format that came back from the SD API), but for the metrics getRange endpoint you can also get results outputted as a sparkline bargraphs (using the unicode characters 9601-9608) with the -s or --spark option, e.g.:

densli metrics getRange -d deviceId=4e95d575160ba0212b003356 -d metric=diskUsage \
-d rangeStart=012-08-25T00:00:00 -d rangeEnd=012-08-30T00:00:00 --spark

Will output something like:

>>> /dev Used for 012-08-25T00:00:00 - 012-08-30T00:00:00:
▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
>>> /boot Used for 012-08-25T00:00:00 - 012-08-30T00:00:00:
▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
>>> / Used for 012-08-25T00:00:00 - 012-08-30T00:00:00:
▇▇▇▇▇▇▇▇▇▇▆▃▁▁▁▁▁▁▁▁
>>> /var/lib/ureadahead/debugfs Used for 012-08-25T00:00:00 - 012-08-30T00:00:00:
▇▇▇▇▇▇▇▇▇▇▆▃▁▁▁▁▁▁▁▁

By default sparkline graphs are limited to a width of 20 characters for display purposes, but you can override this by setting the "max_graph_width" option to an integer of your choice in your config.json file.

--timeago

A shortcut for defining a relative time offset for metrics.getRange calls is provided with the -t and --timeago options. This lets you easily see recent metrics for a period up to right now, and accepts days, hours, minutes, and seconds in various formats, e.g.:

densli metrics getRange deviceId=4e95d575160ba0212b003356 metric=diskUsage \
--spark -t 30m # past 30 minutes

densli metrics getRange deviceId=4e95d575160ba0212b003356 metric=diskUsage \
--spark -t 1hour # past hour

densli metrics getRange deviceId=4e95d575160ba0212b003356 metric=diskUsage \
--spark -timeago="1h 15min" # past hour and a quarter

densli metrics getRange deviceId=4e95d575160ba0212b003356 metric=diskUsage \
--spark -timeago="1d 30s" # past day and 30 seconds

--postback

To make sending postbacks to the metrics.postback endpoint with piped in data more convenient you can use the -P or --postback option to flag STDIN data as a raw JSON payload which will be sent in a payload field as the postback endpoint expects, e.g.:

echo '{ "agentKey": "blah", "someMetric": [...], "someOtherMetric": 1.0 }' \
| densli metrics postback deviceId=4e95d575160ba0212b003356 --postback
 
File Type Py Version Uploaded on Size
densli-1.0.2.tar.gz (md5) Source 2012-08-31 8KB
  • Downloads (All Versions):
  • 14 downloads in the last day
  • 264 downloads in the last week
  • 629 downloads in the last month