Skip to content

Generate and send info from Mikrotik in JSON format to Datadog API

License

Notifications You must be signed in to change notification settings

mtrimarchi/MikrotikJSON4DatadogAPI

Repository files navigation

MikrotikJSON4DatadogAPI

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:

datadog-public-dashboard-example

So, let's go!

First step, LoadGlobalFunctions.rsc

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 nameLoadAllFunctions
  • Start DateNov/27/2018
  • Start Timestartup
  • Interval00:00:00
  • On Eventjust 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

Second step, DatadogMonitoring.rsc

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:

  • apikeyYour API keys are unique to your organization. An API key is required by the Datadog Agent to submit metrics and events to Datadog.
  • applicationkeyApplication 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 nameDatadogMonitoring
  • Start DateNov/27/2018
  • Start Time00:00:00
  • Interval00:00:05
  • On Eventcopy/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.

Let's test!

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

About

Generate and send info from Mikrotik in JSON format to Datadog API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages