CEL variables

CEL expressions for agent status evaluation have access to variables that represent data collected by Telegraf since the last successful heartbeat message (unless noted otherwise).

Top-level variables

VariableTypeDescription
metricsintNumber of metrics arriving at the heartbeat output plugin.
log_errorsintNumber of errors logged by the Telegraf instance.
log_warningsintNumber of warnings logged by the Telegraf instance.
last_updatetimeTimestamp of the last successful heartbeat message. Use with now() to calculate durations or rates.
agentmapAgent-level statistics. See Agent statistics.
inputsmapInput plugin statistics. See Input plugin statistics.
outputsmapOutput plugin statistics. See Output plugin statistics.

Agent statistics

The agent variable is a map containing aggregate statistics for the entire Telegraf instance. These fields correspond to the internal_agent metric from the Telegraf internal input plugin.

FieldTypeDescription
agent.metrics_writtenintTotal metrics written by all output plugins.
agent.metrics_rejectedintTotal metrics rejected by all output plugins.
agent.metrics_droppedintTotal metrics dropped by all output plugins.
agent.metrics_gatheredintTotal metrics collected by all input plugins.
agent.gather_errorsintTotal collection errors across all input plugins.
agent.gather_timeoutsintTotal collection timeouts across all input plugins.

Example

agent.gather_errors > 0

Input plugin statistics (inputs)

The inputs variable is a map where each key is a plugin type (for example, cpu for inputs.cpu) and the value is a list of plugin instances. Each entry in the list represents one configured instance of that plugin type.

These fields correspond to the internal_gather metric from the Telegraf internal input plugin.

FieldTypeDescription
idstringUnique plugin identifier.
aliasstringAlias set for the plugin. Only exists if an alias is defined in the plugin configuration.
errorsintCollection errors for this plugin instance.
metrics_gatheredintNumber of metrics collected by this instance.
gather_time_nsintTime spent gathering metrics, in nanoseconds.
gather_timeoutsintNumber of timeouts during metric collection.
startup_errorsintNumber of times the plugin failed to start.

Access patterns

Access a specific plugin type and iterate over its instances:

// Check if any cpu input instance has errors
inputs.cpu.exists(i, i.errors > 0)
// Access the first instance of the cpu input
inputs.cpu[0].metrics_gathered

Use has() to safely check if a plugin type exists before accessing it:

// Safe access — returns false if no cpu input is configured
has(inputs.cpu) && inputs.cpu.exists(i, i.errors > 0)

Output plugin statistics (outputs)

The outputs variable is a map with the same structure as inputs. Each key is a plugin type (for example, influxdb_v3 for outputs.influxdb_v3) and the value is a list of plugin instances.

These fields correspond to the internal_write metric from the Telegraf internal input plugin.

FieldTypeDescription
idstringUnique plugin identifier.
aliasstringAlias set for the plugin. Only exists if an alias is defined in the plugin configuration.
errorsintWrite errors for this plugin instance.
metrics_filteredintNumber of metrics filtered by the output.
write_time_nsintTime spent writing metrics, in nanoseconds.
startup_errorsintNumber of times the plugin failed to start.
metrics_addedintNumber of metrics added to the output buffer.
metrics_writtenintNumber of metrics written to the output destination.
metrics_rejectedintNumber of metrics rejected by the service or serialization.
metrics_droppedintNumber of metrics dropped (for example, due to buffer fullness).
buffer_sizeintCurrent number of metrics in the output buffer.
buffer_limitintCapacity of the output buffer. Irrelevant for disk-based buffers.
buffer_fullnessfloatRatio of metrics in the buffer to capacity. Can exceed 1.0 (greater than 100%) for disk-based buffers.

Access patterns

// Access the first instance of the InfluxDB v3 output plugin
outputs.influxdb_v3[0].metrics_written
// Check if any InfluxDB v3 output has write errors
outputs.influxdb_v3.exists(o, o.errors > 0)
// Check buffer fullness across all instances of an output
outputs.influxdb_v3.exists(o, o.buffer_fullness > 0.8)

Use has() to safely check if a plugin type exists before accessing it:

// Safe access — returns false if no cpu input is configured
has(outputs.influxdb_v3) && outputs.influxdb_v3.exists(o, o.errors > 0)

Accumulation behavior

Unless noted otherwise, all variable values are accumulated since the last successful heartbeat message. Use the last_update variable with now() to calculate rates — for example:

// True if the error rate exceeds 1 error per minute
log_errors > 0 && duration.getMinutes(now() - last_update) > 0
  && log_errors / duration.getMinutes(now() - last_update) > 1

Was this page helpful?

Thank you for your feedback!