New announcements for Serverless, Network, RUM, and more from Dash! New announcements from Dash!

Dogshell, Quickly Use Datadog's API from Terminal/Shell

You can use the Datadog API straight from terminal/shell by using a wrapper called dogshell.

Setup:

Dogshell comes with the officially supported datadogpy Python library, often used to send data to Datadog via DogStatsD. It can be installed following the instructions.

Once you have that library installed, you have the dog command available to you in your terminal/shell, but it still needs to be “initialized”: you need to provide it with an API and application key so that it can be used to send/receive data to and from your account. When you first try running a dog command, it recognizes that it needs to be initialized, and walks you through the 2-step process.

As one example of a dog command that would trigger the initialization setup (although any old dog command would work), you can run the following:

dog metric post test_metric 1

If your .dogrc file has not yet been created (i.e, the dogshell has not yet been initialized), it returns something like the following:

~/.dogrc does not exist. Would you like to create it? [Y/n] 

Submit “Y”. It then responds:

What is your api key? (Get it here: https://app.datadoghq.com/account/settings#api) 

You can paste your API key, and then:

What is your application key? (Generate one here: https://app.datadoghq.com/account/settings#api)

You can paste your application key. It finishes with:

Wrote ~/.dogrc.

Now you’re all set to use your dog commands to quickly use the Datadog API from your terminal/shell. For further help and information on the dog commands, run dog -h.

In the event that you would rather just write the .dogrc file yourself (perhaps you’d like to push the file to many of your servers programmatically so that you can run dog commands from any of your servers), the content of this file should be as follows:

[Connection]
apikey = <YOUR_API_KEY>
appkey = <YOUR_APPLICATION_KEY>

The Dogshell Commands:

For reference, find the code for Dogshell. But once you have Dogshell installed and initialized, you can append the -h option to the following commands to get more information on specific Dogshell usage:

  • dog metric
  • dog event
  • dog status_check
  • dog monitor
  • dog downtime
  • dog timeboard
  • dog screenboard
  • dog host
  • dog tag
  • dog search
  • dog comment

Example: Dogshell in Use

You can post metrics to your Datadog account by using:

dog metric post <metric_name> <metric_value> --tags "<TAG_KEY_1>:<TAG_VALUE_1>,<TAG_KEY_2>:<TAG_VALUE_2>"

For example, the following command sends a metric named test_dogshell_metric to your account with a value of 1.0 and the tags test:one and another_test:

dog metric post test_dogshell_metric 1.0 --tags "test:one,another_test"

Find more details on sending metrics from Dogshell by running:

dog metric post -h