Skip to main content
Databases & applications

MySQL / MariaDB Query

Run your own SELECT query on a MySQL or MariaDB server and get alerted on its row count or execution time.

The MySQL / MariaDB Query check runs your own SQL query on a MySQL or MariaDB server and evaluates either the number of rows returned or the execution time. Use it, for example, to watch for stuck orders, failed jobs or slow queries. The check runs on the agent device you assign it to and connects from there over TCP to the host you enter. It runs on Windows, Linux and macOS (each in x64 and Arm64), every 5 minutes by default. The database server itself does not need to be an agent device; any agent device that can reach it over the network is enough.

Prerequisites

  • An account on the database server that may sign in from the agent device's address. To create the monitoring account, see Set up the database monitoring account.
  • SELECT rights on exactly the tables your query reads.

Steps

  1. Go to Devices and open the device.
  2. Click the Checks tab → Add Check → MySQL / MariaDB Query.

Settings

FieldTypeRequiredDefaultDescription
HostTextYes—Hostname or IP address of the database server, as seen from the agent device
PortIntegerNo3306TCP port of the server. The check replaces values outside 1–65535 with 3306
Database (optional)TextNo—Default database of the connection. Leave empty if the query uses fully qualified table names (schema.table)
UsernameTextYes—Account the check signs in with
PasswordTextNo—Password of the account
SSL modeSelectNoPreferredPreferred encrypts when the server offers it; Required insists on an encrypted connection; None connects unencrypted
Query (read-only SELECT)TextYes—The statement to run. The check sets the session to READ ONLY first
Alert onSelectNoRow countRow count evaluates the number of rows returned, Execution time (ms) the query duration in milliseconds
Alert when below thresholdYes/NoNoNoReverses the comparison: alert when the value reaches or falls below the thresholds
Warning thresholdNumberNo1Value at which a warning is reported
Error thresholdNumberNo1Value at which a critical result is reported

The check counts rows, not values. SELECT count(*) FROM orders WHERE status = 'stuck' always returns exactly one row and is therefore always evaluated as 1, no matter how many entries are affected. Write the query so that it returns one row per problem, for example SELECT id FROM orders WHERE status = 'stuck'.

Results

The check compares the chosen value (row count or execution time) with both thresholds. Thresholds also trigger on equality.

SituationResult
Value at or above Error threshold (with Alert when below threshold: at or below)Critical
Value at or above Warning threshold (with Alert when below threshold: at or below)Warning
OtherwiseOK
Sign-in rejected, server unreachable, query error or timeoutCritical
No host or no query enteredWarning
Unexpected error in the checkFailure

With the defaults (both thresholds 1, mode Row count), the check is therefore Critical as soon as the query returns at least one row, and OK otherwise. If the two thresholds are in the wrong order, the check swaps them before evaluation. Connection setup and query have a fixed 15-second timeout.

Metrics collected

  • Number of rows returned
  • Query execution time in milliseconds (excluding connection setup)

Notes

  • Setting the session to READ ONLY is a safety net, not a replacement for a read-only account. Grant the monitoring account SELECT only.
  • The host is part of the check configuration. If you assign the check to many devices through a config package, each of them runs the same query against the same server. Assign it to a single device instead.