Prometheus as Windows Service

9,690 views
Skip to first unread message

Lukas Bahr

unread,
Feb 23, 2018, 9:35:48 AM2/23/18
to Prometheus Users

Hello everyone,

i've downloaded prometheus for windows and can successfully start it whilst i'm logged in via RDS.
To run it in background, i've tried to wrap a service around but starting it as a MS Windows Service failed.

sc.exe create prometheus_server binPath="PATH_TO_EXE\prometheus.exe --config.file=PATH_TO_CONFIG\prometheus.yml"

After starting the service, prometheus runs for a short time, until (i guess) the service manager runs into a timeout because of a missing response of a successful start.

My current environment

  • Windows Sever 2012
  • prometheus-2.2.0-rc.1.windows-amd64
  • sample/default config file

Do you have any solution for that? Thanks and kind Regards
Lukas

jean.j...@gmail.com

unread,
May 28, 2018, 5:58:46 AM5/28/18
to Prometheus Users
Hi Lukas,

Did you ever figure out a solution to running Prometheus as Windows service?

Regards,
Jean

Alin Sînpălean

unread,
May 30, 2018, 5:51:25 AM5/30/18
to Prometheus Users
Never tried running Prometheus on Windows, but I am running a WMI exporter for Prometheus. If you're willing to go into the Prometheus source code and make some changes, it doesn't look all that daunting.

IIRC the setup was straightforward and the script for packaging it as an MSI is also there.  If you look at the source code, it the necessary additions are small and well-contained: just search for "svc" in https://github.com/martinlindhe/wmi_exporter/blob/master/exporter.go

Cheers,
Alin.

Eduard-Cristian Stefan

unread,
Jun 1, 2018, 7:02:19 AM6/1/18
to Prometheus Users
I'm using NSSM to run Prometheus, WMI Exporter, and Grafana under Windows Server 2008 R2 x64.

With recent NSSM betas you can dump an existing service as the commands needed to install it again:

nssm.exe install _prometheus C:\tools\prometheus\prometheus.exe
nssm.exe set _prometheus AppParameters "--config.file C:\tools\prometheus\prometheus.yml"
nssm.exe set _prometheus AppDirectory C:\tools\prometheus
nssm.exe set _prometheus AppExit Default Restart
nssm.exe set _prometheus AppRestartDelay 5000
nssm.exe set _prometheus AppStdout C:\tools\prometheus\logs\std_out.log
nssm.exe set _prometheus AppStdoutCreationDisposition 2
nssm.exe set _prometheus AppStderr C:\tools\prometheus\logs\std_err.log
nssm.exe set _prometheus AppStderrCreationDisposition 2
nssm.exe set _prometheus AppStopMethodSkip 6
nssm.exe set _prometheus AppStopMethodConsole 5000
nssm.exe set _prometheus AppThrottle 5000
nssm.exe set _prometheus AppRotateFiles 1
nssm.exe set _prometheus AppRotateOnline 1
nssm.exe set _prometheus AppRotateSeconds 86400
nssm.exe set _prometheus AppRotateBytes 10485760
nssm.exe set _prometheus DisplayName _prometheus
nssm.exe set _prometheus ObjectName LocalSystem
nssm.exe set _prometheus Start SERVICE_AUTO_START
nssm.exe set _prometheus Type SERVICE_WIN32_OWN_PROCESS

Have a nice day,
  Eduard

thebitt...@gmail.com

unread,
Sep 24, 2018, 8:20:55 AM9/24/18
to Prometheus Users
I have the same problem, tried about 5 different configurations without any luck. Windows 7. I'd like to do without NSSM if possible

пятница, 23 февраля 2018 г., 17:35:48 UTC+3 пользователь Lukas Bahr написал:

Eduard-Cristian Stefan

unread,
Sep 25, 2018, 12:41:46 AM9/25/18
to Prometheus Users
On Monday, September 24, 2018 at 3:20:55 PM UTC+3, thebitt...@gmail.com wrote:
I have the same problem, tried about 5 different configurations without any luck. Windows 7. I'd like to do without NSSM if possible
 
Well, you could try cygrunsrv: http://cygwin.wikia.com/wiki/Cygrunsrv

Good luck,
  Eduard

thebitt...@gmail.com

unread,
May 15, 2019, 6:04:22 AM5/15/19
to Prometheus Users
I just repeated most of your setup and the service runs fine (fetches data from various places), but the log files are empty, both of them.

 nssm install prometheus D:\prometheus\bin\prometheus.exe "--config.file=D:\prometheus\config\prometheus.yml --storage.tsdb.path=D:\prometheus\data --storage.tsdb.retention.time=16w --log.level=info"
 nssm
set prometheus AppStdout D:\prometheus\logs\std_out.log
 nssm
set prometheus AppStdoutCreationDisposition 2
 nssm
set prometheus AppStderr D:\prometheus\logs\std_err.log
 nssm
set prometheus AppStderrCreationDisposition 2

Is there something I'm missing?

пятница, 1 июня 2018 г., 14:02:19 UTC+3 пользователь Eduard-Cristian Stefan написал:

thebitt...@gmail.com

unread,
May 15, 2019, 6:29:27 AM5/15/19
to Prometheus Users
Also added rotation parameters, but log files are still empty. When I run prometheus as a console app, it writes logs just fine

среда, 15 мая 2019 г., 13:04:22 UTC+3 пользователь thebitt...@gmail.com написал:

thebitt...@gmail.com

unread,
May 16, 2019, 4:35:16 AM5/16/19
to Prometheus Users
Problem is - I checked web ui and parameters were passed correctly, but logs are still empty

среда, 15 мая 2019 г., 13:29:27 UTC+3 пользователь thebitt...@gmail.com написал:

frank....@interface-projects.de

unread,
May 16, 2019, 4:42:22 AM5/16/19
to Prometheus Users
maybe the user (most of the time this is LOCALSYSTEM) under which the service runs, has no permissions to write to the desired files. Did you check your windows eventlog?

thebitt...@gmail.com

unread,
May 16, 2019, 6:56:07 AM5/16/19
to Prometheus Users
I doubt that's the case, since the files are created but are empty. I looked at event viewer - nssm says it started the server and there are no errors

четверг, 16 мая 2019 г., 11:42:22 UTC+3 пользователь frank....@interface-projects.de написал:

thebitt...@gmail.com

unread,
May 16, 2019, 9:13:55 AM5/16/19
to Prometheus Users
Did the output redirect work for you? I'm starting to think that problem is not due to NSSM - it may be how Go logging library work inside Windows.

четверг, 16 мая 2019 г., 11:42:22 UTC+3 пользователь frank....@interface-projects.de написал:

Frank Taffelt

unread,
May 16, 2019, 9:34:56 AM5/16/19
to Prometheus Users

Yes for me it’s working. I use nssm 2.24. One difference is, I’m logging  both fd to same file:

 

%NSSM% set %SERVICENAME% AppStdout %PROMHOME%\logs\service.log

%NSSM% set %SERVICENAME% AppStderr %PROMHOME%\logs\service.log

--
You received this message because you are subscribed to a topic in the Google Groups "Prometheus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prometheus-users/NjtTA7vsVJ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/ff2f33de-9e22-4b89-85a3-ec9efb263772%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

thebitt...@gmail.com

unread,
May 21, 2019, 5:10:23 AM5/21/19
to Prometheus Users
Well, I run it for several days, and the logs appeared - all of them are in one file, although I configured separate ones. 
Not a big deal though.
Thanks Frank

четверг, 16 мая 2019 г., 16:34:56 UTC+3 пользователь Frank Taffelt написал:

To unsubscribe from this group and all its topics, send an email to prometh...@googlegroups.com.
To post to this group, send email to prometh...@googlegroups.com.

thebitt...@gmail.com

unread,
May 21, 2019, 5:33:48 AM5/21/19
to Prometheus Users
What I don't understand is that log file is overwritten when I restart the service. I don't want that, documentation says the default is to append to existing files. DId I do something wrong? Here's my config:

nssm install prom_exporter_general D:\soft\wmi_exporter.exe

nssm
set prom_exporter_general AppParameters  "--collectors.enabled """cpu,cs,os,logical_disk,net,system""" --telemetry.addr=""":5015"
nssm set prom_exporter_general AppStdout D:\path\to\prometheus\logs\exporter_std_out.log
nssm set prom_exporter_general AppStdoutCreationDisposition 2
nssm set prom_exporter_general AppStderr D:\path\to\prometheus\logs\exporter_std_error.log
nssm set prom_exporter_general AppStderrCreationDisposition 2


nssm set prom_exporter_general AppRotateFiles 1
nssm set prom_exporter_general AppRotateOnline 1
nssm set prom_exporter_general AppRotateSeconds 86400
nssm set prom_exporter_general AppRotateBytes 10485760


nssm start prom_exporter_general



вторник, 21 мая 2019 г., 12:10:23 UTC+3 пользователь thebitt...@gmail.com написал:

Frank Taffelt

unread,
May 21, 2019, 5:56:17 AM5/21/19
to Prometheus Users

I think you should set the param for AppStdoutCreationDisposition and AppStderrCreationDisposition to 4, which maps  to OPEN_ALWAYS.

To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/91f2999b-5c8a-410e-a82c-5a9b573becff%40googlegroups.com.

Frank Taffelt

unread,
May 21, 2019, 6:00:43 AM5/21/19
to Prometheus Users

Or maybe better use the gui with nssm edit.

 

Gesendet: Dienstag, 21. Mai 2019 11:34

To unsubscribe from this group and all its topics, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/91f2999b-5c8a-410e-a82c-5a9b573becff%40googlegroups.com.

thebitt...@gmail.com

unread,
May 21, 2019, 6:48:26 AM5/21/19
to Prometheus Users
Thanks! I tried to understand what that parameter means.
Everything is fine now

вторник, 21 мая 2019 г., 12:56:17 UTC+3 пользователь Frank Taffelt написал:

Eivind Gussiås Løkseth

unread,
Jul 6, 2020, 8:49:21 AM7/6/20
to Prometheus Users
I found this thread after first finding the GitHub issue where the question was asked initially. I would like to add a comment to that issue to link directly to this tread, but unfortunately the issue is locked and only participants can add more comments to it. So maybe you could, @thebitt? This is the link to add to issue #3881: https://groups.google.com/d/msg/prometheus-users/NjtTA7vsVJ8/Nq7tOHtDAAAJ

gopal...@gmail.com

unread,
Jun 23, 2021, 7:53:19 AM6/23/21
to Prometheus Users
Hi,
Is the issue resolved, can some one help me on this. 

I am trying to run as service in windows VM but it was failed.

ManuelH

unread,
Feb 1, 2023, 3:26:40 AM2/1/23
to Prometheus Users
Hello,

Is it possible to start Prometheus as a service in Windows without using third-party apps? Any clue why this is not working? 

Regards

Reply all
Reply to author
Forward
0 new messages