配置 Kapacitor
Kapacitor 服务的基本安装和启动在Kapacitor 入门中介绍。在继续阅读本文档之前,应理解其中描述的 Kapacitor 的基本工作原理。本文档更详细地介绍了 Kapacitor 配置。
Kapacitor 服务属性使用组织成组的键值对进行配置。任何属性键都可以通过在配置文件中遵循其路径来定位(例如,[http].https-enabled
或 [slack].channel
)。配置键的值在配置文件中声明。
Kapacitor 配置文件位置
Kapacitor 在特定位置查找配置文件,具体取决于您的操作系统
- Linux:
/etc/kapacitor/kapacitor.conf
- macOS:
/usr/local/etc/kapacitor.conf
- Windows: 与
kapacitord.exe
相同的目录
使用 -config
标志在启动时为您 kapacitor.conf
定义自定义位置。配置文件的路径也可以使用环境变量 KAPACITOR_CONFIG_PATH
声明。配置文件中声明的值将被以 KAPACITOR_
开头的环境变量覆盖。当键 [config-override].enabled
设置为 true
时,某些值也可以使用 HTTP API 动态更改。
配置优先级
使用一种或多种可用的配置机制配置 Kapacitor。配置机制按以下优先级顺序进行。
- 命令行参数
- HTTP API (用于 InfluxDB 连接和其他可选服务)
- 环境变量
- 配置文件值
注意: 将配置文件中的属性 skip-config-overrides
设置为 true
将禁用启动时的配置覆盖。
启动
要指定如何加载和运行 Kapacitor 守护程序,请设置以下命令行选项
-config
:配置文件的路径。-hostname
:将覆盖配置文件中指定的主机名。-pidfile
:将写入进程 ID 的文件。-log-file
:将写入日志的文件。-log-level
:将消息写入日志文件的阈值。有效值包括debug、info、warn、error
。
Systemd
在 POSIX 系统上,当 Kapacitor 守护程序作为 systemd
的一部分启动时,可以在文件 /etc/default/kapacitor
中设置环境变量。
要将 Kapacitor 作为
systemd
的一部分启动,请执行以下操作之一$ sudo systemctl enable kapacitor
$ sudo systemctl enable kapacitor —-now
定义 PID 文件和日志文件将写入的位置
在
/etc/default/kapacitor
文件中添加类似以下行的行KAPACITOR_OPTS="-pidfile=/home/kapacitor/kapacitor.pid -log-file=/home/kapacitor/logs/kapacitor.log"
重启 Kapacitor
sudo systemctl restart kapacitor
环境变量 KAPACITOR_OPTS
是 Kapacitor 在启动时使用的少数特殊变量之一。有关使用环境变量的更多信息,请参阅下面的Kapacitor 环境变量。
Kapacitor 配置文件
可以使用 Kapacitor 守护程序的 config
命令显示默认配置。
kapacitord config
示例配置文件也可在 Kapacitor 代码库中找到。最新版本可以在 Github 上访问。
使用 Kapacitor HTTP API 获取当前配置设置和 Kapacitor 服务运行时可以更改的值。请参阅检索当前配置。
TOML
配置文件基于 TOML。重要的配置属性由区分大小写的键标识,这些键被分配值。键值对被分组到表中,表的标识符用方括号分隔。表也可以分组到表数组中。
Kapacitor 配置文件中最常见的数值类型包括以下几种
- 字符串(用双引号声明)
- 示例:
host = "localhost"
,id = "myconsul"
,refresh-interval = "30s"
。
- 示例:
- 整数
- 示例:
port = 80
,timeout = 0
,udp-buffer = 1000
。
- 示例:
- 浮点数
- 示例:
threshold = 0.0
。
- 示例:
- 布尔值
- 示例:
enabled = true
,global = false
,no-verify = false
。
- 示例:
- 数组 –
- 示例:
my_database = [ "default", "longterm" ]
,urls = ["https://#:8086"]
- 示例:
- 内联表
- 示例:
basic-auth = { username = "my-user", password = "my-pass" }
- 示例:
表分组标识符在方括号内声明。例如,[http]
,[deadman]
,[kubernetes]
。
表数组在双括号内声明。例如,[[influxdb]]
。 [[mqtt]]
,[[dns]]
。
组织
大多数键在表分组的上下文中声明,但 Kapacitor 系统的基本属性在配置文件的根上下文中定义。Kapacitor 服务的四个基本属性包括
hostname
:声明 Kapacitor 守护程序运行的 DNS 主机名的字符串。data_dir
:声明存储核心 Kapacitor 数据的文件系统目录的字符串。skip-config-overrides
:指示是否跳过配置覆盖的布尔值。default-retention-policy
:声明要在 InfluxDB 数据库上使用的默认保留策略的字符串。
表分组和表数组遵循基本属性,并包括基本和可选功能,包括特定的警报处理程序以及用于服务发现和数据抓取的机制。
基本配置组
身份验证和授权 (auth)
在 Kapacitor 中启用和配置用户身份验证和授权。
[auth]
# Enable authentication for Kapacitor
enabled = false
# User permissions cache expiration time.
cache-expiration = "10m"
# Cost to compute bcrypt password hashes.
# bcrypt rounds = 2^cost
bcrypt-cost = 10
# Address of a meta server.
# If empty then meta, is not used as a user backend.
# host:port
meta-addr = "172.17.0.2:8091"
meta-use-tls = false
# Username for basic user authorization when using meta API. meta-password should also be set.
meta-username = "kapauser"
# Password for basic user authorization when using meta API. meta-username must also be set.
meta-password = "kapapass"
# Shared secret for JWT bearer token authentication when using meta API.
# If this is set, then the `meta-username` and `meta-password` settings are ignored.
# This should match the `[meta] internal-shared-secret` setting on the meta nodes.
meta-internal-shared-secret = "MyVoiceIsMyPassport"
# Absolute path to PEM encoded Certificate Authority (CA) file.
# A CA can be provided without a key/certificate pair.
meta-ca = "/etc/kapacitor/ca.pem"
# Absolute paths to PEM encoded private key and server certificate files.
meta-cert = "/etc/kapacitor/cert.pem"
meta-key = "/etc/kapacitor/key.pem"
meta-insecure-skip-verify = false
HTTP
Kapacitor 服务需要 HTTP 连接。使用 [http]
配置组配置 HTTP 属性,例如绑定地址和 HTTPS 证书的路径。
# ...
[http]
# HTTP API Server for Kapacitor
# This server is always on,
# it serves both as a write endpoint
# and as the API endpoint for all other
# Kapacitor calls.
bind-address = ":9092"
# Require authentication when interacting with Kapacitor
auth-enabled = false
log-enabled = true
write-tracing = false
pprof-enabled = false
https-enabled = false
https-certificate = "/etc/ssl/influxdb-selfsigned.pem"
shared-secret = ""
# The shared secret must match on all data and kapacitor nodes.
### Use a separate private key location.
# https-private-key = ""
# ...
传输层安全 (TLS)
如果未指定 TLS 配置设置,Kapacitor 支持 Go crypto/tls
包文档的常量部分中列出的所有密码套件 ID 和所有 TLS 版本,具体取决于用于构建 InfluxDB 的 Go 版本。使用 SHOW DIAGNOSTICS
命令查看用于构建 Kapacitor 的 Go 版本。
# ...
[tls]
ciphers = [
"TLS_AES_128_GCM_SHA256",
"TLS_AES_256_GCM_SHA384",
"TLS_CHACHA20_POLY1305_SHA256"
]
min-version = "tls1.3"
max-version = "tls1.3"
# ...
重要提示: ciphers
设置中密码套件 ID 的顺序决定了按优先级选择哪些算法。上面示例中的 TLS min-version
和 max-version
设置将支持限制为 TLS 1.3。
ciphers
可用 TLS 密码套件列表。默认为 ["TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"]
。
有关与用于构建 Kapacitor 的 Go 版本一起提供的可用密码列表,请参阅 Go crypto/tls
包。使用查询 SHOW DIAGNOSTICS
查看用于构建 Kapacitor 的 Go 版本。
min-version
将协商的 TLS 协议的最低版本。有效值包括
tls1.2
tls1.3
(默认)
max-version
将协商的 TLS 协议的最高版本。有效值包括
tls1.2
tls1.3
(默认)
现代兼容性的推荐配置
InfluxData 建议将 Kapacitor 服务器的 TLS 设置配置为“现代兼容性”,以提供更高级别的安全性,并假设不需要向后兼容性。我们推荐的 ciphers
、min-version
和 max-version
TLS 配置设置基于 Mozilla 在 Security/Server Side TLS 中描述的“现代兼容性”TLS 服务器配置。
InfluxData 推荐的“现代兼容性”TLS 设置在上面的配置设置示例中指定。
配置覆盖
[config-override]
组仅包含一个键,该键启用或禁用通过 HTTP API 覆盖某些值的能力。默认情况下启用它。
# ...
[config-override]
# Enable/Disable the service for overriding configuration via the HTTP API.
enabled = true
#...
日志记录
Kapacitor 服务使用日志记录来监控和检查其行为。日志的路径和日志阈值在 [logging]
组中定义。
# ...
[logging]
# Destination for logs
# Can be a path to a file or 'STDOUT', 'STDERR'.
file = "/var/log/kapacitor/kapacitor.log"
# Logging level can be one of:
# DEBUG, INFO, WARN, ERROR, or OFF
level = "INFO"
#...
加载
Kapacitor 可以在服务启动时加载 TICKscript 任务。使用 [load]
组启用此功能并指定要加载的 TICKscript 的目录路径。
# ...
[load]
# Enable/Disable the service for loading tasks/templates/handlers
# from a directory
enabled = true
# Directory where task/template/handler files are set
dir = "/etc/kapacitor/load"
#...
重放
Kapacitor 可以记录数据流和批处理,以便在启用任务之前对其进行测试。使用 [replay]
组指定存储重放文件的目录路径。
# ...
[replay]
# Where to store replay files.
dir = "/var/lib/kapacitor/replay"
# ...
任务
在 Kapacitor 1.4 之前,任务被写入特殊的任务数据库。[task]
组及其关联的键已弃用,应仅用于迁移目的。
存储
Kapacitor 服务将其配置和其他信息存储在 BoltDB(一种基于文件的键值数据存储)中。使用 [storage]
组定义磁盘上 BoltDB 数据库文件的位置。
# ...
[storage]
# Where to store the Kapacitor boltdb database
boltdb = "/var/lib/kapacitor/kapacitor.db"
#...
Deadman
使用 [deadman]
组全局配置 Kapacitor 的死人开关。请参阅 AlertNode 文档中的Deadman 帮助程序函数主题。
# ...
[deadman]
# Configure a deadman's switch
# Globally configure deadman's switches on all tasks.
# NOTE: for this to be of use you must also globally configure at least one alerting method.
global = false
# Threshold, if globally configured the alert will be triggered if the throughput in points/interval is <= threshold.
threshold = 0.0
# Interval, if globally configured the frequency at which to check the throughput.
interval = "10s"
# Id: the alert Id, NODE_NAME will be replaced with the name of the node being monitored.
id = "node 'NODE_NAME' in task '{{ .TaskName }}'"
# The message of the alert. INTERVAL will be replaced by the interval.
message = "{{ .ID }} is {{ if eq .Level \"OK\" }}alive{{ else }}dead{{ end }}: {{ index .Fields \"collected\" | printf \"%0.3f\" }} points/INTERVAL."
#...
InfluxDB
使用 [[influxdb]]
组配置 InfluxDB 连接。配置一个或多个 [[influxdb]]
组配置,每个 InfluxDB 连接一个。将其中一个 InfluxDB 组标识为 default
。
InfluxDB 用户必须具有管理员权限
要将 Kapacitor 与需要身份验证的 InfluxDB 实例一起使用,InfluxDB 用户必须具有管理员权限。
# ...
[[influxdb]]
# Connect to InfluxDB
# Kapacitor can subscribe, query, and write to this cluster.
# Using InfluxDB is not required and can be disabled.
# To connect to InfluxDB OSS 1.x or InfluxDB Enterprise,
# use the following configuration:
enabled = true
default = true
name = "localhost"
urls = ["https://#:8086"]
username = ""
password = ""
timeout = 0
# To connect to InfluxDB OSS 2.x or InfluxDB Cloud,
# use the following configuration:
enabled = true
default = true
name = "localhost"
urls = ["https://#:8086"]
token = ""
timeout = 0
# By default, all data sent to InfluxDB is compressed in gzip format.
# To turn off gzip compression, add the following config setting:
compression = "none"
# Absolute path to pem encoded CA file.
# A CA can be provided without a key/cert pair
# ssl-ca = "/etc/kapacitor/ca.pem"
# Absolutes paths to pem encoded key and cert files.
# ssl-cert = "/etc/kapacitor/cert.pem"
# ssl-key = "/etc/kapacitor/key.pem"
# Do not verify the TLS/SSL certificate.
# This is insecure.
insecure-skip-verify = false
# Maximum time to try and connect to InfluxDB during startup
startup-timeout = "5m"
# Turn off all subscriptions
disable-subscriptions = false
# Subscription mode is either "cluster" or "server"
subscription-mode = "server"
# Which protocol to use for subscriptions
# one of 'udp', 'http', or 'https'.
subscription-protocol = "http"
# Subscriptions resync time interval
# Useful if you want to subscribe to new created databases
# without restart Kapacitord
subscriptions-sync-interval = "1m0s"
# Override the global hostname option for this InfluxDB cluster.
# Useful if the InfluxDB cluster is in a separate network and
# needs special configuration to connect back to this Kapacitor instance.
# Defaults to `hostname` if empty.
kapacitor-hostname = ""
# Override the global http port option for this InfluxDB cluster.
# Useful if the InfluxDB cluster is in a separate network and
# needs special configuration to connect back to this Kapacitor instance.
# Defaults to the port from `[http] bind-address` if 0.
http-port = 0
# Host part of a bind address for UDP listeners.
# For example if a UDP listener is using port 1234
# and `udp-bind = "hostname_or_ip"`,
# then the UDP port will be bound to `hostname_or_ip:1234`
# The default empty value will bind to all addresses.
udp-bind = ""
# Subscriptions use the UDP network protocol.
# The following options of for the created UDP listeners for each subscription.
# Number of packets to buffer when reading packets off the socket.
udp-buffer = 1000
# The size in bytes of the OS read buffer for the UDP socket.
# A value of 0 indicates use the OS default.
udp-read-buffer = 0
[influxdb.subscriptions]
# Set of databases and retention policies to subscribe to.
# If empty will subscribe to all, minus the list in
# influxdb.excluded-subscriptions
#
# Format
# db_name = <list of retention policies>
#
# Example:
# my_database = [ "default", "longterm" ]
[influxdb.excluded-subscriptions]
# Set of databases and retention policies to exclude from the subscriptions.
# If influxdb.subscriptions is empty it will subscribe to all
# except databases listed here.
#
# Format
# db_name = <list of retention policies>
#
# Example:
# my_database = [ "default", "longterm" ]
# ...
内部配置组
Kapacitor 包括可配置的内部服务,可以启用或禁用。
报告
Kapacitor 会将使用情况统计信息发送回 InfluxData。使用 [reporting]
组禁用、启用和配置报告。
# ...
[reporting]
# Send usage statistics
# every 12 hours to Enterprise.
enabled = true
url = "https://usage.influxdata.com"
#...
统计信息
Kapacitor 可以将内部 Kapacitor 统计信息输出到 InfluxDB 数据库。使用 [stats]
组配置收集频率和存储统计信息的数据库。
# ...
[stats]
# Emit internal statistics about Kapacitor.
# To consume these stats, create a stream task
# that selects data from the configured database
# and retention policy.
#
# Example:
# stream|from().database('_kapacitor').retentionPolicy('autogen')...
#
enabled = true
stats-interval = "10s"
database = "_kapacitor"
retention-policy= "autogen"
# ...
警报
使用 [alert]
组全局配置由 alertNode 创建的警报。
# ...
[alert]
# Persisting topics can become an I/O bottleneck under high load.
# This setting disables them entirely.
persist-topics = false
# This setting sets the topic queue length.
# Default is 5000. Minimum length is 1000.
topic-buffer-length = 5000
# ...
可选配置组
可选表分组默认情况下处于禁用状态,并且与 TICKscript 节点可以利用的特定功能或用于发现和抓取远程位置的信息的功能相关。在默认配置中,这些可选表分组可能会被注释掉或包含一个键 enabled
设置为 false
(即 enabled = false
)。每当任务需要相关节点或相关节点的处理程序,或者需要输入源时,都应启用由可选表定义的功能。
可选功能包括
事件处理程序
事件处理程序管理从 Kapacitor 到第三方服务或跨互联网标准消息传递协议的通信。它们通过 AlertNode 上的链接方法激活。
每个事件处理程序都具有属性 enabled
。它们还需要一个端点来发送消息。端点可能包括单个属性(例如,url
和 addr
)或属性对(例如,host
和 port
)。大多数包括身份验证机制,例如 token
或一对属性,如 username
和 password
。
有关可用事件处理程序及其配置选项的信息
Docker 服务
使用 Kapacitor 通过 SwarmAutoScale 和 K8sAutoScale 节点触发 Docker 集群中的更改。
Swarm
# ...
[[swarm]]
# Enable/Disable the Docker Swarm service.
# Needed by the swarmAutoscale TICKscript node.
enabled = false
# Unique ID for this Swarm cluster
# NOTE: This is not the ID generated by Swarm rather a user defined
# ID for this cluster since Kapacitor can communicate with multiple clusters.
id = ""
# List of URLs for Docker Swarm servers.
servers = ["https://#:2376"]
# TLS/SSL Configuration for connecting to secured Docker daemons
ssl-ca = ""
ssl-cert = ""
ssl-key = ""
insecure-skip-verify = false
# ...
Kubernetes
# ...
[kubernetes]
# Enable/Disable the kubernetes service.
# Needed by the k8sAutoscale TICKscript node.
enabled = false
# There are several ways to connect to the kubernetes API servers:
#
# Via the proxy, start the proxy via the `kubectl proxy` command:
# api-servers = ["https://#:8001"]
#
# From within the cluster itself, in which case
# kubernetes secrets and DNS services are used
# to determine the needed configuration.
# in-cluster = true
#
# Direct connection, in which case you need to know
# the URL of the API servers, the authentication token and
# the path to the ca cert bundle.
# These value can be found using the `kubectl config view` command.
# api-servers = ["http://192.168.99.100:8443"]
# token = "..."
# ca-path = "/path/to/kubernetes/ca.crt"
#
# Kubernetes can also serve as a discoverer for scrape targets.
# In that case the type of resources to discoverer must be specified.
# Valid values are: "node", "pod", "service", and "endpoint".
# resource = "pod"
# ...
请参阅K8sAutoScaleNode。
用户定义的函数 (UDF)
使用 Kapacitor 运行用户定义的函数 (UDF),作为 TICKscript 中的链接方法。在您的 kapacitor.conf
中使用组标识符模式定义 UDF 配置组
[udf.functions.udf_name]
UDF 配置组需要以下属性
属性 | 描述 | 值类型 |
---|---|---|
prog | 可执行文件的路径 | 字符串 |
args | 传递给可执行文件的参数 | 字符串数组 |
timeout | 可执行文件响应超时 | 字符串 |
使用组模式在您的 UDF 配置组中包含环境变量
[udf.functions.udf_name.env]
示例 UDF 配置
# ...
[udf]
# Configuration for UDFs (User Defined Functions)
[udf.functions]
# ...
# Example Python UDF.
# Use in TICKscript:
# stream.pyavg()
# .field('value')
# .size(10)
# .as('m_average')
#
[udf.functions.pyavg]
prog = "/usr/bin/python2"
args = ["-u", "./udf/agent/examples/moving_avg.py"]
timeout = "10s"
[udf.functions.pyavg.env]
PYTHONPATH = "./udf/agent/py"
# ...
其他示例可以在默认配置文件中找到。
输入方法
使用 Kapacitor 接收和处理来自 InfluxDB 以外的数据源的数据,然后将结果写入 InfluxDB。
支持以下来源(除 InfluxDB 外)
每个输入源都有特定于其配置的其他属性。
Collectd
# ...
[collectd]
enabled = false
bind-address = ":25826"
database = "collectd"
retention-policy = ""
batch-size = 1000
batch-pending = 5
batch-timeout = "10s"
typesdb = "/usr/share/collectd/types.db"
# ...
Opentsdb
# ...
[opentsdb]
enabled = false
bind-address = ":4242"
database = "opentsdb"
retention-policy = ""
consistency-level = "one"
tls-enabled = false
certificate = "/etc/ssl/influxdb.pem"
batch-size = 1000
batch-pending = 5
batch-timeout = "1s"
# ...
用户数据报协议 (UDP)
使用 Kapacitor 从 UDP 连接收集原始数据。
# ...
[[udp]]
enabled = true
bind-address = ":9100"
database = "game"
retention-policy = "autogen"
# ...
有关使用 Kapacitor 收集原始 UDP 数据的示例,请参阅
服务发现和指标抓取
Kapacitor 服务发现和指标抓取器允许您在运行时发现和抓取来自数据源的指标。此过程称为指标抓取和发现。有关更多信息,请参阅抓取和发现。
使用 [[scraper]]
配置组配置抓取器和服务发现。一个抓取器可以绑定到一个发现服务。
示例抓取器配置
# ...
[[scraper]]
enabled = false
name = "myscraper"
# Specify the id of a discoverer service specified below
discoverer-id = "goethe-ec2"
# Specify the type of discoverer service being used.
discoverer-service = "ec2"
db = "prometheus_raw"
rp = "autogen"
type = "prometheus"
scheme = "http"
metrics-path = "/metrics"
scrape-interval = "1m0s"
scrape-timeout = "10s"
username = "schwartz.pudel"
password = "f4usT!1808"
bearer-token = ""
ssl-ca = ""
ssl-cert = ""
ssl-key = ""
ssl-server-name = ""
insecure-skip-verify = false
# ...
发现服务
Kapacitor 支持以下发现服务
- Azure
- Consul
- DNS
- EC2
- 文件发现
- GCE
- Marathon
- Nerve
- ServerSet
- 静态发现
- Triton
- UDP
每个发现服务都有一个 id
属性,用于将服务绑定到抓取器。要查看每个发现服务独有的配置属性,请参阅示例 Kapacitor 配置文件。
示例 EC2 发现服务配置
# ...
[[ec2]]
enabled = false
id = "goethe-ec2"
region = "us-east-1"
access-key = "ABCD1234EFGH5678IJKL"
secret-key = "1nP00dl3N01rM4Su1v1Ju5qU3ch3ZM01"
profile = "mph"
refresh-interval = "1m0s"
port = 80
# ...
Flux 任务
使用 [fluxtask]
配置组启用和配置 Kapacitor Flux 任务。
# ...
[fluxtask]
# Configure flux tasks for kapacitor
enabled = false
# The InfluxDB instance name (from the [[influxdb]] config section)
# to store historical task run data in
# Not recommended: use "none" to turn off historical task run data storage.
task-run-influxdb = "localhost"
# Bucket to store historical task run data in. We recommend leaving this empty; by default, data is written to the `kapacitor_fluxtask_logs` bucket or database.
# If you have multiple Kapacitor instances and want to keep your data separate, specify the InfluxDB 2.x bucket or InfluxDB 1.x database to write to. For InfluxDB 1.x, use the `"mydb"` convention--the `"mydb/rp"` convention with the retention policy is not supported.
task-run-bucket=" "
# The organization name or ID if storing historical task run data
# in InfluxDB 2.x or InfluxDB Cloud
task-run-org = ""
task-run-orgid = ""
# The measurement name for the historical task run data
task-run-measurement = "runs"
# ...
有关将 Flux 任务与 Kapacitor 一起使用的更多信息,请参阅使用 Flux 任务。
Kapacitor 环境变量
使用环境变量设置全局 Kapacitor 配置设置或覆盖配置文件中的属性。
配置文件中没有的环境变量
环境变量 | 描述 | 值类型 |
---|---|---|
KAPACITOR_OPTS | 当 kapacitord 进程由 systemd 启动时传递给 systemd 的选项 | 字符串 |
KAPACITOR_CONFIG_PATH | Kapacitor 配置文件的路径 | 字符串 |
KAPACITOR_URL | kapacitor CLI 使用的 Kapacitor URL | 字符串 |
KAPACITOR_UNSAFE_SSL | 允许 kapacitor CLI 在使用 SSL 时跳过证书验证 | 布尔值 |
将配置属性映射到环境变量
Kapacitor 特定的环境变量以标记 KAPACITOR
开头,后跟下划线 (_
)。然后,属性遵循其在配置文件树中的路径,树中的每个节点用下划线分隔。配置文件标识符中的破折号替换为下划线。表数组中的表分组由整数标记标识。
示例环境变量映射
# Set the skip-config-overrides configuration property
KAPACITOR_SKIP_CONFIG_OVERRIDES=false
# Set the value of the first URLs in the first InfluxDB configuration group
# [infludxb][0].[urls][0]
KAPACITOR_INFLUXDB_0_URLS_0=(https://#:8086)
# Set the value of the [storage].boltdb configuration property
KAPACITOR_STORAGE_BOLTDB=/var/lib/kapacitor/kapacitor.db
# Set the value of the authorization header in the first httpost configuration group
# [httppost][0].headers.{authorization:"some_value"}
KAPACITOR_HTTPPOST_0_HEADERS_Authorization=some_value
# Enable the Kubernetes service – [kubernetes].enabled
KAPACITOR_KUBERNETES_ENABLED=true
使用 HTTP API 配置
使用Kapacitor HTTP API 覆盖某些配置属性。当属性可能包含安全敏感信息或当您需要重新配置服务而无需重启 Kapacitor 时,这很有用。
要查看哪些属性可以通过 API 配置,请将 GET
请求方法与 /kapacitor/v1/config
端点一起使用
GET /kapacitor/v1/config
curl --request GET 'https://#:9092/kapacitor/v1/config'
要通过 API 应用配置覆盖,请将 Kapacitor 配置文件中的 [config-override].enabled
属性设置为 true
。
查看配置部分
大多数 Kapacitor 配置组或部分可以通过使用 GET
请求方法并将组标识符附加到 /kapacitor/v1/config/
端点来查看为 JSON 文件。例如,要获取 InfluxDB 配置属性
GET /kapacitor/v1/config/influxdb
curl --request GET 'https://#:9092/kapacitor/v1/config/influxdb'
当使用 GET
请求方法时,敏感字段(如密码、密钥和安全令牌)将被编辑。
修改配置部分
要修改配置属性,请使用 POST
请求方法将 JSON 文档发送到配置部分端点。JSON 文档必须包含一个 set
字段,其中包含要覆盖的属性及其新值的映射。
POST /kapacitor/v1/config/{config-group}
启用 SMTP 配置
curl --request POST 'https://#:9092/kapacitor/v1/config/smtp' \
--data '{
"set":{
"enabled": true
}
}'
要删除配置覆盖,请使用 POST
请求方法将带有 delete
字段的 JSON 文档发送到配置端点。
删除 SMTP 配置覆盖
curl --request POST 'https://#:9092/kapacitor/v1/config/smtp' \
--data '{
"delete":[
"enabled"
]
}'
有关如何使用 Kapacitor API 覆盖配置的详细信息,请参阅覆盖配置。
此页是否对您有帮助?
感谢您的反馈!