Send Telegraf metrics to Zerobus Ingest with OpenTelemetry
The OpenTelemetry output is part of Telegraf, the open-source agent that collects metrics. For every option, see Telegraf's OpenTelemetry output plugin reference.
Maintained by: the Telegraf open-source project, in the influxdata/telegraf repository.
This page shows how to send Telegraf metrics to a Unity Catalog Delta table through Zerobus Ingest. Telegraf collects metrics from hosts, services, and applications, and writes them to outputs. Its OpenTelemetry output sends those metrics with OpenTelemetry Protocol (OTLP) over HTTP, Protobuf encoded, to the Zerobus Ingest OTLP metrics endpoint. Zerobus Ingest writes them into a Unity Catalog Delta table, with no broker or staging layer between Telegraf and the lakehouse.
When to use Telegraf with the OpenTelemetry output
- You already run Telegraf on your hosts or containers and want its metrics in Delta tables.
- You want all of Telegraf's metrics in one table that uses the OpenTelemetry metrics schema.
- You want Telegraf to refresh the OAuth token for a Databricks service principal, without a static token in the config.
How it works
- Interface: The
outputs.opentelemetryplugin is built into Telegraf. It sends each batch of metrics as OTLP/HTTP with Protobuf encoding to the Zerobus Ingest metrics endpoint. There's no separate plugin to install. - Field mapping: Each numeric field becomes a metric named
<measurement>_<field>, so theusage_userfield of thecpumeasurement becomes the metriccpu_usage_user. The metric is a gauge, unless the input plugin marks the field as a counter. Tags become the metric's attributes. Telegraf's OpenTelemetry output README describes this mapping. A string field doesn't produce a row, and no400is logged. See Troubleshooting. - Resource attributes: The
[outputs.opentelemetry.attributes]table sets resource attributes on every metric. Settingservice.namethere fills the table'sservice_namecolumn. - Table: The output writes every metric to the one table named in the
x-databricks-zerobus-table-nameheader. The table uses the fixed OpenTelemetry metrics schema from the Zerobus Ingest OTLP docs. See OpenTelemetry table reference for Zerobus Ingest. - Authentication: The
oauth2secret store requests a token for the Databricks service principal, and renews it before it expires. The output reads the token through a secret reference,@{<store-id>:<key>}. - Delivery: Zerobus Ingest delivers each record at least one time, so a retried batch can write a row more than one time. Telegraf retries a rejected batch every flush interval until it's stopped. See Handle duplicates and restarts.
Requirements
- Telegraf 1.39.0 and above. The OpenTelemetry output gained the
tokenoption this page uses in 1.39.0, and theoauth2secret store needs 1.28.0 and above. Install a stable release that meets that floor. - A workspace in a region that supports Zerobus Ingest, and a target table that meets the Zerobus Ingest table requirements. See Availability.
- A Databricks service principal with an OAuth secret and the Workspace access entitlement. See Configure authentication. Note the Databricks service principal's application ID and client secret.
- Databricks Runtime 17.3 and above to read and write the metrics table, because the Step 1 table definition enables variant shredding, which needs 17.3. See Use variant shredding and Create target tables in Unity Catalog.
- Network access from the Telegraf host to your workspace URL and to your Zerobus Ingest endpoint on port 443.
- Root access on the Telegraf host, with
sudo, to install the package and edit/etc/telegraf/telegraf.conf(Steps 2 and 4).
Step 1: Create the target table and grant access
Zerobus Ingest doesn't create tables, so create the metrics table before you start Telegraf. This is the metrics table from the Zerobus Ingest OTLP docs, with the name <catalog>.<schema>.<table>:
CREATE TABLE <catalog>.<schema>.<table> (
record_id STRING,
time TIMESTAMP,
date DATE,
service_name STRING,
start_time_unix_nano LONG,
time_unix_nano LONG,
name STRING,
description STRING,
unit STRING,
metric_type STRING,
gauge STRUCT<
value: DOUBLE,
exemplars: ARRAY<STRUCT<
time_unix_nano: LONG,
value: DOUBLE,
span_id: STRING,
trace_id: STRING,
filtered_attributes: VARIANT
>>,
attributes: VARIANT,
flags: INT
>,
sum STRUCT<
value: DOUBLE,
exemplars: ARRAY<STRUCT<
time_unix_nano: LONG,
value: DOUBLE,
span_id: STRING,
trace_id: STRING,
filtered_attributes: VARIANT
>>,
attributes: VARIANT,
flags: INT,
aggregation_temporality: STRING,
is_monotonic: BOOLEAN
>,
histogram STRUCT<
count: LONG,
sum: DOUBLE,
bucket_counts: ARRAY<LONG>,
explicit_bounds: ARRAY<DOUBLE>,
exemplars: ARRAY<STRUCT<
time_unix_nano: LONG,
value: DOUBLE,
span_id: STRING,
trace_id: STRING,
filtered_attributes: VARIANT
>>,
attributes: VARIANT,
flags: INT,
min: DOUBLE,
max: DOUBLE,
aggregation_temporality: STRING
>,
exponential_histogram STRUCT<
attributes: VARIANT,
count: LONG,
sum: DOUBLE,
scale: INT,
zero_count: LONG,
positive_bucket: STRUCT<
offset: INT,
bucket_counts: ARRAY<LONG>
>,
negative_bucket: STRUCT<
offset: INT,
bucket_counts: ARRAY<LONG>
>,
flags: INT,
exemplars: ARRAY<STRUCT<
time_unix_nano: LONG,
value: DOUBLE,
span_id: STRING,
trace_id: STRING,
filtered_attributes: VARIANT
>>,
min: DOUBLE,
max: DOUBLE,
zero_threshold: DOUBLE,
aggregation_temporality: STRING
>,
summary STRUCT<
count: LONG,
sum: DOUBLE,
quantile_values: ARRAY<STRUCT<
quantile: DOUBLE,
value: DOUBLE
>>,
attributes: VARIANT,
flags: INT
>,
metadata VARIANT,
resource STRUCT<
attributes: VARIANT,
dropped_attributes_count: INT
>,
resource_schema_url STRING,
instrumentation_scope STRUCT<
name: STRING,
version: STRING,
attributes: VARIANT,
dropped_attributes_count: INT
>,
metric_schema_url STRING
) USING DELTA
CLUSTER BY (time, service_name)
TBLPROPERTIES (
'otel.schemaVersion' = 'v2',
'delta.checkpointPolicy' = 'classic',
'delta.enableVariantShredding' = 'true', -- optional
'delta.feature.variantShredding' = 'supported', -- optional
'delta.feature.variantType' = 'supported' -- optional
);
Grant the Databricks service principal access to the catalog, the schema, and the table. Granting ALL PRIVILEGES isn't enough, so grant MODIFY and SELECT on the table explicitly. See Create a service principal and grant permissions.
GRANT USE CATALOG ON CATALOG <catalog> TO `<service-principal-uuid>`;
GRANT USE SCHEMA ON SCHEMA <catalog>.<schema> TO `<service-principal-uuid>`;
GRANT MODIFY, SELECT ON TABLE <catalog>.<schema>.<table> TO `<service-principal-uuid>`;
Step 2: Install Telegraf
Install Telegraf for your operating system, as Telegraf's install page describes. On Debian and Ubuntu, you can install the package from a .deb file. Download the .deb file for the version you want from the same page, then install it with its version number in the file name:
sudo dpkg -i telegraf_<version>_amd64.deb
telegraf --version
The package installs the configuration file at /etc/telegraf/telegraf.conf.
Step 3: Get your endpoints
The output needs two values:
- The Zerobus Ingest endpoint host, written as
<zerobus-endpoint>. In the configuration, you add thehttps://prefix and the/v1/metricspath. - Your workspace host, without the
https://prefix, written as<workspace-url>. The configuration adds the prefix. Theoauth2secret store uses its token endpoint to get OAuth tokens.
- Zerobus Ingest endpoint (
<zerobus-endpoint>):<workspace-id>.zerobus.<region>.gcp.databricks.com - Workspace URL:
<workspace-url>
To find your workspace ID, region, and URL, see Get your workspace URL and Zerobus Ingest endpoint.
Step 4: Configure the output
-
Back up the installed file:
Bashsudo cp /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.bakIf you keep your existing settings, merge the example's
[agent]settings and inputs into the sections that already exist, instead of adding a second[agent]table. -
Set the credentials. The Databricks service principal's application ID and client secret come from the
DATABRICKS_CLIENT_IDandDATABRICKS_CLIENT_SECRETenvironment variables, which Telegraf expands when it starts. Keep the secret out of the file. To keep it out of your shell history, read it in without typing it into a command. In bash:Bashexport DATABRICKS_CLIENT_ID=<client-id>read -rsp 'Client secret: ' DATABRICKS_CLIENT_SECRET && export DATABRICKS_CLIENT_SECRETTelegraf replaces
${...}variables before it parses the file, as Telegraf's configuration reference describes under environment variables. Its secret stores can hold the secret instead of an environment variable.For the packaged service, the shell's variables don't reach it. The
.debpackage reads variables from/etc/default/telegraf, so addDATABRICKS_CLIENT_ID="<client-id>"andDATABRICKS_CLIENT_SECRET="<client-secret>"to that file asNAME="value"lines. That file then holds the secret, so restrict it to the account that runs Telegraf, for example withchmod 0600, and check that Telegraf can still read it. -
Replace the file with the following complete example, and replace each placeholder. Replace the host in
service_addresswith your Zerobus Ingest endpoint from Step 3. The[[inputs.cpu]]and[[inputs.mem]]sections collect host metrics. Add any other Telegraf input the same way. Theservice.namevalue fills the table'sservice_namecolumn, so set it to your service's name.Toml[agent]interval = "5s"flush_interval = "5s"metric_batch_size = 1000metric_buffer_limit = 10000[[secretstores.oauth2]]id = "zbauth"service = "custom"token_endpoint = "https://<workspace-url>/oidc/v1/token"token_expiry_margin = "30s"[[secretstores.oauth2.token]]key = "zbtoken"client_id = "${DATABRICKS_CLIENT_ID}"client_secret = "${DATABRICKS_CLIENT_SECRET}"scopes = ["all-apis"][secretstores.oauth2.token.parameters]resource = "api://databricks/workspaces/<workspace-id>/zerobusDirectWriteApi"authorization_details = '[{"type":"unity_catalog_privileges","privileges":["USE CATALOG"],"object_type":"CATALOG","object_full_path":"<catalog>"},{"type":"unity_catalog_privileges","privileges":["USE SCHEMA"],"object_type":"SCHEMA","object_full_path":"<catalog>.<schema>"},{"type":"unity_catalog_privileges","privileges":["SELECT","MODIFY"],"object_type":"TABLE","object_full_path":"<catalog>.<schema>.<table>"}]'[[inputs.cpu]]percpu = falsetotalcpu = true[[inputs.mem]][[outputs.opentelemetry]]service_address = "https://<zerobus-endpoint>/v1/metrics"encoding_type = "protobuf"timeout = "30s"token = "@{zbauth:zbtoken}"[outputs.opentelemetry.attributes]"service.name" = "<service-name>"[outputs.opentelemetry.headers]x-databricks-zerobus-table-name = "<catalog>.<schema>.<table>" -
Validate the file, then restart the service and check its log. The
--testflag loads the configuration and gathers metrics without sending them. Run it in the foreground for testing only:Bashtelegraf --config /etc/telegraf/telegraf.conf --testThen restart the packaged service and read its log:
Bashsudo systemctl restart telegrafsudo journalctl -u telegraf -n 50After the first flush interval, the log shouldn't show
E!lines. If it does, see Troubleshooting.
Step 5: Check the table
After the first flush, the newest rows appear in the table. This query shows the latest metric names, values, and attributes:
SELECT time, name, gauge.value, to_json(gauge.attributes) AS attributes, service_name
FROM <catalog>.<schema>.<table>
ORDER BY time DESC
LIMIT 3;
Metrics from the cpu input appear with names such as cpu_usage_user, and the host tag appears in attributes. With service.name set as in Step 4, service_name holds that value on every row.
Troubleshooting
Symptom | Cause | Fix |
|---|---|---|
Telegraf logs | Telegraf 1.38.0 and above expand environment variables in strict mode by default | If the configuration loads and the variables expand, no action is needed. If it doesn't, start Telegraf with |
Telegraf logs | Zerobus Ingest OTLP documents partial success, but this endpoint returned 400 for the whole batch when one point had timestamp 0 (the Unix epoch), and rejected the other points in that batch too. Telegraf retries the same batch every flush interval. While writes fail, Telegraf holds up to | Find the point with the bad timestamp at its source and correct it. Watch the Telegraf log for |
Some points in a batch are missing, and Telegraf logs no error | Zerobus Ingest can accept the valid points in a batch and report the rejected points in a successful response, as partial success describes. Telegraf doesn't read that response, so the rejected points are dropped without a log line and without a retry. | Check the points at the source. The rejected records section lists the checks that reject a record. |
Metrics are missing after a crash or after | Telegraf holds unsent metrics in memory, in its default | Stop Telegraf with SIGTERM, for example |
A string field doesn't appear in the table, and Telegraf logs no | The output maps each field value to a float, per the output README. A string field doesn't produce a row, and no | Send numeric fields as metrics, and put text values in tags. |
| No | Set |
An unsigned integer with the | Cause not identified | Check the value in the table after the first flush. |
Handle duplicates and restarts
Zerobus Ingest delivers each record at least one time, so a retried batch can write a row more than one time. Deduplicate downstream if duplicates matter.
Telegraf keeps unsent metrics in memory, up to metric_buffer_limit per output. When writes fail, it keeps them across flush cycles, so a crash loses whatever is still in the buffer. A graceful stop with SIGTERM makes one final flush attempt. If writes still fail, the buffered metrics are lost on exit, so restore connectivity first. Telegraf's configuration reference describes an experimental disk value for buffer_strategy. This page does not use it.
Additional resources
- Configure OpenTelemetry (OTLP) clients: the endpoints, the required headers, and an OpenTelemetry Collector option that refreshes tokens for you.
- OpenTelemetry table reference: the metrics schema and the numeric precision limits.
- Example OpenTelemetry queries: queries for spans, logs, and metrics.
- Telegraf OpenTelemetry output reference: every option of the output.
- Telegraf configuration reference: agent settings for the flush interval and the buffer.
- Telegraf Zerobus example: a runnable dice-roll app that sends its metrics through Telegraf into a Delta table.