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