# Prometheus.yml targets in separate file?

**URL:** <https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80>\
**Category:** Prometheus server\
**Created:** [March 23, 2021, 1:39pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80 "2021-03-23T13:39:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregGT](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/greggt/32/29_2.png) [@gregGT](https://discuss.prometheus.io/u/gregGT)\
**Post date:** [March 23, 2021, 1:39pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/1 "2021-03-23T13:39:12Z")

</div>

Hello, he have a high performance compute environment where I have thousands of node exporter nodes in multiple clusters to add to to my prometheus. Rather than list all of the target nodes directly in prometheus.yml, I would like to list them in a separate file, which is then read in by Prometheus.

Is this possible? If so, what is the syntax for including the outside file of targets in prometheus.yml?

To clarify I’m envisioning adding nodes to Prometheus something like this:

- job\_name: clusterA  
static\_configs:
  - targets:  
clusterA\_nodes\_list.txt

- job\_name: clusterB  
static\_configs:
  - targets:  
clusterB\_nodes\_list.txt

- job\_name: clusterC  
static\_configs:
  - targets:  
clusterC\_nodes\_list.txt

Thanks.

---

<div class="post-metadata">

**Author:** ![roidelapluie](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/roidelapluie/32/6_2.png) [@roidelapluie](https://discuss.prometheus.io/u/roidelapluie)\
**Post date:** [March 23, 2021, 2:34pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/2 "2021-03-23T14:34:18Z")

</div>

You can do that with file\_sd: [Use file-based service discovery to discover scrape targets | Prometheus](https://prometheus.io/docs/guides/file-sd/)

---

<div class="post-metadata">

**Author:** ![gregGT](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/greggt/32/29_2.png) [@gregGT](https://discuss.prometheus.io/u/gregGT)\
**Post date:** [March 23, 2021, 3:04pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/3 "2021-03-23T15:04:23Z")

</div>

Thanks, I’ll check that out.

---

<div class="post-metadata">

**Author:** ![gregGT](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/greggt/32/29_2.png) [@gregGT](https://discuss.prometheus.io/u/gregGT)\
**Post date:** [March 23, 2021, 7:25pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/4 "2021-03-23T19:25:32Z")

</div>

I found another service discovery that looks even better – dns\_sd\_config. As I understand it will find all node\_exporter nodes automatically.

but when I added the three items needed to configure it to my prometheus.yml , I get this error when cycling prometheus:

“Error reloading config” err=“couldn’t load configuration (–config.file=“prometheus.yml”): parsing YAML file prometheus.yml: yaml: line 8: could not find expected ‘:’”

Here’s my prometheus.yml Line 8 is the “names”

```auto
global:
  scrape_interval: 10s
  evaluation_interval: 10s

#BEGIN DNS Node Scan
dns_sd_config

 - names: pace.gatech.edu

# The type of DNS query to perform. One of SRV, A, or AAAA.
#[type: <string> | default = 'SRV']

# The port number used if the query type is not SRV.
 - port: 9100

 - refresh_interval: 1800

#END DNS Node Scan

I get the same error if I format names: like so (on two lines)

 - names:
     pace.gatech.edu

```

---

<div class="post-metadata">

**Author:** ![roidelapluie](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/roidelapluie/32/6_2.png) [@roidelapluie](https://discuss.prometheus.io/u/roidelapluie)\
**Post date:** [March 23, 2021, 7:39pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/5 "2021-03-23T19:39:14Z")

</div>

Can you try:

```auto
scrape_configs:
   - dns_sd_configs:
      - names: [pace.gatech.edu]
        port: 9100
        refresh_interval: 1800

```

---

<div class="post-metadata">

**Author:** ![SuperQ](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/superq/32/4_2.png) [@SuperQ](https://discuss.prometheus.io/u/SuperQ)\
**Post date:** [March 24, 2021, 7:50am UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/6 "2021-03-24T07:50:30Z")

</div>

> [@gregGT](#):
>
> `pace.gatech.edu`

For DNS SD, you need to have SRV records at this address.

---

<div class="post-metadata">

**Author:** ![gregGT](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/greggt/32/29_2.png) [@gregGT](https://discuss.prometheus.io/u/gregGT)\
**Post date:** [March 24, 2021, 1:15pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/7 "2021-03-24T13:15:32Z")

</div>

Thanks Julien,

results, unfortunately: parsing YAML file prometheus.yml: not a valid duration string: “1800"”

I’ve reviewed the documentation for configuration, and am puzzled by syntax. You put the names: **value** within square brackets, which follows the below example. But you did not put port: or refresh\_value: into square brackets, which is shown below. This seems inconsistent.

Further, you prepended “names:” as " - names", but that item is not prepended with " - " in the documented syntax. Rather, it is the **value** which is prepended. The other three items (type, port, refresh\_interval) are not prepended. It seems there’s a lot of inconsistency within the config doc, and also between the doc, and the syntax you have recommended. Can you help me to understand the seeming discrepancies, so that I can follow docs for the .yml files successfully?

```auto
names:
  [- <string>]

# The type of DNS query to perform. One of SRV, A, or AAAA.
[type: <string> | default = 'SRV']

# The port number used if the query type is not SRV.
[port: <int>]

# The time after which the provided names are refreshed.
[refresh_interval: <duration> | default = 30s]

```

@SuperQ , I’m going to explicitly try out SRV, A, and AAAA, see which one works.

---

<div class="post-metadata">

**Author:** ![roidelapluie](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/roidelapluie/32/6_2.png) [@roidelapluie](https://discuss.prometheus.io/u/roidelapluie)\
**Post date:** [March 24, 2021, 1:29pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/8 "2021-03-24T13:29:19Z")

</div>

Sorry, yes you need `1800s`

---

<div class="post-metadata">

**Author:** ![roidelapluie](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/roidelapluie/32/6_2.png) [@roidelapluie](https://discuss.prometheus.io/u/roidelapluie)\
**Post date:** [March 24, 2021, 1:30pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/9 "2021-03-24T13:30:44Z")

</div>

> [@gregGT](#):
>
> Further, you prepended “names:” as " - names", but that item is not prepended with " - " in the documented syntax.

brackets means that it is not mandatory, it might be a bug in the documentation.

`-` means it is a list, which is also written `[]` in yaml if you want to write it in a short form.

---

<div class="post-metadata">

**Author:** ![gregGT](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/greggt/32/29_2.png) [@gregGT](https://discuss.prometheus.io/u/gregGT)\
**Post date:** [March 24, 2021, 1:38pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/10 "2021-03-24T13:38:57Z")

</div>

OK, the correct syntax (or at least which eliminated the last error) is:

refresh\_interval: 1800s **\< "s"**

Now that that is solved, I have new error which did not manifest until I added dns\_sd\_configs to my .yml:

“Error reloading config” err=“couldn’t load configuration (–config.file=“prometheus.yml”): parsing YAML file prometheus.yml: job\_name is empty”

Of course I have job\_name further down in my .yml, but each entry has a value:

scrape\_configs:

- job\_name: prometheus  
static\_configs:
  - targets:
    - localhost:9100  
#BEGIN node\_exporter config of my Prom node

- job\_name: greg-test  
static\_configs:
  - targets:
    - localhost:9100  
#BEGIN node\_exporter config of PROD coda nodes

- job\_name: coda  
static\_configs:
  - targets:  
\< — snip —\>

#END node\_exporter config

---

<div class="post-metadata">

**Author:** ![gregGT](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/greggt/32/29_2.png) [@gregGT](https://discuss.prometheus.io/u/gregGT)\
**Post date:** [March 25, 2021, 2:11pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/11 "2021-03-25T14:11:10Z")

</div>

bump, any thoughts on the prometheus.yml: job\_name is empty error, when all of my job\_names have a value?

Thanks

---

<div class="post-metadata">

**Author:** ![roidelapluie](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/roidelapluie/32/6_2.png) [@roidelapluie](https://discuss.prometheus.io/u/roidelapluie)\
**Post date:** [March 25, 2021, 2:25pm UTC](https://discuss.prometheus.io/t/prometheus-yml-targets-in-separate-file/80/12 "2021-03-25T14:25:29Z")

</div>

It seems malformed yaml, hard to say without the complete file. Can you check the indentation?
