文档文档

配置 Kapacitor

Kapacitor 服务的安装和启动基础知识已在“Kapacitor 入门”中介绍。在继续阅读本文档之前,您应该理解其中描述的 Kapacitor 工作原理。本文档将更详细地介绍 Kapacitor 的配置。

Kapacitor 服务的属性通过按组组织的键值对进行配置。任何属性键都可以通过其在配置文件中的路径找到(例如,[http].https-enabled[slack].channel)。配置键的值在配置文件中声明。

Kapacitor 配置文件位置

Kapacitor 会根据您的操作系统在特定位置查找配置文件。

  • Linux/etc/kapacitor/kapacitor.conf
  • macOS/usr/local/etc/kapacitor.conf
  • Windowskapacitord.exe 在同一目录

在启动时使用 -config 标志定义 kapacitor.conf 的自定义位置。配置文件路径也可以通过环境变量 KAPACITOR_CONFIG_PATH 声明。配置文件中声明的值会被以 KAPACITOR_ 开头的环境变量覆盖。一些值也可以通过 HTTP API 动态更改,前提是 [config-override].enabled 键设置为 true

配置优先级

使用一个或多个可用配置机制来配置 Kapacitor。配置机制按以下优先级顺序处理。

  1. 命令行参数
  2. HTTP API(用于 InfluxDB 连接和其他可选服务)
  3. 环境变量
  4. 配置文件值

注意: 将配置文件中的属性 skip-config-overrides 设置为 true 将禁用启动时的配置覆盖。

启动

要指定如何加载和运行 Kapacitor 守护程序,请设置以下命令行选项:

  • -config:配置文件的路径。
  • -hostname:将覆盖配置文件中指定的主机名的主机名。
  • -pidfile:将写入进程 ID 的文件。
  • -log-file:将写入日志的文件。
  • -log-level:写入日志文件的消息阈值。有效值包括 debug、info、warn、error

Systemd

在 POSIX 系统上,当 Kapacitor 守护程序作为 systemd 的一部分启动时,可以在 /etc/default/kapacitor 文件中设置环境变量。

  1. 要将 Kapacitor 作为 systemd 的一部分启动,请执行以下操作之一:

    $ sudo systemctl enable kapacitor
    $ sudo systemctl enable kapacitor —-now
  2. 定义 PID 文件和日志文件的写入位置

    1. 将类似以下的行添加到 /etc/default/kapacitor 文件中:

      KAPACITOR_OPTS="-pidfile=/home/kapacitor/kapacitor.pid -log-file=/home/kapacitor/logs/kapacitor.log"
    2. 重启 Kapacitor

      sudo systemctl restart kapacitor

环境变量 KAPACITOR_OPTS 是 Kapacitor 在启动时使用的一些特殊变量之一。有关处理环境变量的更多信息,请参阅下面的“Kapacitor 环境变量”

Kapacitor 配置文件

可以使用 Kapacitor 守护程序的 config 命令显示默认配置。

kapacitord config

Kapacitor 代码库中也提供了一个示例配置文件。最新的版本可以在 Github 上访问。

使用 Kapacitor HTTP API 来获取当前配置设置以及在 Kapacitor 服务运行时可以更改的值。请参阅“检索当前配置”

TOML

配置文件基于 TOML。重要的配置属性由区分大小写的键标识,并为其分配值。键值对被分组到由方括号分隔的表(tables)中。表也可以被分组到表数组(table arrays)中。

Kapacitor 配置文件中最常见的值类型包括以下内容:

  • 字符串(在双引号中声明)
    • 示例:host = "localhost"id = "myconsul"refresh-interval = "30s"
  • 整数
    • 示例:port = 80timeout = 0udp-buffer = 1000
  • 浮点数
    • 示例:threshold = 0.0
  • 布尔值
    • 示例:enabled = trueglobal = falseno-verify = false
  • 数组
    • 示例:my_database = [ "default", "longterm" ]urls = ["https://:8086"]
  • 内联表(Inline Table)
    • 示例:basic-auth = { username = "my-user", password = "my-pass" }

表(Table)的标识符在方括号内声明。例如:[http][deadman][kubernetes]

表数组(Array of tables)在双括号内声明。例如:[[influxdb]][[mqtt]][[dns]]

组织结构

大多数键都在表分组的上下文中声明,但 Kapacitor 系统的基本属性是在配置文件根目录上下文中定义的。Kapacitor 服务的四个基本属性包括:

  • hostname:声明 Kapacitor 守护程序运行的 DNS 主机的字符串。
  • data_dir:声明核心 Kapacitor 数据存储的文件系统目录的字符串。
  • skip-config-overrides:一个布尔值,指示是否跳过配置覆盖。
  • default-retention-policy:声明将在 InfluxDB 数据库上使用的默认保留策略的字符串。

表(Table)分组和表数组(Arrays of tables)遵循基本属性,并包含核心和可选功能,包括特定的警报处理程序以及服务发现和指标抓取机制。

核心配置组

身份验证和授权(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-versionmax-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 设置配置为“现代兼容性”,以提供更高的安全性,并假定不需要向后兼容。我们推荐的 ciphersmin-versionmax-version 的 TLS 配置设置基于 Mozilla 的“现代兼容性”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"

#...

Load

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"

#...

回放(Replay)

Kapacitor 可以记录数据流和批处理,以便在任务启用之前对其进行测试。使用 [replay] 组指定回放文件存储目录的路径。

# ...

[replay]
  # Where to store replay files.
  dir = "/var/lib/kapacitor/replay"

# ...

任务(Task)

在 Kapacitor 1.4 之前,任务被写入一个特殊的任务数据库。[task] 组及其关联的键已弃用,仅用于迁移目的。

存储(Storage)

Kapacitor 服务将其配置和其他信息存储在 BoltDB 中,这是一个基于文件的键值数据存储。使用 [storage] 组来定义 BoltDB 数据库文件在磁盘上的位置。

# ...

[storage]
  # Where to store the Kapacitor boltdb database
  boltdb = "/var/lib/kapacitor/kapacitor.db"

#...

死人开关(Deadman)

使用 [deadman] 组全局配置 Kapacitor 的死人开关。请参阅“死人开关”帮助函数主题在 AlertNode 文档中。

# ...

[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 包含可配置的内部服务,可以启用或禁用。

报告(Reporting)

Kapacitor 会将使用情况统计信息发送回 InfluxData。使用 [reporting] 组来禁用、启用和配置报告。

# ...

[reporting]
  # Send usage statistics
  # every 12 hours to Enterprise.
  enabled = true
  url = "https://usage.influxdata.com"

#...

Stats

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)

使用 [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

# ...

可选配置组

可选的表(Table)分组默认禁用,并且与可以通过 TICKscript 节点利用的特定功能相关,或者用于从远程位置发现和抓取信息。在默认配置中,这些可选的表分组可能被注释掉,或者包含一个设置为 falseenabled 键(例如,enabled = false)。当任务需要一个相关节点的节点或处理程序,或者需要一个输入源时,应该启用由可选表定义的某个功能。

可选功能包括:

事件处理程序(Event handlers)

事件处理程序管理 Kapacitor 与第三方服务或跨 Internet 标准消息协议的通信。它们通过AlertNode上的链式方法激活。

每个事件处理程序都有 enabled 属性。它们还需要一个发送消息的端点。端点可以包括单个属性(例如,urladdr)或属性对(例如,hostport)。大多数都包含身份验证机制,例如 token 或属性对,如 usernamepassword

有关可用事件处理程序及其配置选项的信息:

查看可用的事件处理程序

Docker 服务

使用 Kapacitor 通过 SwarmAutoScaleK8sAutoScale 节点触发 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
# ...

请参阅SwarmAutoscaleNode

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

用户定义函数(UDFs)

使用 Kapacitor 在 TICKscript 中通过链式方法运行用户定义函数(UDF)。在您的 kapacitor.conf 中使用组标识符模式定义一个 UDF 配置组:

[udf.functions.udf_name]

UDF 配置组需要以下属性:

属性描述值类型
prog可执行文件的路径string
args传递给可执行文件的参数字符串数组
timeout可执行文件响应超时string

使用组模式在 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"
# ...

其他示例可以在默认配置文件中找到。

输入方法(Input methods)

使用 Kapacitor 从 InfluxDB 以外的数据源接收和处理数据,然后将结果写入 InfluxDB。

支持以下源(除 InfluxDB 外):

  • Collectd:用于收集系统、网络和服务性能数据的 POSIX 守护程序。
  • Opentsdb:Open Time Series Database。
  • UDP:用户数据报协议。

每个输入源都有其配置特定的附加属性。

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"
# ...

查看 collectd 配置属性

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"
# ...

查看 Opentsdb 配置属性

用户数据报协议 (UDP)

使用 Kapacitor 从 UDP 连接收集原始数据。

# ...
[[udp]]
  enabled = true
  bind-address = ":9100"
  database = "game"
  retention-policy = "autogen"
# ...

查看 UDP 配置属性

有关使用 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" 

# ...

有关使用 Kapacitor 的 Flux 任务的更多信息,请参阅“使用 Flux 任务”

Kapacitor 环境变量

使用环境变量来设置全局 Kapacitor 配置设置或覆盖配置文件中的属性。

配置文件中不存在的环境变量

环境变量描述值类型
KAPACITOR_OPTSkapacitord 进程由 systemd 启动时,传递给 systemd 的选项string
KAPACITOR_CONFIG_PATHKapacitor 配置文件的路径string
KAPACITOR_URLkapacitor CLI 使用的 Kapacitor URLstring
KAPACITOR_UNSAFE_SSL允许 kapacitor CLI 在使用 SSL 时跳过证书验证boolean

将配置属性映射到环境变量

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 配置组或节都可以作为 JSON 文件查看,方法是使用 GET 请求方法并将组标识符附加到 /kapacitor/v1/config/ 端点。例如,要获取 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 覆盖配置的详细信息,请参阅“覆盖配置”


此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2