Drop Target

35 views
Skip to first unread message

akshay sharma

unread,
Jan 23, 2024, 3:01:20 AM1/23/24
to Prometheus Users
Hi, 

I have a file_sd_config defined in Prometheus configuration file (/tmp/test.json)
in that, I have 3-4 scrape targets as defined below:

cat /tmp/test.json
{
        "targets": [
            "x:123"
        ],
        "labels": {
            "job": "1",
            "element_name": "x",
            "__metrics_path__": "/x/test"
        }
        "targets": [
            "y:123"
        ],
        "labels": {
            "job": "2",
            "element_name": "y",
            "__metrics_path__": "/y/test"
        }
        "targets": [
            "3:123"
        ],
        "labels": {
            "job": "3",
            "element_name": "z",
            "__metrics_path__": "/z/test"
        }
    }
Now, I want prometheus to read only from job 2,3 and drop 1, do we have a provision to do that in file_sd_config?
How can I achieve this? please let me know.

thanks,


Brian Candler

unread,
Jan 24, 2024, 8:56:59 AM1/24/24
to Prometheus Users
> Now, I want prometheus to read only from job 2,3 and drop 1, do we have a provision to do that in file_sd_config?

Yes. Use target relabelling using "drop" or "keep" rules. You will have to match on some label(s) which distinguish job 1 from jobs 2 and 3.

Note 1: the text you provided is not valid JSON. Even if it were, it is not structured correctly for consumption by Prometheus. The top level entity must be a list of objects [...], and each object needs to have {"targets":[...], "labels":{...}}

Note 2: it's a really bad idea to override the "job" label. This is set by prometheus, and should identify the scrape job which collected the data.

Reply all
Reply to author
Forward
0 new messages