Grafana Alloy
Grafana Alloy 是一个用于 OpenTelemetry (OTel)、Prometheus、Pyroscope、Loki 等其他指标、日志、追踪和分析工具的可观测性数据管道。 你可以将 GreptimeDB 集成为 Alloy 的数据接收端。
Prometheus Remote Write
将 GreptimeDB 配置为远程写入目标:
prometheus.remote_write "greptimedb" {
endpoint {
url = coalesce(sys.env("GREPTIME_SCHEME"), "http") + "://" +
coalesce(sys.env("GREPTIME_HOST"), "greptimedb") + ":" +
coalesce(sys.env("GREPTIME_PORT"), "4000") +
"/v1/prometheus/write?db=" + coalesce(sys.env("GREPTIME_DB"), "public")
basic_auth {
username = sys.env("GREPTIME_USERNAME")
password = sys.env("GREPTIME_PASSWORD")
}
}
}
GREPTIME_HOST: GreptimeDB 主机地址,例如localhost。GREPTIME_DB: GreptimeDB 数据库名称,默认是public。GREPTIME_USERNAME和GREPTIME_PASSWORD: GreptimeDB 的鉴权认证信息。
有关从 Prometheus 到 GreptimeDB 的数据模型转 换的详细信息,请参阅 Prometheus Remote Write 指南中的数据模型部分。
OpenTelemetry
GreptimeDB 也可以配置为 OpenTelemetry Collector 的目标。
指标
otelcol.exporter.otlphttp "greptimedb" {
client {
endpoint = coalesce(sys.env("GREPTIME_SCHEME"), "http") + "://" +
coalesce(sys.env("GREPTIME_HOST"), "greptimedb") + ":" +
coalesce(sys.env("GREPTIME_PORT"), "4000") + "/v1/otlp/"
headers = {
"X-Greptime-DB-Name" = coalesce(sys.env("GREPTIME_DB"), "public"),
}
auth = otelcol.auth.basic.credentials.handler
}
}
otelcol.auth.basic "credentials" {
username = sys.env("GREPTIME_USERNAME")
password = sys.env("GREPTIME_PASSWORD")
}
GREPTIME_HOST: GreptimeDB 主机地址,例如localhost。GREPTIME_DB: GreptimeDB 数据库名称,默认是public。GREPTIME_USERNAME和GREPTIME_PASSWORD: GreptimeDB 的鉴权认证信息。
有关从 OpenTelemetry 到 GreptimeDB 的指标数据模型转换的详细信息,请参阅 OpenTelemetry 指南中的数据模型部分。
日志
此示例通过 OpenTelemetry 管道将日志发送到 GreptimeDB。 对于生产环境中的日志管道,建议在 exporter 之前显式添加一个 batch processor。详情请参阅批处理部分。
loki.source.file "greptime" {
targets = [
{__path__ = "/tmp/foo.txt"},
]
forward_to = [otelcol.receiver.loki.greptime.receiver]
}
otelcol.receiver.loki "greptime" {
output {
logs = [otelcol.processor.batch.greptimedb_logs.input]
}
}
otelcol.processor.batch "greptimedb_logs" {
send_batch_size = 5000
send_batch_max_size = 10000
timeout = "1s"
output {
logs = [otelcol.exporter.otlphttp.greptimedb_logs.input]
}
}
otelcol.auth.basic "credentials" {
username = sys.env("GREPTIME_USERNAME")
password = sys.env("GREPTIME_PASSWORD")
}
otelcol.exporter.otlphttp "greptimedb_logs" {
client {
endpoint = coalesce(sys.env("GREPTIME_SCHEME"), "http") + "://" +
coalesce(sys.env("GREPTIME_HOST"), "greptimedb") + ":" +
coalesce(sys.env("GREPTIME_PORT"), "4000") + "/v1/otlp/"
headers = {
"X-Greptime-DB-Name" = coalesce(sys.env("GREPTIME_DB"), "public"),
"X-Greptime-Log-Table-Name" = coalesce(sys.env("GREPTIME_LOG_TABLE_NAME"), "demo_logs"),
"X-Greptime-Log-Extract-Keys" = "filename,log.file.name,loki.attribute.labels",
}
auth = otelcol.auth.basic.credentials.handler
}
sending_queue {
queue_size = 10000
num_consumers = 10
}
}
GREPTIME_HOST: GreptimeDB 主机地址,例如localhost。GREPTIME_DB: GreptimeDB 数据库名称,默认是public。GREPTIME_LOG_TABLE_NAME: 目标日志表名,默认为demo_logs。GREPTIME_USERNAME和GREPTIME_PASSWORD: GreptimeDB 的鉴权认证信息。X-Greptime-Log-Extract-Keys: 从 OTLP 日志属性中提取的键。详情请参阅 OTLP/HTTP API 文档。
有关从 OpenTelemetry 到 GreptimeDB 的日志数据模型转换的详细信息,请参阅 OpenTelemetry 指南中的数据模型部分。
Loki
GreptimeDB 也支持通过 Loki Push 协议写入日志。 如果你的 Alloy 日志管道本身就是基于 Loki 组件构建的,建议优先使用原生的 Loki 写入路径。 关于 Loki 协议的详细说明和数据模型映射,请参阅 Loki 指南。
日志
此示例仅使用 Loki 组件读取、处理并通过 Loki Push API 将日志发送到 GreptimeDB:
loki.source.file "greptime" {
targets = [
{__path__ = "/tmp/foo.txt"},
]
forward_to = [loki.process.greptime.receiver]
}
loki.process "greptime" {
forward_to = [loki.write.greptimedb.receiver]
stage.static_labels {
values = {
job = "greptime",
from = "alloy",
}
}
}
loki.write "greptimedb" {
endpoint {
url = coalesce(sys.env("GREPTIME_SCHEME"), "http") + "://" +
coalesce(sys.env("GREPTIME_HOST"), "greptimedb") + ":" +
coalesce(sys.env("GREPTIME_PORT"), "4000") + "/v1/loki/api/v1/push"
headers = {
"X-Greptime-DB-Name" = coalesce(sys.env("GREPTIME_DB"), "public"),
"X-Greptime-Log-Table-Name" = coalesce(sys.env("GREPTIME_LOG_TABLE_NAME"), "loki_demo_logs"),
}
basic_auth {
username = sys.env("GREPTIME_USERNAME")
password = sys.env("GREPTIME_PASSWORD")
}
}
}