At work, we have a lot of infrastructure and we have to know what is going on with our servers and apps.
There are different options to do that and one of them is Datadog service.
Datadog can handle all stats from your servers and show you nice graphs and send alerts in case of a problem.
To use it, you have to create an account and install datadog agent service on your server.
Today I decided to write an suave.io web site and connect it to our datadog account to show some info
about request rates and so on. There are different options how to connect your app to your datadog account.
For example you could write datadog custom check, but it is easier to use existing one.
We use golang expvars checks for our golang servers, so I decided to emulate them in suave.
What is expvars?
Expvars is a golang module which allows you to create some variables and expose them via web interface in json format.
You could find more info here. This is an example of expvars output. There are some predefined expvars in golang, so you could check memory stats and so on.
By convention address of this json is “IP:8000/debug/vars”.
Let’s implement one expvar in a suave app.
First of all, you have to create a datadog account and after that install datadog agent as described here.
In our case this is an ubuntu server. After installation we have to create “/etc/dd-agent/conf.d/go_expvar.yaml” file.
Actually we also need to comment this line in “/etc/dd-agent/checks.d/go_expvar.py”:
This line will throw in case of missing memstats data.
Now restart the datadog agent “/etc/init.d/datadog-agent restart”)
More about how to setup datadog with expvars you could find here
Last step is to create suave.io app with “hellorps” expvar and run it.
We will use suave script template
Now we have to add a thread safe rate counter.
Create hello webpart and start server.
And do the same for expvars.
create load generator.
And finally run everything
Done. Now we can go to datadog and see our metric.