This is a simple example to generate and push metrics in JSON format to Datadog API using RouterOS scripting language.
I'm using Timeseries Points POST
Datadog API call.
With this example you can generate a dashboard like that:
So, let's go!
At first, we need to add some basic global functions and load them on startup.
You have to go on System \ Scheduler
and add a new Schedule.
Configure the schedule this way:
- Schedule name →
LoadAllFunctions
- Start Date →
Nov/27/2018
- Start Time →
startup
- Interval →
00:00:00
- On Event → just copy/paste LoadGlobalFunctions.rsc content
Ok, now if we reboot our router we will get loaded three functions. We can find them on System \ Scripts \ Environment
.
These loaded scripts are named:
- functionJulianDate Julian Calendar function wich convert RouterOS date call in JD format seconds
- timestamp Timestamp function to get UNIX POSIX timestamp in UTC timezone
- uptimeseconds Get uptime in seconds
First of all we need to generate an API Key
and a new Application Key
. We can do it here.
Once created both keys, as already done before, we have to add a new Schedule. This one generate the JSON data and push it to Datadog API using fetch
command. We need to adapt vars on the script because when we call Datadog API we need to identify ourself with the generated API key
and Application key
.
When you copy DatadogMonitoring.rsc pay attention to the first part of the script identified as "Datadog API Settings".
Adapt all the values:
- apikey → Your API keys are unique to your organization. An API key is required by the Datadog Agent to submit metrics and events to Datadog.
- applicationkey → Application keys, in conjunction with your org's API key, give you full access to Datadog's programmatic API. Application keys are associated with the user account that created them and can be named. The application key is used to log all requests made to the API.
- ddendpoint →
"https://app.datadoghq.com/api/v1"
URL Datadog API endpoint. - type →
"gauge"
[optional, default=gauge]: Type of your metric either: gauge, rate, or count. - tags →
"source:mikrotik"
[optional, default=None]: A list of tags associated with the metric.
Now you have to go once again on System \ Scheduler
and add a new Schedule.
Configure the schedule this way:
- Schedule name →
DatadogMonitoring
- Start Date →
Nov/27/2018
- Start Time →
00:00:00
- Interval →
00:00:05
- On Event → copy/paste the modified content of DatadogMonitoring.rsc
You can adjust Interval
seconds value in order to change the frequency timeframe for generation and push of the JSON to Datadog.
You can see system.cpu.load
metric using Metrics Explorer
on Datadog website.
Click here for an example: https://app.datadoghq.com/metric/explorer?live=true&exp_metric=system.cpu.load