# CrateDB Prometheus adapter service not starting

**URL:** <https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971>\
**Category:** Integrations\
**Created:** [January 4, 2022, 11:25pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971 "2022-01-04T23:25:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrianS](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@BrianS](https://community.cratedb.com/u/BrianS)\
**Post date:** [January 4, 2022, 11:25pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/1 "2022-01-04T23:25:54Z")

</div>

Hello,

I am trying to use the crate prometheus adapter for long term data retention with prometheus. The problem I am having is with setting up the service where the service is not able to see the config.yml file.

The error I get is the following:

```auto
cratedb-prometheus-adapter[222965]: time="2022-01-04T18:02:04-05:00" level=fatal msg="Error loading configuration file \"config.yml\": error reading configuration file: open config.yml: no such file or directory" source="server.go:393"

```

I was using the instructions a this location: → “[GitHub - crate/cratedb-prometheus-adapter: CrateDB Prometheus Adapter](https://github.com/crate/cratedb-prometheus-adapter)”

I’m hoping some has seen this in the past.

Thank you

---

<div class="post-metadata">

**Author:** ![jayeff](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/jayeff/32/271_2.png) [@jayeff](https://community.cratedb.com/u/jayeff)\
**Post date:** [January 5, 2022, 9:10am UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/2 "2022-01-05T09:10:20Z")

</div>

Hi @BrianS,

can you paste the command you use to start `cratedb-prometheus-adapter`? Do you specify the `-config.file` parameter and point it to your config.yml file?

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [January 5, 2022, 12:19pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/3 "2022-01-05T12:19:40Z")

</div>

I think the **Usage** instructions aren’t quite clear, as the `config.yml` is only included with the docker image, but not with the native images. You can create a simple `config.yml` in the same folder or use the `-config.file` option as described by @jayeff

> **[GitHub - crate/cratedb-prometheus-adapter: CrateDB Prometheus Adapter](https://github.com/crate/cratedb-prometheus-adapter#cratedb-adapter-endpoint-configuration)**
>
> CrateDB Prometheus Adapter. Contribute to crate/cratedb-prometheus-adapter development by creating an account on GitHub.

```auto
cratedb_endpoints:
- host: "localhost" # Host to connect to (default: "localhost").
  port: 5432 # Port to connect to (default: 5432).
  user: "crate" # Username to use (default: "crate")
  password: "" # Password to use (default: "").
  schema: "" # Schema to use (default: "").
  connect_timeout: 10 # TCP connect timeout (seconds) (default: 10).
  max_connections: 5 # The maximum number of concurrent connections (default: 5).
  enable_tls: false # Whether to connect using TLS (default: false).
  allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).

```

---

<div class="post-metadata">

**Author:** ![BrianS](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@BrianS](https://community.cratedb.com/u/BrianS)\
**Post date:** [January 6, 2022, 3:40am UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/4 "2022-01-06T03:40:01Z")

</div>

Thanks for the replies.

The location and the content of the file config.yml looks as follows:

```auto
cat /etc/cratedb-prometheus-adapter/config.yml 
cratedb_endpoints:
- host: "localhost" # Host to connect to (default: "localhost").
  port: 5432 # Port to connect to (default: 5432).
  user: "crate" # Username to use (default: "crate")
  password: "" # Password to use (default: "").
  schema: "" # Schema to use (default: "").
  connect_timeout: 10 # TCP connect timeout (seconds) (default: 10).
  max_connections: 5 # The maximum number of concurrent connections (default: 5).
  enable_tls: false # Whether to connect using TLS (default: false).
  allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).

```

The start command I used is the following:

```auto
systemctl start cratedb-prometheus-adapter.service

```

The service file content shows the following:

```auto
 cat /etc/systemd/system/cratedb-prometheus-adapter.service 
# -*- mode: conf -*-

[Unit]
Description=Prometheus adapter to write to CrateDB
Documentation=https://github.com/crate/cratedb-prometheus-adapter/
After=network.target

[Service]
#EnvironmentFile=-/etc/default/cratedb-prometheus-adapter
#EnvironmentFile=-/etc/cratedb-prometheus-adapter
EnvironmentFile=-/etc/cratedb-prometheus-adapter/config.yml
User=prometheus
ExecStart=/usr/bin/cratedb-prometheus-adapter $CRATEDB_PROMETHEUS_ADAPTER_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
LimitNOFILE=65536
LimitNPROC=4096

[Install]
WantedBy=multi-user.target

```

Thanks again!

---

<div class="post-metadata">

**Author:** ![jayeff](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/jayeff/32/271_2.png) [@jayeff](https://community.cratedb.com/u/jayeff)\
**Post date:** [January 10, 2022, 12:26pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/5 "2022-01-10T12:26:47Z")

</div>

Hi @BrianS,

`EnvironmentFile` will put stuff into your env but you cannot directly load the config though it. Instead use it to set a env variable which points to your config file as done in the [sample `EnvironmentFile`](https://github.com/crate/cratedb-prometheus-adapter/blob/main/systemd/cratedb-prometheus-adapter.default). Adjust paths as you need them.

See also the corresponding section in the README: [GitHub - crate/cratedb-prometheus-adapter: CrateDB Prometheus Adapter](https://github.com/crate/cratedb-prometheus-adapter#running-as-service)

---

<div class="post-metadata">

**Author:** ![BrianS](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@BrianS](https://community.cratedb.com/u/BrianS)\
**Post date:** [January 14, 2022, 6:13pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/6 "2022-01-14T18:13:40Z")

</div>

Thanks @jayeff

So I made the following change in the file: /etc/systemd/system/cratedb-prometheus-adapter.service:

```auto
Added the Line:
CRATEDB_PROMETHEUS_ADAPTER_OPTS=-config.file=/etc/cratedb-prometheus-adapter/config.yml

```

Next, this is what the actual file looks like now with the added line:

```auto
 # -*- mode: conf -*-

[Unit]
Description=Prometheus adapter to write to CrateDB
Documentation=https://github.com/crate/cratedb-prometheus-adapter/
After=network.target

[Service]
EnvironmentFile=-/etc/cratedb-prometheus-adapter/config.yml
CRATEDB_PROMETHEUS_ADAPTER_OPTS=-config.file=/etc/cratedb-prometheus-adapter/config.yml
User=prometheus
ExecStart=/usr/bin/cratedb-prometheus-adapter $CRATEDB_PROMETHEUS_ADAPTER_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
LimitNOFILE=65536
LimitNPROC=4096

```

Now the file “/etc/cratedb-prometheus-adapter/config.yml” is referenced in the “cat /etc/cratedb-prometheus-adapter/config.yml” variable.

Below is the content of that file:

```auto

cratedb_endpoints:
- host: "localhost" # Host to connect to (default: "localhost").
  port: 5432 # Port to connect to (default: 5432).
  user: "crate" # Username to use (default: "crate")
  password: "" # Password to use (default: "").
  schema: "" # Schema to use (default: "").
  connect_timeout: 10 # TCP connect timeout (seconds) (default: 10).
  max_connections: 5 # The maximum number of concurrent connections (default: 5).
  enable_tls: false # Whether to connect using TLS (default: false).
  allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).

```

Finally, I attempt to start the service and then check the status:

systemctl start cratedb-prometheus-adapter

```auto

Checking the status:
systemctl status cratedb-prometheus-adapter

● cratedb-prometheus-adapter.service - Prometheus adapter to write to CrateDB
   Loaded: loaded (/etc/systemd/system/cratedb-prometheus-adapter.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2022-01-14 12:50:10 EST; 4s ago
     Docs: https://github.com/crate/cratedb-prometheus-adapter/
  Process: 863958 ExecStart=/usr/bin/cratedb-prometheus-adapter $CRATEDB_PROMETHEUS_ADAPTER_OPTS (code=exited, status=1/FAILURE)
 Main PID: 863958 (code=exited, status=1/FAILURE)

Jan 14 12:50:10 myhostsrv1 systemd[1]: cratedb-prometheus-adapter.service: Service RestartSec=100ms expired, scheduling restart.
Jan 14 12:50:10 myhostsrv1 systemd[1]: cratedb-prometheus-adapter.service: Scheduled restart job, restart counter is at 5.
Jan 14 12:50:10 myhostsrv1 systemd[1]: Stopped Prometheus adapter to write to CrateDB.
Jan 14 12:50:10 myhostsrv1 systemd[1]: cratedb-prometheus-adapter.service: Start request repeated too quickly.
Jan 14 12:50:10 myhostsrv1 systemd[1]: cratedb-prometheus-adapter.service: Failed with result 'exit-code'.
Jan 14 12:50:10 myhostsrv1 systemd[1]: Failed to start Prometheus adapter to write to CrateDB.

```

Unfortunately it still fails to start the cratedb-protheus service.

When I check the prometheus service, it continues to run just fine as you can see from the output below of the status command:

```auto
systemctl status prometheus.service 
● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-01-14 13:04:35 EST; 30s ago
     Docs: https://prometheus.io/docs/introduction/overview/
 Main PID: 864985 (prometheus)
    Tasks: 14 (limit: 410197)
   Memory: 45.5M
   CGroup: /system.slice/prometheus.service
           └─864985 /usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus ->

Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.333Z caller=main.go:945 level=info fs_type=EXT4_SUPER_MAGIC
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.333Z caller=main.go:948 level=info msg="TSDB started"
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.333Z caller=main.go:1129 level=info msg="Loading configuratio>
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.334Z caller=dedupe.go:112 component=remote level=info remote_>
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.334Z caller=dedupe.go:112 component=remote level=info remote_>
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.334Z caller=dedupe.go:112 component=remote level=info remote_>
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.341Z caller=main.go:1166 level=info msg="Completed loading of>
Jan 14 13:04:36 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:36.341Z caller=main.go:897 level=info msg="Server is ready to re>
Jan 14 13:04:46 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:46.165Z caller=dedupe.go:112 component=remote level=info remote_>
Jan 14 13:04:46 myhostsrv1 prometheus[864985]: ts=2022-01-14T18:04:46.196Z caller=dedupe.go:112 component=remote level=warn remote_

```

Not sure what else may be missing.

Any other suggestion, we be appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![amotl](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/amotl/32/617_2.png) [@amotl](https://community.cratedb.com/u/amotl)\
**Post date:** [January 14, 2022, 7:01pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/7 "2022-01-14T19:01:14Z")

</div>

Dear Brian,

thank you for writing in and also thanks for clarifying that you are looking at the systemd-based configuration, which wasn’t clear from your original post. I will try to assist you in configuring this service appropriately.

## Introduction

> [@BrianS](#):
>
> ```auto
> [Service]
> EnvironmentFile=-/etc/cratedb-prometheus-adapter/config.yml
> CRATEDB_PROMETHEUS_ADAPTER_OPTS=-config.file=/etc/cratedb-prometheus-adapter/config.yml
> 
> ```

Both configuration settings are clearly incorrect, I will try to elaborate on it.

- Regarding `EnvironmentFile`: The YAML configuration file is specific to the `cratedb-prometheus-adapter` program and is not an environment variable file which can be loaded by systemd.
- Regarding `CRATEDB_PROMETHEUS_ADAPTER_OPTS`: Plucking environment variables into the systemd unit file like this does not work.

In order to cite @jayeff here:

> [@jayeff](#):
>
> **`EnvironmentFile` will put stuff into your env but you cannot directly load the config through it.**

I admit the instructions at [CrateDB Prometheus Adapter » Running as service](https://github.com/crate/cratedb-prometheus-adapter#running-as-service) could be outlined better, but nevertheless I believe they are correct.

## Solution

For the systemd-based setup, you need four files to be correctly deployed to your machine.

1. `/usr/bin/cratedb-prometheus-adapter`. This is the program itself, extracted from the corresponding tarball distribution package at [Index of /downloads/dist/prometheus/](https://cdn.crate.io/downloads/dist/prometheus/).
2. `/etc/cratedb-prometheus-adapter/config.yml`. Get it from [config.yml](https://github.com/crate/cratedb-prometheus-adapter/blob/main/config.yml) and adjust the settings according to your needs.
3. `/etc/systemd/system/cratedb-prometheus-adapter.service`. Get it from [cratedb-prometheus-adapter.service](https://github.com/crate/cratedb-prometheus-adapter/blob/main/systemd/cratedb-prometheus-adapter.service).
4. `/etc/default/cratedb-prometheus-adapter`. Get it from [cratedb-prometheus-adapter.default](https://github.com/crate/cratedb-prometheus-adapter/blob/main/systemd/cratedb-prometheus-adapter.default).

I don’t think you will need to make any adjustments to the latter two files. They should work out of the box.

After deploying those files correctly, invoking the following commands should start the service appropriately, given that the settings in `/etc/cratedb-prometheus-adapter/config.yml` are valid.

```shell
systemctl daemon-reload
systemctl restart cratedb-prometheus-adapter

```

Please let us know about the outcome for you.

With kind regards,  
Andreas.

P.S.: Note to self: We might look into bundling this program as Debian and RPM packages in order to make its installation easier. See also [Improve installation, configuration, and first invocation · Issue #49 · crate/cratedb-prometheus-adapter · GitHub](https://github.com/crate/cratedb-prometheus-adapter/issues/49).

---

<div class="post-metadata">

**Author:** ![BrianS](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@BrianS](https://community.cratedb.com/u/BrianS)\
**Post date:** [January 14, 2022, 8:30pm UTC](https://community.cratedb.com/t/cratedb-prometheus-adapter-service-not-starting/971/8 "2022-01-14T20:30:46Z")

</div>

Hello Andreas,

Thank you so much for the exact and detail instructions.

It is active!!!

```auto
systemctl status cratedb-prometheus-adapter.service 
● cratedb-prometheus-adapter.service - Prometheus adapter to write to CrateDB
   Loaded: loaded (/etc/systemd/system/cratedb-prometheus-adapter.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-01-14 15:25:27 EST; 8s ago
     Docs: https://github.com/crate/cratedb-prometheus-adapter/
 Main PID: 871719 (cratedb-prometh)
    Tasks: 8 (limit: 410197)
   Memory: 14.3M
   CGroup: /system.slice/cratedb-prometheus-adapter.service
           └─871719 /usr/bin/cratedb-prometheus-adapter -config.file=/etc/cratedb-prometheus-adapter/config.yml

Jan 14 15:25:27 myhostsrv1 systemd[1]: Started Prometheus adapter to write to CrateDB.
Jan 14 15:25:27 myhostsrv1 cratedb-prometheus-adapter[871719]: time="2022-01-14T15:25:27-05:00" level=info msg="Starting CrateDB Pr>
Jan 14 15:25:27 myhostsrv1 cratedb-prometheus-adapter[871719]: time="2022-01-14T15:25:27-05:00" level=info msg="Listening ..." addr>
Jan 14 15:25:27 myhostsrv1 cratedb-prometheus-adapter[871719]: time="2022-01-14T15:25:27-05:00" level=info msg="Connecting ..." end>

```
