配置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。
系统d
在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 environment variables。
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 = ["http://localhost: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支持列出的所有密码套件ID以及在Go crypto/tls包文档的常量部分中实现的所有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。
密码
可用的TLS密码套件列表。 默认值是 ["TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"]。
有关与用于构建Kapacitor的Go版本可用的密码列表,请参见Go crypto/tls package。使用查询SHOW DIAGNOSTICS可以查看用于构建Kapacitor的Go版本。
最小版本
将要协商的TLS协议的最低版本。有效值包括:
tls1.2tls1.3(默认)
最大版本
将协商的TLS协议的最大版本。有效值包括:
tls1.2tls1.3(默认)
现代兼容性推荐配置
InfluxData 推荐为您的 Kapacitor 服务器配置 TLS 设置以实现“现代兼容性”,以提供更高的安全级别,并假设不需要向后兼容。 我们推荐的 TLS 配置设置对于 ciphers、min-version 和 max-version 基于 Mozilla 的“现代兼容性”TLS 服务器配置,具体描述见 Security/Server Side 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] 组来启用此功能并指定要加载的 TICKscripts 的目录路径。
# ...
[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] 组全局配置 Kapacitor 的死区开关。请参阅警报节点文档中的 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 组标识为 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 = ["http://localhost: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 = ["http://localhost: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 可以将内部统计信息输出到 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在Docker集群中触发变化,配合SwarmAutoScale和K8sAutoScale节点。
群体
# ...
[[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 = ["http://localhost: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 = ["http://localhost: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.
用户定义函数 (UDFs)
使用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 之外):
每个输入源都有特定于其配置的其他属性。
收集数据的工具
# ...
[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]
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
- 域名系统
- 弹性云计算(EC2)
- 文件发现
- 谷歌计算引擎
- 马拉松
- 神经
- 服务器集
- 静态发现
- Triton
- 用户数据报协议
每个发现服务都有一个 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"
# ...
有关在Kapacitor中使用Flux任务的更多信息,请参见 使用Flux任务。
Kapacitor 环境变量
使用环境变量来设置全局Kapacitor配置设置或覆盖配置文件中的属性。
环境变量不在配置文件中
| 环境变量 | 描述 | 值类型 |
|---|---|---|
KAPACITOR_OPTS | 启动kapacitord进程时,传递给systemd的选项 | 字符串 |
KAPACITOR_CONFIG_PATH | Kapacitor 配置文件的路径 | string |
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=(http://localhost: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/configcurl --request GET 'http://localhost:9092/kapacitor/v1/config'
要通过API应用配置覆盖,请在您的Kapacitor配置文件中将[config-override].enabled
属性设置为true。
查看配置部分
大多数Kapacitor配置组或部分可以通过使用GET请求方法并将组标识符附加到/kapacitor/v1/config/端点来查看为JSON文件。比如,获取InfluxDB配置属性:
GET /kapacitor/v1/config/influxdbcurl --request GET 'http://localhost:9092/kapacitor/v1/config/influxdb'
敏感字段如密码、密钥和安全令牌在使用GET请求方法时会被遮蔽。
修改配置部分
要修改配置属性,使用 POST 请求方法将 JSON 文档发送到配置部分端点。 JSON 文档必须包含一个 set 字段,里面是要覆盖的属性及其新值的映射。
POST /kapacitor/v1/config/{config-group}启用SMTP配置
curl --request POST 'http://localhost:9092/kapacitor/v1/config/smtp' \
--data '{
"set":{
"enabled": true
}
}'
要移除配置覆盖,使用 POST 请求方法发送一个包含 delete 字段的 JSON 文档到配置端点。
删除SMTP配置覆盖
curl --request POST 'http://localhost:9092/kapacitor/v1/config/smtp' \
--data '{
"delete":[
"enabled"
]
}'
有关如何使用Kapacitor API覆盖配置的详细信息,请参见 覆盖配置。