Skip to main content

Send Telegraf metrics to Zerobus Ingest with OpenTelemetry

info

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.opentelemetry plugin 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 the usage_user field of the cpu measurement becomes the metric cpu_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 no 400 is logged. See Troubleshooting.
  • Resource attributes: The [outputs.opentelemetry.attributes] table sets resource attributes on every metric. Setting service.name there fills the table's service_name column.
  • Table: The output writes every metric to the one table named in the x-databricks-zerobus-table-name header. The table uses the fixed OpenTelemetry metrics schema from the Zerobus Ingest OTLP docs. See OpenTelemetry table reference for Zerobus Ingest.
  • Authentication: The oauth2 secret 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 token option this page uses in 1.39.0, and the oauth2 secret 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>:

SQL
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.

SQL
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:

Bash
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 the https:// prefix and the /v1/metrics path.
  • Your workspace host, without the https:// prefix, written as <workspace-url>. The configuration adds the prefix. The oauth2 secret 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​

  1. Back up the installed file:

    Bash
    sudo cp /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.bak

    If 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.

  2. Set the credentials. The Databricks service principal's application ID and client secret come from the DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET environment 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:

    Bash
    export DATABRICKS_CLIENT_ID=<client-id>
    read -rsp 'Client secret: ' DATABRICKS_CLIENT_SECRET && export DATABRICKS_CLIENT_SECRET

    Telegraf 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 .deb package reads variables from /etc/default/telegraf, so add DATABRICKS_CLIENT_ID="<client-id>" and DATABRICKS_CLIENT_SECRET="<client-secret>" to that file as NAME="value" lines. That file then holds the secret, so restrict it to the account that runs Telegraf, for example with chmod 0600, and check that Telegraf can still read it.

  3. Replace the file with the following complete example, and replace each placeholder. Replace the host in service_address with 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. The service.name value fills the table's service_name column, so set it to your service's name.

    Toml
    [agent]
    interval = "5s"
    flush_interval = "5s"
    metric_batch_size = 1000
    metric_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 = false
    totalcpu = 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>"
  4. Validate the file, then restart the service and check its log. The --test flag loads the configuration and gathers metrics without sending them. Run it in the foreground for testing only:

    Bash
    telegraf --config /etc/telegraf/telegraf.conf --test

    Then restart the packaged service and read its log:

    Bash
    sudo systemctl restart telegraf
    sudo journalctl -u telegraf -n 50

    After 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:

SQL
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 W! Strict environment variable handling is the new default starting with v1.38.0!

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 --non-strict-env-handling.

Telegraf logs E! ... received unexpected status: Bad Request (400) every flush interval, and no new metrics appear

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 metric_buffer_limit metrics. When the buffer is full, it drops the oldest metrics, which can include the rejected point and valid metrics queued behind it, and logs Metric buffer overflow; N metrics have been dropped.

Find the point with the bad timestamp at its source and correct it. Watch the Telegraf log for Metric buffer overflow warnings. Stopping Telegraf ends the retries, but the buffered metrics are lost on exit while writes still fail.

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 kill -9

Telegraf holds unsent metrics in memory, in its default memory buffer, up to metric_buffer_limit per output. A crash loses whatever is still in the buffer.

Stop Telegraf with SIGTERM, for example kill <pid>. A graceful stop makes one final flush attempt. If writes still fail, the buffered metrics are lost on exit. To keep a backlog, restore connectivity and let the buffer drain before you stop Telegraf. See Handle duplicates and restarts.

A string field doesn't appear in the table, and Telegraf logs no 400 response for it

The output maps each field value to a float, per the output README. A string field doesn't produce a row, and no 400 response is logged.

Send numeric fields as metrics, and put text values in tags.

service_name is NULL in every row

No service.name resource attribute is set

Set service.name under [outputs.opentelemetry.attributes], as Step 4 shows.

An unsigned integer with the u suffix near the 64-bit maximum shows the wrong value in the table, for example -1.0 for value=18446744073709551615u

Cause not identified

Check the value in the table after the first flush.

Symptom

Cause

Fix

Telegraf logs W! Strict environment variable handling is the new default starting with v1.38.0!

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 --non-strict-env-handling.

Telegraf logs E! ... received unexpected status: Bad Request (400) every flush interval, and no new metrics appear

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 metric_buffer_limit metrics. When the buffer is full, it drops the oldest metrics, which can include the rejected point and valid metrics queued behind it, and logs Metric buffer overflow; N metrics have been dropped.

Find the point with the bad timestamp at its source and correct it. Watch the Telegraf log for Metric buffer overflow warnings. Stopping Telegraf ends the retries, but the buffered metrics are lost on exit while writes still fail.

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 kill -9

Telegraf holds unsent metrics in memory, in its default memory buffer, up to metric_buffer_limit per output. A crash loses whatever is still in the buffer.

Stop Telegraf with SIGTERM, for example kill <pid>. A graceful stop makes one final flush attempt. If writes still fail, the buffered metrics are lost on exit. To keep a backlog, restore connectivity and let the buffer drain before you stop Telegraf. See Handle duplicates and restarts.

A string field doesn't appear in the table, and Telegraf logs no 400 response for it

The output maps each field value to a float, per the output README. A string field doesn't produce a row, and no 400 response is logged.

Send numeric fields as metrics, and put text values in tags.

service_name is NULL in every row

No service.name resource attribute is set

Set service.name under [outputs.opentelemetry.attributes], as Step 4 shows.

An unsigned integer with the u suffix near the 64-bit maximum shows the wrong value in the table, for example -1.0 for value=18446744073709551615u

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​