windows_exporter icon indicating copy to clipboard operation
windows_exporter copied to clipboard

Unable to start windows_exporter with a configuration file in the default location

Open qmonitoring opened this issue 4 years ago • 20 comments

Unable to start windows_exporter with a configuration file in the default location

Steps to reproduce:

OS: Win 10 Pro 10.0.19041 User with a Administrator privileges

First scenario: Default config

1)Create folder C:\Program Files\windows_exporter with the following files:

windows_exporter-0.15.0-amd64.msi config.yml

config.yml file content:

collectors:
  enabled: service
collector:
  service:
    services-where: "Name='<any_existing_service>'"
log:
  level: warn

2)Execute the following command in PowerShell (under Administrator)

msiexec /i C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi

Expected result:

The windows_exporter is up and running with parameters from the C:\Program Files\windows_exporter\config.yml file

Actual result: The windows installer popup like this image

Second scenario: Explicitly add a path to the config file in the C:\Program Files\windows_exporter directory

1)Create folder C:\Program Files\windows_exporter with the following files:

windows_exporter-0.15.0-amd64.msi config.yml

config.yml file content:

collectors:
  enabled: service
collector:
  service:
    services-where: "Name='<any_existing_service>'"
log:
  level: warn

2)Execute the following command in PowerShell (under Administrator)

msiexec /i C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi --% EXTRA_FLAGS="--config.file=C:\Program Files\windows_exporter\config.yml"

Expected result:

The windows_exporter is up and running with parameters from the C:\Program Files\windows_exporter\config.yml file

Actual result: The windows installer popup like this image

Third scenario: Explicitly add a path to the config file in the C:\Program Files\windows_exporter directory and locate windows_exporter-0.15.0-amd64.msi installation file in C:\windows_exporter folder

1)Create folder C:\windows_exporter with the following file:

windows_exporter-0.15.0-amd64.msi

Create folder C:\Program Files\windows_exporter with the following file:

config.yml

config.yml file content:

collectors:
  enabled: service
collector:
  service:
    services-where: "Name='<any_existing_service>'"
log:
  level: warn

2)Execute the following command in PowerShell (under Administrator)

msiexec /i C:\windows_exporter\windows_exporter-0.15.0-amd64.msi --% EXTRA_FLAGS="--config.file=C:\Program Files\windows_exporter\config.yml"

Expected result:

The windows_exporter is up and running with parameters from the C:\Program Files\windows_exporter\config.yml file

Actual result: Error popup: image

Fourth scenario: Explicitly add a path to the config file in the C:\windows_exporter directory

1)Create folder C:\windows_exporter with the following files:

windows_exporter-0.15.0-amd64.msi config.yml file content:

collectors:
  enabled: service
collector:
  service:
    services-where: "Name='<any_existing_service>'"
log:
  level: warn

3)Execute the following command in PowerShell (under Administrator)

msiexec /i C:\windows_exporter\windows_exporter-0.15.0-amd64.msi --% EXTRA_FLAGS="--config.file=C:\windows_exporter\config.yml"

Expected result:

windows_exporter is up and running with parameters from the C:\windows_exporter\config.yml file

Actual result: The windows_exporter is up and running

Question: How to start windows_exporter with a configuration file in the default location?

qmonitoring avatar Nov 12 '20 10:11 qmonitoring

Hi @qmonitoring, It looks to me like the first two cases are caused by not properly quoting the path to the msi file, causing msiexec to pop the help dialog since it couldn't figure out what to do. In the third case, it looks like a similar problem, you haven't quoted the path to the config file. The fourth case works because you do not have any spaces that need to be escaped.

carlpett avatar Nov 12 '20 10:11 carlpett

@carlpett Thank you very much for such a quick response! Indeed, if the path is correct, windows_exporter is up and running, but no default configuration has been applied:

Scenario: 1)Create folder C:\Program Files\windows_exporter with the following files:

windows_exporter-0.15.0-amd64.msi config.yml

Execute the following command in PowerShell (under Administrator) msiexec /i "C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi"

Actual result: Scraping of all default metrics, not just those specified in the config file

qmonitoring avatar Nov 12 '20 11:11 qmonitoring

Yes, you need to specify that you want to use the file. Currently, we do not read the file unasked, as a way to simplify the feature and get it finished. We might add it later, but for now you have to use the --config.file flag.

carlpett avatar Nov 12 '20 11:11 carlpett

The "Second scenario" with correct path quotation also doesn't work:

1)Create folder C:\Program Files\windows_exporter with the following files:

windows_exporter-0.15.0-amd64.msi config.yml

2)Execute the following command in PowerShell (under Administrator) msiexec /i "C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi" --% EXTRA_FLAGS="--config.file=C:\Program Files\windows_exporter\config.yml"

Actual result: Error popup image

qmonitoring avatar Nov 12 '20 11:11 qmonitoring

Yes, you need to specify that you want to use the file. Currently, we do not read the file unasked, as a way to simplify the feature and get it finished. We might add it later, but for now you have to use the --config.file flag.

Could you please clarify how to use this flag with an example of a full command?

qmonitoring avatar Nov 12 '20 11:11 qmonitoring

You should be seeing logs in the event viewer that says why it is going wrong when it is getting this far. In this case, I'd guess they'll indicate you also need to quote the config.file path.

carlpett avatar Nov 12 '20 12:11 carlpett

Could you please clarify how to use this flag with an example of a full command? There's a bit of nested quoting required, I think this would be it (I don't have a test environment available right now): msiexec /i "C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi" --% EXTRA_FLAGS="--config.file=""C:\Program Files\windows_exporter\\config.yml""

But since it's in the working directory of the executable, msiexec /i "C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi" --% EXTRA_FLAGS="--config.file=.\config.yml" should work, I believe.

carlpett avatar Nov 12 '20 12:11 carlpett

@carlpett thank you for your reply! With your help I have found the solution.

Eventually I have found that the appropriate command is

msiexec /i "C:\Program Files\windows_exporter\windows_exporter-0.15.0-amd64.msi" --% EXTRA_FLAGS="--config.file=""C:\Program Files\windows_exporter\config.yml"""

Unfortunately, none of the combinations of the relative path quoting led to the desired result.

qmonitoring avatar Nov 12 '20 13:11 qmonitoring

Hi,

I have the same need to use a config file and the same issue with the msi installer: msiexec /i C:\Users\Administrator\Downloads\windows_exporter-0.15.0-amd64.msi /log msiexec.log EXTRA_FLAGS="--config.file=config.yml" This ends up in the message mentioned above "Can't start the service"... The logfile: msiexec.log

The lines with the error: Error 1920. Service 'windows_exporter' (windows_exporter) failed to start. Verify that you have sufficient privileges to start system services. MSI (s) (C0:2C) [19:30:32:327]: Product: windows_exporter -- Error 1920. Service 'windows_exporter' (windows_exporter) failed to start. Verify that you have sufficient privileges to start system services. btw. Property(C): EXTRA_FLAGS = --config.file=config.yml looks good, right?

Asking Dr. Google for 1920 is not really helpful but one hint I found: Ask the application event log and there I found the following: could not load config file: CreateFile config.yml: Das System kann die angegebene Datei nicht finden.

uhhh. ok, now I copied the config.yml to C:\Temp etc... but no, it's C:\Windows\System32 where the config.yml (in my case) must exists. (Path where the "system services" starts.)

I think it's a kind of race condition that the config.yml must exist while the installer is running and if not the installer can't proceed.

Hope that helps, Kai

Ka-Hen avatar Nov 17 '20 18:11 Ka-Hen

@Ka-Hen I ran into the same issue. If you use "unix style" in the parameter for config file, it works. ImagePath example from registry : "C:\Program Files\windows_exporter\windows_exporter.exe" --log.format logger:eventlog?name=windows_exporter --config.file=c:/winexporter/winexp.yml Maybe, you have to escape the backslashes otherwise. Windows :=) Anyway, why does config.file require "=" instead of ":" ?

frank2b avatar Nov 21 '20 09:11 frank2b

@Ka-Hen

it's C:\Windows\System32 where the config.yml (in my case) must exists.

Interesting, I'd expected the working directory to the be installation dir. We'll need to see if that can be adjusted.

I think it's a kind of race condition that the config.yml must exist while the installer is running and if not the installer can't proceed.

This is a good point, which I think we didn't take into account. The expectation was perhaps that users who need the configuration file approach would be doing custom installations using some 3rd party tool rather than using the msi file. What would you consider a reasonable approach? I do not believe that we should start the exporter if the specified configuration file is not in place, and I do think we want to start the service automatically. Which seems hard to resolve, unless we say that the user must have pre-created the installation directory and placed the configuration file there? @breed808 what do you think?

@frank2b All flags use = to separate flag name and value. Perhaps you are comparing with the log.format flag, where the : is actually part of the value? --log.format logger:eventlog?name=windows_exporter is equivalent to --log.format=logger:eventlog?name=windows_exporter

carlpett avatar Nov 21 '20 10:11 carlpett

@carlpett Hej Calle, my bad :=), sorry. If I my list my wish list, I would like the following (I use Ansible to install the service) :

  • when parameter --config.file is given, the config file must exist (like it is implemented right now)
  • config file should be given by either absolute path (my favourite in Windows but ...) or relative to the "windows_exporter home dir", i.ex "config.yml" or "config\win_exp.yml" where config is subdir in home dir
  • backslash should be supported without need for escaping
  • plus https support but that is another thing :=)

frank2b avatar Nov 21 '20 12:11 frank2b

@carlpett I'm inclined to agree. The configuration file seems best suited where dynamic configuration of the exporter is desired. Custom tools (Ansible, Puppet, scripts, etc) are best placed to handle this situation, as the configuration file will need to be set before running the exporter, and changes to the configuration will need to trigger a restart of the exporter. Static installations where configuration changes are not made could be done via the MSI, with SCCM or another method of MSI installation.

Treating a missing configuration file as a soft-fail would violate the principal of least surprise. Users expecting particular metrics from an exporter that is running successfully might be confused as to why their configuration has not applied.

breed808 avatar Nov 22 '20 03:11 breed808

it's C:\Windows\System32 where the config.yml (in my case) must exists. Interesting, I'd expected the working directory to the be installation dir. We'll need to see if that can be adjusted.

I would expect the directory where the executable is located or the LOCAL_APPDATA directory (Environment.SpecialFolder.LocalApplicationData) . AFAIK for services it's something like C:\WINDOWS\system32\config\systemprofile\AppData\Local + AppName. The path differs from OS.

I think it's a kind of race condition that the config.yml must exist while the installer is running and if not the installer can't proceed. This is a good point, which I think we didn't take into account. The expectation was perhaps that users who need the configuration file approach would be doing custom installations using some 3rd party tool rather than using the msi file. What would you consider a reasonable approach? I do not believe that we should start the exporter if the specified configuration file is not in place, and I do think we want to start the service automatically. Which seems hard to resolve, unless we say that the user must have pre-created the installation directory and placed the configuration file there? @breed808 what do you think?

My personal recommendation is to remove the "--config-file" from EXTRA_FLAGS and use a common default path. If the config file exits, is readable, etc. it is used by the services. If not use the default / command line arguments. A message in the event look is helpful to be transparent. From which path the config file is used or not because it was not found.

Ka-Hen avatar Nov 22 '20 17:11 Ka-Hen

Maybe I'm too late but this command is working for me (Win10) msiexec /i "c:\Scripts\windows_exporter\windows_exporter.msi" --% EXTRA_FLAGS="--config.file=c:\Scripts\windows_exporter\config.yml"

a-mazed avatar Jan 26 '21 14:01 a-mazed

I thought I had it, but I was wrong. Command I'm using, seemingly like the others listed:

msiexec /i "C:\windows_exporter\windows_exporter-0.15.0-amd64.msi" TEXTFILE_DIR="C:\windows_exporter\custom_metrics" --% EXTRA_FLAGS="--config.file=C:\windows_exporter\config.yml"

I opted to forgo the config file, which is frustrating.

msiexec /i "C:\windows_exporter\windows_exporter-0.15.0-amd64.msi" ENABLED_COLLECTORS=cpu,cs,logical_disk,net,os,service,system,textfile,thermalzone,process,memory LISTEN_PORT=9182

jehanalvani avatar Feb 03 '21 00:02 jehanalvani

Hi @jehanalvani, I will test the install with config file and it's doesn't work when i set the config file on the native repository (C:\Program Files\windows_exporter\config.yml) the installer say me that : ExecFirewallExceptions: Installing firewall exception2 windows_exporter (HTTP 9182) (C:\Program Files\windows_exporter\windows_exporter.exe) Error 1920. Service 'windows_exporter' (windows_exporter) failed to start. Verify that you have sufficient privileges to start system services. MSI (s) (B8:04) [17:35:04:995]: Product: windows_exporter -- Error 1920. Service 'windows_exporter' (windows_exporter) failed to start. Verify that you have sufficient privileges to start system services.

You need to setup this on another file i push this on my salt repository (C:\salt) and it's work like this : msiexec /i windows_exporter-0.15.0-amd64.msi EXTRA_FLAGS="--config.file=C:\salt\config.yml /qn

My config file if you want in attachement. config.yml.txt

PierreNa avatar Feb 04 '21 07:02 PierreNa

This works for me when run from cmd.exe:

msiexec.exe /i "C:\Users\me\AppData\Local\Temp\windows_exporter-0.16.0-amd64.msi" TEXTFILE_DIR="""C:\Program Files\windows_exporter\textfile_inputs""" EXTRA_FLAGS="--config.file=""C:\Program Files\windows_exporter\config.yml"""

lubyou avatar Feb 26 '21 18:02 lubyou

needed to do extra single quotes to get it to work:

msiexec.exe /i '"C:\windows\temp\windows_exporter.msi" EXTRA_FLAGS="--config.file=""C:\Program Files\windows_exporter\config.yml"""'

I think this can be closed.

martohub avatar Feb 04 '22 16:02 martohub

why do we need to run an MSI with a bunch of custom args? Why doesnt the installer deliver a config.yml to the installed directory and set the service to use that file?

-or- have windows_exporter.exe look in its own directory for a conventionally named config.yml file?

amccool avatar Feb 09 '22 15:02 amccool

Many of the attempts above include --%. That's not valid syntax for msiexec, so will throws an msiinstall error. It looks like someone then also used to this to create the Chocolatey package which also doesn't install for the same reason. Readme.md should read

msiexec /i ENABLED_COLLECTORS=os,service EXTRA_FLAGS="--collector.service.services-where ""Name LIKE 'sql%'"""

not

msiexec /i ENABLED_COLLECTORS=os,service --% EXTRA_FLAGS="--collector.service.services-where ""Name LIKE 'sql%'"""

winstonpickle avatar Dec 09 '22 17:12 winstonpickle

I have managed to add the configuration file as follows:

msiexec.exe /i C:\monit\windows_exporter.msi EXTRA_FLAGS="--config.file=""C:\monit\config.yml"""

fhera avatar Dec 13 '22 08:12 fhera

why do we need to run an MSI with a bunch of custom args? Why doesnt the installer deliver a config.yml to the installed directory and set the service to use that file?

The configuration file isn't intended to be used with the MSI, but rather with the EXE and some form of configuration management.

The MSI is intended for deployments lacking configuration management, such as SCCM, which allow setting installation options but not management of files outside the MSI.

have windows_exporter.exe look in its own directory for a conventionally named config.yml file?

This could be done. If --config-file is not specified but a file exists in a default location, such as C:\windows_exporter\config.yml we could read it.

breed808 avatar Dec 16 '22 12:12 breed808

This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

github-actions[bot] avatar Nov 25 '23 05:11 github-actions[bot]