Skip to main content

Prometheus Textfile Tooling

Project description

promtext-cli

promtext-cli is a tool for creating prometheus text files from a simple cli command.

It is intended for use with cronjob scripts (e.g. backups).

Features:

  • supports merging new metrics into existing files
  • metrics will be updated (same labelset or no labels given), or appended to existing metrics as new timeseries
  • currently only supports gauge metrics

Usage

promtext -h
usage: main.py [-h] [--docs DOCS] [--label KEY=VALUE] [-v] filename metric value

Prometheus textfile helper

positional arguments:
  filename           Path to existing or new prometheus textfile, will be updated
  metric             metric name (new or updated)
  value              metric value

options:
  -h, --help         show this help message and exit
  --docs DOCS        metric documentation
  --label KEY=VALUE  label key=value pairs
  -v, --verbose

Examples

tmp/backup.prom before:

# HELP backup_last_start 
# TYPE backup_last_start gauge
backup_last_start{backup="example_1"} 1.721923501e+09
# HELP backup_last_end 
# TYPE backup_last_end gauge
backup_last_end{backup="example_1"} 1.721989156e+09
# HELP backup_last_exit 
# TYPE backup_last_exit gauge
backup_last_exit{backup="example_1"} 2.0

Updating existing timeseries: promtext tmp/backup.prom backup_last_start 0 --label backup=example_1:

# HELP backup_last_start 
# TYPE backup_last_start gauge
backup_last_start{backup="example_1"} 0.0
# HELP backup_last_end 
# TYPE backup_last_end gauge
backup_last_end{backup="example_1"} 1.721989156e+09
# HELP backup_last_exit 
# TYPE backup_last_exit gauge
backup_last_exit{backup="example_1"} 2.0

Adding a new label: promtext tmp/backup.prom backup_last_start 0 --label backup=example_2

# HELP backup_last_start 
# TYPE backup_last_start gauge
backup_last_start{backup="example_1"} 0.0
backup_last_start{backup="example_2"} 0.0
# HELP backup_last_end 
# TYPE backup_last_end gauge
backup_last_end{backup="example_1"} 1.721989156e+09
# HELP backup_last_exit 
# TYPE backup_last_exit gauge
backup_last_exit{backup="example_1"} 2.0

Adding a new metric: promtext tmp/backup.prom some_other_state 0 --label new_label=foo_bar

# HELP backup_last_start 
# TYPE backup_last_start gauge
backup_last_start{backup="example_1"} 0.0
backup_last_start{backup="example_2"} 0.0
# HELP backup_last_end 
# TYPE backup_last_end gauge
backup_last_end{backup="example_1"} 1.721989156e+09
# HELP backup_last_exit 
# TYPE backup_last_exit gauge
backup_last_exit{backup="example_1"} 2.0
# HELP some_other_state metric appended by promtext-cli
# TYPE some_other_state gauge
some_other_state{new_label="foo_bar"} 0.0

However, changing the label keys does not work:

promtext tmp/backup.prom some_other_state 0 --label foo_bar=foo_bar  
ERROR:promtext_cli.main:labelnames for metric some_other_state not compatible, cannot update! Old: ['new_label'], New: ['foo_bar']

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promtext_cli-0.1.2.dev76.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promtext_cli-0.1.2.dev76-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file promtext_cli-0.1.2.dev76.tar.gz.

File metadata

  • Download URL: promtext_cli-0.1.2.dev76.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for promtext_cli-0.1.2.dev76.tar.gz
Algorithm Hash digest
SHA256 47b7a450ec4b31a68c7b9966ac7d5d3bf3a64b17e1aff53c6b21a8fe40a62675
MD5 7445851270ea1dd3ad3a9ce15fbce250
BLAKE2b-256 97da27410635e7eae7535a46e7ee720ebd361bc9248b506bf2c38c9c42bfd66d

See more details on using hashes here.

File details

Details for the file promtext_cli-0.1.2.dev76-py3-none-any.whl.

File metadata

  • Download URL: promtext_cli-0.1.2.dev76-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for promtext_cli-0.1.2.dev76-py3-none-any.whl
Algorithm Hash digest
SHA256 b65999744bca54277c65197e795a1d53e750b745eb19e1455f7cf1b5055a3cd5
MD5 08f0a161471deb8c28b3cf96b9f901f4
BLAKE2b-256 f743a3c717a10ad1b585ddb679f03b6e3a962c6f4d57bdba6f72aa6110edf68f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page