(DEV) [API] DataDog • Stats, monitoring and more

DataDog FiveM Library (DDFL)

  • Statistics, monitoring and more !
  • Standalone
  • Open source
  • Free to use
  • Easy to use

Summary:

  1. Description
  2. Credits
  3. Download
  4. Installation
  5. Setup
  6. Usage
  7. Examples (and screens)

Description

DataDog-FiveM is a library to communicate with the REST API of the DataDog service (https://www.datadoghq.com/).

For those who don’t know, it is a service that allows to make statistical curves from sent data. DataDog also allows you to do monitoring.


Credits

Idea & Code by Pablo "PABLO-1610"
Code review by Jordan "AbsoluteDev"


Download

You can download the project from the repo by clicking here: datadog-fivem

This project is open source, which means that I invite all developers who wish to contribute and maintain this library to do so!


Installation

To install this library, you just need to download it (or clone it) and then add ensure datadog-fivem to your server.cfg.

If you want, you can define your API key directly using the convar datadog_api_key.

:globe_with_meridians: To obtain or generate an API key, follow this link

Otherwise, use the ddfl:setApiKey event by passing your API key as a parameter to the event.

Usage: TriggerEvent("ddfl:setApiKey", "yourApiKeyHere")


Setup

To use DDFL, you must make sure that DDFL is started before any other script that will use it.

:globe_with_meridians: To obtain or generate an application key, follow this link

To make queries, you must authenticate with an application key. Create your authorization with this line;

TriggerEvent("ddfl:setApplication", "myApplicationName", "myApplicationKey")

TriggerEvent("ddfl:setApplication", "myApplicationName", "myApplicationKey", true) (With logs)

You can put whatever you want for myApplicationName, it only serves to identify your application.


Usage

Possible usages


Examples

Creating a simple graph with a single point

Code:

-- Set the API key
TriggerEvent("ddfl:setApiKey", "<yourApiKeyHere>")
-- Create an application instance with a name (just for you) and the app token
TriggerEvent("ddfl:setApplication", "myMonitoringApp", "<yourAppKeyHere>", true)

RegisterCommand("test_metric", function()
    local currentTime, playersCount = os.time(), 25
    TriggerEvent("ddfl:submitMetric", "myMonitoringApp", function(success)
        if (success) then
            print("Players count submitted")
        else
            print("Players count not submitted")
        end
    end, { metric = "myserver.players", type = "gauge", points = { { currentTime, 25 } }, tags = { "filter:all" } })
end)

Result:

Creating multiple points, with one delayed

Code:

-- (...) before this, set API key and app
RegisterCommand("test_metric_multiple", function()
    local currentTime, playersCount = os.time(), 25
    TriggerEvent("ddfl:submitMetric", "myMonitoringApp", function(success)
        if (success) then
            print("2 Players count submitted, with one in the past :o")
        else
            print("2 Players count not submitted")
        end
    end, { metric = "myserver.players.newPlayers", type = "gauge", points = { { currentTime, 10 }, { currentTime - (60*5), 5 } }, tags = { "filter:all" } })
end)

Results:


9 Likes

Feel free to ask questions (if you have any) and leave feedback on this script!

1 Like

holy fuck, i use datadog for monitoring. this is awesome.

1 Like

Don’t hesitate to give me feedback on the library if you use it

Hey , i would like to ask how to add so it logs ox_inventory they have it in readme but i dont understand it

its says:

Logging

The included logging module utilises datadog to store logging data, which can be expanded for improved analytics and metrics. Register an account at datadoghq.
The free plan is enough for most user’s purposes and provides far more utility than the typical weird discord logs utilised in other resources.

Once you have registered, generate an API key and add set datadog:key 'apikey' to your server config.