Skip to main content

Using Command-Line Flags

1. Setting Configuration File

Flag Description Default Value Example
--config.file Path to the configuration file prometheus.yml --config.file=/etc/prometheus/prometheus.yml
--config.file.sd Configuration file service discovery false --config.file.sd=true

Example: Setting Configuration File

prometheus --config.file=/etc/prometheus/prometheus.yml

2. Configuring Storage Path

Flag Description Default Value Notes
--storage.tsdb.path Directory to store the TSDB (Time Series Database) data data/ Must be writable by the Prometheus process
--storage.tsdb.retention.time How long to retain samples in the database 15d Can be specified in days (d), hours (h), minutes (m), or seconds (s)
--storage.tsdb.retention.size Maximum size of the data directory (in bytes or with unit suffixes like GB, TB) 0 Zero means unlimited. When set, Prometheus will delete oldest data to stay under the limit

Example: Setting Storage Path and Retention

prometheus --storage.tsdb.path=/var/lib/prometheus/data \
           --storage.tsdb.retention.time=30d
Note: The data/ directory is used by default if no path is specified. Ensure sufficient disk space and proper permissions for the storage directory.

3. Setting Retention Time

Flag Description Default Value Notes
--storage.tsdb.retention.time How long to retain samples in storage 15d Can be specified in days (d), hours (h), minutes (m), or seconds (s)
--storage.tsdb.retention.size Maximum number of bytes to store in storage 0 Disabled by default. When set, overrides time-based retention

Example: Setting 30-day retention

prometheus --storage.tsdb.retention.time=30d

Example: Setting 50GB size limit

prometheus --storage.tsdb.retention.size=50GB
Note: If both --storage.tsdb.retention.time and --storage.tsdb.retention.size are set, Prometheus will use the more restrictive of the two limits.

4. Configuring Retention Size

Flag Description Default Value Notes
--storage.tsdb.retention.size Maximum number of bytes to retain in storage Unlimited Can be specified with units (e.g., 1GB, 2TB)
--storage.tsdb.retention.time Maximum time to retain samples in storage 15d Overrides retention size if both are set

Example: Setting retention size to 50GB

prometheus --storage.tsdb.retention.size=50GB
Note: Setting --storage.tsdb.retention.size will limit the size of the storage directory, and Prometheus will remove old data to stay within this limit.

5. Setting Web Listen Address

Flag Description Default Value Example
--web.listen-address Address to listen on for web interface and telemetry :9090 --web.listen-address=:8080

Example: Change Web Listen Address

prometheus --web.listen-address=:8080
Note: The address must be in the format <host>:<port>. If host is omitted, it defaults to all interfaces.

6. Configuring External URL

Flag Description Default Value Example
--web.external-url Sets the URL under which Prometheus is externally reachable Empty string (not set) --web.external-url=https://prometheus.example.com

Example: Setting External URL

prometheus --web.external-url=https://prometheus.example.com
Note: The --web.external-url flag is used to set the URL under which Prometheus is externally reachable, useful for reverse proxies or when Prometheus is behind a load balancer.

7. Enabling Feature Flags

Flag Description Default Status
--enable-feature Enables experimental features None EXPERIMENTAL
--enable-feature=exemplar-storage Enables exemplar storage support false NEW
--enable-feature=remote-write-receiver Enables remote write receiver capability false NEW

Example: Enabling Feature Flags

prometheus --enable-feature=exemplar-storage --enable-feature=remote-write-receiver
Note: Feature flags are intended for experimental use and may change or be removed in future versions.

8. Setting Query Timeout

Flag Description Default Value Notes
--query.timeout Maximum time a query is allowed to run 2m Timeout for query execution

Example: Setting Query Timeout

prometheus --query.timeout=5m
Note: Setting a query timeout prevents long-running queries from consuming excessive resources and affecting system performance.

9. Configuring Max Samples

Flag Description Default Value Notes
--storage.tsdb.max-samples-per-chunk Maximum number of samples per chunk 120 Controls the size of chunks in the time series database
--storage.tsdb.max-chunks-per-raw-samples Maximum number of chunks per raw sample 1000 Used to limit the number of chunks generated per sample
--storage.tsdb.max-chunk-size Maximum size of a chunk in bytes 1048576 Defines the maximum size of a chunk in the database

Example: Setting Max Samples Per Chunk

prometheus --storage.tsdb.max-samples-per-chunk=240

10. Setting Log Level

Flag Description Default Values
--log.level Set the log level for the Prometheus server info debug, info, warn, error

Example: Setting Log Level to Debug

prometheus --log.level=debug

11. Configuring WAL Compression

Flag Description Default Value Notes
--storage.tsdb.wal-compression Enables or disables WAL compression false Set to true to enable compression using Snappy
--storage.tsdb.wal-compression-level Compression level for WAL (1-9) 4 Higher levels = better compression but more CPU usage

Example: Enabling WAL Compression

prometheus --storage.tsdb.wal-compression=true --storage.tsdb.wal-compression-level=6
Note: WAL compression can reduce disk I/O and storage usage, but may increase CPU overhead during writes.

12. Setting Max Block Duration

Flag Description Default Value Notes
--storage.tsdb.max-block-duration Maximum duration a block can last before being closed and persisted to disk. 2h Used to control the size and retention of time series blocks in the TSDB.

Example: Setting Max Block Duration

prometheus --storage.tsdb.max-block-duration=3h
Note: Setting this value too low may result in excessive block creation, leading to increased I/O and storage overhead. Setting it too high can lead to larger blocks that are harder to manage or query efficiently.

Was this article helpful?