How to Add a Custom Label to Existing Metrics in PromQL for Grafana

Hi everyone,

I’m currently working with a Prometheus data source in Grafana, where I have a metric site_pages with labels such as {id, url, type, site}. An example of a current label setup is:

site_pages{ id="1", url="https://example.com/post/101", type="post", site="example.com" }

I want to add a custom label, {title}, to my existing metric. Here’s what I’m aiming to achieve:
For each url, I would like a corresponding title label, like so:

  • url="https://example.com/post/101"title="Guide to Setting Up"
  • url="https://example.com/post/102"title="How to Get Started"
  • url="https://example.com/post/103"title="Advanced Tips"

Note that I have a couple thousands sets of title/URLs (in JSON/JSONL format) like this, so manually setting up one by one on the web interface is not ideal…

I attempted to use Prometheus recording rules to add the label, but it seems PromQL doesn’t natively support adding labels to existing metrics without modifying the original ingestion process. Also, I’m limited in options on the ingestion side to add title directly.

Is there a way within Grafana or PromQL to dynamically map each url to a specific title, or should I be looking at external preprocessing before metrics ingestion?

Any advice or workarounds would be much appreciated!

Thanks in advance!

Prometheus was not designed for update. But you can ingest “info” metric, where you will have url, title label and then join 2 metrics together:

You can also use your favorite Grafana supported datasource, where you will store mapping url->title. Then you will add second query on the panel to select these mappings and use Grafana join transformation to join 2 query results. You can use Grafana bultin test datasource and CSV content for quick testing.