Prerequisites
1. Threshold Evaluation Mode
This mode is suitable for scenarios requiring threshold comparison on aggregated values.Configuration
- Query Statement: Write SQL aggregate query, returning value columns and (optional) label columns.
- Example: Count error log quantity by service in the last 5 minutes.
- Field Mapping:
- Value fields: Select
error_cntfor threshold evaluation. - Label fields: Select
service_nameto identify the alert object. After you select label fields, other non-value fields are carried with the alert as additional information. - See Query Result Field Mapping for the complete behavior.
- Threshold Conditions:
- Use
$A.field_nameto reference values. - Example:
Critical: $A.error_cnt > 50,Warning: $A.error_cnt > 10.
How It Works
Monitors distinguishes alert objects by their label fields and evaluates thresholds with their value fields. If Label fields is empty, every returned field except the value fields becomes a label.Recovery Logic
2. Data Exists Mode
This mode is suitable for scenarios where filter logic is written directly in SQL.Configuration
- Query Statement: Use
HAVINGclause in SQL to directly filter out anomalous data.
- Example: Directly query services with error count exceeding 50.
- Evaluation Rules: As long as SQL query returns data, triggers alert.
Pros and Cons Analysis
Recovery Logic
- Recovery When Data Disappears: When SQL query result is empty, determines recovery
- Recovery Query: Supports configuring additional query statements to assist in determining recovery status
- Manual Close: Keep the alert active until it is closed manually
3. No Data Mode
This mode is used to monitor scenarios where “data is expected but actually missing”.Configuration
- Query Statement: Write a SQL query that is expected to continuously return data.
- Example: Query heartbeat reports from all probes.
- Evaluation Rules: If a
probe_idappeared in previous cycles but cannot be found in current and N consecutive cycles, triggers “No Data” alert.
Recovery Logic
No-data alerts support configuring the alert ending mode, which decides how the alert ends:4. Best Practices
Type Conversion
Type Conversion
ClickHouse drivers may return formats unrecognizable by the engine when processing complex types. Recommend explicit conversion in SELECT clause:
toString(uuid)toFloat64(avg_duration)
Time Filtering
Time Filtering
ClickHouse is very sensitive to time partitions. Always include time range filtering in
WHERE clause to utilize indexes:timestamp > now() - INTERVAL 5 MINUTEtimestamp > toDateTime(now()) - 300
Field Case
Field Case
Monitors converts column names returned by ClickHouse to lowercase. Use lowercase names for both label fields and value fields.