In this part we’ll set up monitoring of the currency conversion service we’ve made and the server it is running on. We will use Datadog - you can read a previous (more generic) article on setting up monitoring with Datadog.
The previous article described how to setup monitoring to check if your server is running and to keep an eye on resources and resource consumption.
In the following we’ll assume that something similar is up and running and is not needed.
What monitoring can we add?
Now that we have a concrete server we can actually start to monitor something about it.
Since it is writted in Go we can use
expvar package that’ll give is the ability to export some variables from inside Go and give an interface to access them from Datadog.
Datadog previously wrote a blog post about it - it basically covers everything we/you need to know.
We’ll add the following metrics:
currency_hitsa counter for the hits to the
/currenciesendpoint - both the
POSTare counted as one
conversion_hitsa counter for the hits to the
webhook_hitsa counter for the hits to (succesfully) register a webhook
webhook_triggersa counter for the times webhooks are called by the server
We start by going to the
/etc/dd-agent/conf.d/ and renaming
go_expvar.yaml.example to just
Then we’ll open edit the file to contain only the following:
init_config: instances: - expvar_url: http://localhost/debug/vars metrics: - path: currency_hits - path: convert_hits - path: webhook_hits - path: webhook_triggers
Restart the agent:
service datadog-agent restart
And you’re running!
Changes in the code
Check out the new version of the server in the repository. It adds some
expvar variables in to code and performs
Add(1)’s to them on the requests.
Setting it up in Datadog
When we go to our dashboard in Datadog we can add new metrics from
It’ll look like this:
Now Datadog let’s us set up dashboard elements for the four metrics we added in the code along with the standard metrics from
expvar like memory allocated eg.
Hopefully this gives you some ideas on how to use tools like Datadog to keep an eye on your servers and services. Next we’ll need to put this currency conversion tool into the hands of some users.