Package: densli
About denslidensliis a command line client for accessing theServer DensityAPIwith the following features:Store authentication details in a config file, or pass them as command optionsExtensive error checkingDisplay metric ranges as a sparklines graphPrettyTERMcolours!Outputs JSON in an indented human readable (but still machine readable) formatCan accept data to send as JSON via pipedstdinSuppress none JSON data output via option to pipe data to other processesFlexible ways to define API endpoints and data to send (different API path formats and add data viastdin, named options or as extra unnamed arguments)InstallationThe app can be installed from PyPi usingpip:pip install densliOr cloned fromGithubusinggit:git clone git://github.com/serverdensity/densli.git
cd densli
python setup.py installUsagedensli 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 rundenslifor 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/Densliunder OS X).DENSLI_HOME environment variableThe location for this config file can be changed using the environment variableDENSLI_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 ...–helpYou can get a list/descrption of all the available options using-hor--helpoptions.API endpointsYou can use densli to get results back from any of theServer Density APIendpoints, for example to access thedevices list:densli devices listThe above format “<section> <method>” can also be represented using a ‘/’ or ‘.’, e.g.:devices.listdevices/listdataData to send to an endpoint can be defined as name-value pairs (seperated by an equals sign=) using multiple-dor--dataoptions, 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–quietdensli is rather vocal about picking up settings and how it handles things (viaSTDOUT), or about errors (viaSTDERR), you might not want anything sent toSTDOUTif you’re piping densli’s output to another process, to silence non-API output use the-qor-quietoptions.–sparkThe 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 themetrics getRangeendpoint you can also get results outputted as a sparkline bargraphs (using the unicode characters 9601-9608) with the-sor--sparkoption, 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 --sparkWill 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 yourconfig.jsonfile.–timeagoA shortcut for defining a relative time offset formetrics.getRangecalls is provided with the-tand--timeagooptions. 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–postbackTo make sending postbacks to themetrics.postback endpointwith piped in data more convenient you can use the-Por--postbackoption to flagSTDINdata as a raw JSON payload which will be sent in apayloadfield as the postback endpoint expects, e.g.:echo '{ "agentKey": "blah", "someMetric": [...], "someOtherMetric": 1.0 }' \
| densli metrics postback deviceId=4e95d575160ba0212b003356 --postback