monitoring web services using Globalping and notifications in Telegram

it’s not the drag moyor who is watching you, but the watchman who watches and notifies

it’s not the drag moyor who is watching you, but the watchman who watches and notifies

Imagine: your service must work flawlessly 24/7, be accessible from anywhere in the world, and any problems must be detected instantly. How to make sure that the site works equally quickly in New York, Tokyo and Moscow? How can I track routing or censorship issues in different countries?

Standard analytics systems can help with basic availability monitoring, but what if you need more? What if it is not possible to install a counter or you are not satisfied with the way notifications are delivered?

What is Globalping

Globalping is a team project jsDelivrexperts with 10 years of experience in the CDN field. They provide a free API to run network tests (ping, traceroute, dns, mtr, http) from locations around the world. At the time of writing, the network includes:

  • 82 countries

  • 338 cities

  • 1103 knots

Features of the project:

  • Open source code, you can check it out Here

  • Active Community

  • Ability to add your own node via Docker or ARM device

  • Credit system for extended use (earn money on your node)

This is what an ARM device looks like

This is what an ARM device looks like

API: simple and effective

API Globalping provides 4 main methods:

  1. POST /v1/measurements — creating a test with the specified parameters

  2. GET /v1/measurements/{id} — getting results by ID

  3. GET /v1/probes — list of available nodes with metadata

  4. GET /v1/limits — information about current limits

Basic use of the API does not require authentication, but through dashboard you can issue a token for expanded access.

Uptime Wachter: creating a monitoring system

The following goals were set during development:

  1. Maximum test flexibility

    – Direct transmission of JSON parameters to the API

    – No unnecessary abstractions

  1. Regular execution

    – Configuration via cron expressions

    – Instant start at startup

  1. Reliable notifications

    – Integration with Telegram

    – Instant delivery

    – Accessibility from any device

  1. Detailed logging

    – Saving all results

    – Various levels of detail

  1. Open source

    – Possibility of customization

    – Adding new notification methods

Technical details

The project is implemented in TypeScript and requires Node.js 18+. The configuration is as follows:

TELEGRAM_TOKEN= # Токен бота

NOTIFICATION_LIST= # Список ID получателей, можно указать групповой чат

LOG_LEVEL= # Уровень логирования (0-3)

NOTIFICATION_LEVEL= # Уровень уведомлений (0-3)

TIMEZONE= # Часовой пояс

MEASUREMENTS_PATH= # Папка для результатов

About logging and notification levels:

  • 3 – only errors

  • 2 – errors and warnings

  • 1 – errors, warnings and progress information

  • 0 – all of the above

The main Wachter class includes three key methods:

  1. loadMeasurements — loading tests from the file system

  2. runMeasurement — test execution via globalping-ts (typescript API wrapper available in npm)

  3. notify — processing and sending notifications

The system covers various types of tests:

  • ping: the number of lost packets and the average round-trip time RTT (round-trip time) are checked;

  • traceroute: we calculate the average RTT based on the data for each hop and the same thing happens as in the ping type;

  • dns: here the situation is a little more complicated, the type itself is divided into 2 subtypes: a simple DNS test and with tracing enabled. In both, the average TTL(time to live) lifetime is checked;

  • mtr: the number of lost packets, the average round-trip time RTT and the average number of unwanted phase or frequency deviations of the transmitted signal (jitter) are checked;

  • http: various timings are checked (they are listed in API documentation), the presence and validity of the TLS certificate, as well as notifications are sent every iteration of the test about the end of the certificate or the approach of this date.

    The tests themselves are stored in the folder measurementslet's add some test, any of the documentation for the API is quite suitable, the only thing we need to add is cronExpressionfor example */2 * * * *, the measurement will be performed every 2 minutes. The file name can be anything, the main thing is to save it in JSON format.
    It turns out the following:

    {
        "type": "ping",
        "target": "cdn.jsdelivr.net",
        "locations": [
            {
                "country": "DE"
            },
            {
                "country": "PL"
            }
        ],
        "cronExpression": "*/2 * * * *"
    }

    Now you can make a build and run the application:

    npm run buildAndGuard
This is what notifications look like

This is what notifications look like

Results

Uptime Wachter is an application to demonstrate the capabilities of the Globalping API and nothing more.

Perhaps it will be useful for teams for which constant monitoring of services from different parts of the world is critical without deploying their own infrastructure. Source code available at Github. I will be glad to hear your questions and suggestions for improvement in the comments!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *