1 参数查询

Prometheus命令参数可通过./prometheus -h查询。

usage: prometheus [<flags>]

The Prometheus monitoring server

Flags:
  -h, --help                     Show context-sensitive help (also try --help-long and
                                 --help-man).
      --version                  Show application version.
      --config.file="prometheus.yml"
                                 Prometheus configuration file path.
      --web.listen-address="0.0.0.0:9090"
                                 Address to listen on for UI, API, and telemetry.
      --web.config.file=""       [EXPERIMENTAL] Path to configuration file that can
                                 enable TLS or authentication.
      --web.read-timeout=5m      Maximum duration before timing out read of the
                                 request, and closing idle connections.
      --web.max-connections=512  Maximum number of simultaneous connections.
      --web.external-url=<URL>   The URL under which Prometheus is externally
                                 reachable (for example, if Prometheus is served via a
                                 reverse proxy). Used for generating relative and
                                 absolute links back to Prometheus itself. If the URL
                                 has a path portion, it will be used to prefix all
                                 HTTP endpoints served by Prometheus. If omitted,
                                 relevant URL components will be derived
                                 automatically.
      --web.route-prefix=<path>  Prefix for the internal routes of web endpoints.
                                 Defaults to path of --web.external-url.
      --web.user-assets=<path>   Path to static asset directory, available at /user.
      --web.enable-lifecycle     Enable shutdown and reload via HTTP request.
      --web.enable-admin-api     Enable API endpoints for admin control actions.
      --web.console.templates="consoles"
                                 Path to the console template directory, available at
                                 /consoles.
      --web.console.libraries="console_libraries"
                                 Path to the console library directory.
      --web.page-title="Prometheus Time Series Collection and Processing Server"
                                 Document title of Prometheus instance.
      --web.cors.origin=".*"     Regex for CORS origin. It is fully anchored. Example:
                                 'https?://(domain1|domain2)\.com'
      --storage.tsdb.path="data/"
                                 Base path for metrics storage.
      --storage.tsdb.retention=STORAGE.TSDB.RETENTION
                                 [DEPRECATED] How long to retain samples in storage.
                                 This flag has been deprecated, use
                                 "storage.tsdb.retention.time" instead.
      --storage.tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME
                                 How long to retain samples in storage. When this flag
                                 is set it overrides "storage.tsdb.retention". If
                                 neither this flag nor "storage.tsdb.retention" nor
                                 "storage.tsdb.retention.size" is set, the retention
                                 time defaults to 15d. Units Supported: y, w, d, h, m,
                                 s, ms.
      --storage.tsdb.retention.size=STORAGE.TSDB.RETENTION.SIZE
                                 Maximum number of bytes that can be stored for
                                 blocks. A unit is required, supported units: B, KB,
                                 MB, GB, TB, PB, EB. Ex: "512MB".
      --storage.tsdb.no-lockfile
                                 Do not create lockfile in data directory.
      --storage.tsdb.allow-overlapping-blocks
                                 Allow overlapping blocks, which in turn enables
                                 vertical compaction and vertical query merge.
      --storage.remote.flush-deadline=<duration>
                                 How long to wait flushing sample on shutdown or
                                 config reload.
      --storage.remote.read-sample-limit=5e7
                                 Maximum overall number of samples to return via the
                                 remote read interface, in a single query. 0 means no
                                 limit. This limit is ignored for streamed response
                                 types.
      --storage.remote.read-concurrent-limit=10
                                 Maximum number of concurrent remote read calls. 0
                                 means no limit.
      --storage.remote.read-max-bytes-in-frame=1048576
                                 Maximum number of bytes in a single frame for
                                 streaming remote read response types before
                                 marshalling. Note that client might have limit on
                                 frame size as well. 1MB as recommended by protobuf by
                                 default.
      --rules.alert.for-outage-tolerance=1h
                                 Max time to tolerate prometheus outage for restoring
                                 "for" state of alert.
      --rules.alert.for-grace-period=10m
                                 Minimum duration between alert and restored "for"
                                 state. This is maintained only for alerts with
                                 configured "for" time greater than grace period.
      --rules.alert.resend-delay=1m
                                 Minimum amount of time to wait before resending an
                                 alert to Alertmanager.
      --alertmanager.notification-queue-capacity=10000
                                 The capacity of the queue for pending Alertmanager
                                 notifications.
      --query.lookback-delta=5m  The maximum lookback duration for retrieving metrics
                                 during expression evaluations and federation.
      --query.timeout=2m         Maximum time a query may take before being aborted.
      --query.max-concurrency=20
                                 Maximum number of queries executed concurrently.
      --query.max-samples=50000000
                                 Maximum number of samples a single query can load
                                 into memory. Note that queries will fail if they try
                                 to load more samples than this into memory, so this
                                 also limits the number of samples a query can return.
      --enable-feature= ...      Comma separated feature names to enable. Valid
                                 options: exemplar-storage, expand-external-labels,
                                 memory-snapshot-on-shutdown, promql-at-modifier,
                                 promql-negative-offset, remote-write-receiver,
                                 extra-scrape-metrics. See
                                 https://prometheus.io/docs/prometheus/latest/feature_flags/
                                 for more details.
      --log.level=info           Only log messages with the given severity or above.
                                 One of: [debug, info, warn, error]
      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]

2 参数说明

参数

描述

--version

显示版本信息

--confi.file="xxxxxxxxx"

指定配置文件

--web.listen-address=“0.0.0.0:9090”

ui、api、telemetry监听地址信息

--web.config.file=""

TLS或身份验证配置文件

--web.read-timeout=5m

页面读取请求最大超时时间 

--web.max-connections=512

同时访问Prometheus页面的最大连接数,默认为512

 --web.external-url=<URL>

Prometheus对外提供的url(eg: Prometheus通过反向代理提供服务)。用于生成一个相对和绝对的链接返回给Prometheus本身。如果这个url有路径部分,它将用于Prometheus所有HTTP端点的前缀。如果省略了,则相关的url组件将自动派生

 --web.route-prefix=<path>

Web端点内部路由的前缀。默认路径:web.external-url

--web.user-assets=<path>

静态资源路径,可以在/user下找到

 --web.enable-lifecycle

通过HTTP请求启用关闭和重新加载

--web.enable-admin-api

启用管理控制操作的api端点

--web.console.templates="consoles"

到控制台模板目录的路径,可以在consoles/目录下找到。

--web.console.libraries="console_libraries"

控制台库目录的路径

–web.page-title=”Prometheus时间序列采集和处理服务器”

Prometheus实例的文件标题。

--web.cors.origin=".*"

正则表达式为CORS原点。它已完全锚定。例子:“https ?: / / (domain1 | domain2) \。com”

--storage.tsdb.path="data/"

数据存储的基本路径

 --storage.tsdb.min-block-duration=2h

在持久化之前数据块的最短保存期

 --storage.tsdb.max-block-duration=<duration>

在持久化之前数据块的最大保存期(默认为保存期的10%)

  --storage.tsdb.retention=STORAGE.TSDB.RETENTION

样品保存的时间。此标志已被弃用,请使用“storage.tsdb.retention”。时间”。——storage.tsdb.retention。时间= STORAGE.TSDB.RETENTION。保存样品的时间。当设置此标志时,它将覆盖“storage.tsdb.retention”。如果既没有这个标志,也没有“storage.tsdb”。保留”也不“storage.tsdb.retention。设置大小,保留时间默 认为15d。支持单位:y, w, d, h, m, s, ms。

 --storage.tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME

样品保存的时间。此标志已被弃用,请使用“storage.tsdb.retention”。时间”。——storage.tsdb.retention。时间= STORAGE.TSDB.RETENTION。保存样品的时间。当设置此标志时,它将覆盖“storage.tsdb.retention”。如果既没有这个标志,也没有“storage.tsdb”。保留”也不“storage.tsdb.retention。设置大小,保留时间默 认为15d。支持单位:y, w, d, h, m, s, ms。

 --storage.tsdb.retention.size=

STORAGE.TSDB.RETENTION。大小[实验]块可以存储的最大字节数。需要一个单位,支持单位:B, KB, MB, GB, TB, PB, EB。例:“512 mb”。这个标志是实验性的,可以在以后的版本中更改。——storage.tsdb。不要在数据目录中创建lockfile。

 --storage.tsdb.no-lockfile

不在数据目录中创建lockfile

–storage.tsdb.allow-overlapping-blocks

允许重叠块,从而支持垂直压缩和垂直查询合并。

–storage.tsdb.wal-compression

压缩tsdb WAL。

–storage.remote.flush-deadline=

关闭或重新加载配置时需要等待多长时间刷新样例。

–storage.remote.read-sample-limit=5e7

在单个查询中通过远程读接口返回的最大样本总数。0意味着没有限制。对于流响应类型,此限制将被忽略。

–storage.remote.read-concurrent-limit=10

并发远程读调用的最大数量。0意味着没有限制

–storage.remote.read-max-bytes-in-frame=1048576

在编组前流化远程读取响应类型的单个帧中的最大字节数。请注意,客户端可能也有帧大小的限制。默认情况下为1MB。

–rules.alert.for-outage-tolerance=1h

忍受Prometheus故障恢复“for”警报状态的最大时间。

 --rules.alert.for-grace-period=10m

警报和恢复“for”状态之间的最小持续时间。仅对配置的“for”时间大于宽限期的警报进行维护。

–rules.alert.resend-delay=1m

在向Alertmanager重新发送警报之前等待的最短时间。

--alertmanager.notification-queue-capacity=10000

等待报警通知队列的大小

 --alertmanager.timeout=10s

发送警报到Alertmanager的超时时间

 --query.lookback-delta=5m

允许在表达式求值期间检索度量值的delta差值

--query.timeout=2m

一个查询在终止之前可以执行的最长时间(如果超过2min,就会自动kill掉)

--query.max-concurrency=20

并发执行的最大查询数,默认为20

–query.max-samples=50000000

单个查询可以加载到内存中的最大样本数。注意,如果查询尝试将比这个更多的样本加载到内存中,那么查询将会失败,因此这也限制了查询可以返回的样本数量。

--enable-feature=

逗号分隔要启用的功能名称,有效选项:agent、examplar-storage、expand-external-labels、memory--snapshot-on-shutdown、promql-at-modifier、promql-negative-offset、remote-write-reciver、extra-scrape-metrics、new-service-discovery-manager,详情请查看https://prometheus.io/docs/prometheus/latest/feature_flags/

--log.level=info

开启打印日志级别(debug,info,warn,error,fatal)。默认为info

 --log.format=logfmt

日志消息的输出格式。其中一个:[logfmt, json]

3 参数特殊用法

1)未设置参数 --web.enable-lifecycle时,执行curl -X POST http://localhost:9090/-/reload 会报错。

# curl -X POST http://localhost:9090/-/reload
Lifecycle API is not enabled.

启动设置参数--web.enable-lifecycle就可以用命令 curl -X POST http://localhost:9090/-/reload 重新加载配置文件了。

# ./prometheus --config.file  ./prometheus.yml --web.enable-lifecycle
# curl -X POST http://localhost:9090/-/reload

2)调整日志级别

启动prometheus时,把参数--log.level=info带上。

# ./prometheus --config.file  ./prometheus.yml --web.enable-lifecycle --log.level=info 2> prom.log &

查看日志文件

# tail -f prom.log
level=info ts=2023-02-14T15:22:57.725Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=43 maxSegment=46
level=info ts=2023-02-14T15:22:57.736Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=44 maxSegment=46
level=info ts=2023-02-14T15:22:57.737Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=45 maxSegment=46
level=info ts=2023-02-14T15:22:57.737Z caller=head.go:577 component=tsdb msg="WAL segment loaded" segment=46 maxSegment=46
level=info ts=2023-02-14T15:22:57.737Z caller=head.go:583 component=tsdb msg="WAL replay completed" checkpoint_replay_duration=5.246341ms wal_replay_duration=44.623041ms total_replay_duration=50.886206ms
level=info ts=2023-02-14T15:22:57.739Z caller=main.go:849 fs_type=XFS_SUPER_MAGIC
level=info ts=2023-02-14T15:22:57.739Z caller=main.go:852 msg="TSDB started"
level=info ts=2023-02-14T15:22:57.739Z caller=main.go:979 msg="Loading configuration file" filename=./prometheus.yml
level=info ts=2023-02-14T15:22:57.742Z caller=main.go:10