sql_exporter
sql_exporter copied to clipboard
Run as a Windows service
It would be great to have ability to run sql_exporter as a Windows service. Now I register service with sc.exe, but it crush with error 7000:
The sql_exporter service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.
Apparently you can't just run a random binary as Windows service, it needs to interact with the OS and take commands from it (pause, resume, stop etc.) while publishing its state.
It doesn't appear complicated to implement, you can see a working example in wmi_exporter (just scroll all the way to the bottom). It uses what appears to be Go standard library support for Windows services and I've been running it as a service on a couple of Windows boxes without issues for over a year now.
What I'm wondering though, is if it's possible to have a binary that can run both as a regular process (e.g. started from the command line) and as a Windows service; or whether you would need 2 separate binaries.
But unfortunately I really don't have the time to figure it out, so as they say, contributions are welcome. (o:
The easiest and least invasive way to me seems to import https://github.com/kardianos/minwinsvc package, which contains platform build annotations, so it would have an effect just for windows build.
It's the way Gogs/Gitea build their apps for Windows at the moment.
Using "golang.org/x/sys/windows/svc" I was able to build a release that now runs as a windows service, but in my world, I have to add sql_exporter.yml & mssql_standard.collector.yml into the System32 folder and the service would run successfully. Thanks, John.
Hi @johndnlightnit ,
I tried to compile your code but getting errors with reference to original fork. can you help me to compile the code or send me the exe you are using
Thanks, Rajasekhar
Hi
Leave it with me and ill have a look
Cheers
John
From: rajacoast [email protected] Sent: 27 August 2020 08:11 To: free/sql_exporter [email protected] Cc: John Denny [email protected]; Mention [email protected] Subject: Re: [free/sql_exporter] Run as a Windows service (#30)
Hi @johndnlightnithttps://github.com/johndnlightnit ,
I tried to compile your code but getting errors with reference to original fork. can you help me to compile the code or send me the exe you are using
Thanks, Rajasekhar
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/free/sql_exporter/issues/30#issuecomment-681661978, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK7DKZEPAFJ6ZB5K2VFJMX3SCYBJLANCNFSM4HFFYPGA.
LEGAL DISCLAIMER: This email and any files transmitted with it are confidential and intended solely for use by the individual or entity to whom they are addressed. If you have received this transmission in error please contact the sender or your system manager. Any views or opinions presented by the sender of this message are not necessarily those of nlightn-IT Ltd. The recipient should check this email and any attachments for the presence of viruses. nlightn-IT Ltd accepts no liability for any damage caused by any virus transmitted by this email. nlightn-IT Ltd, Registered in England No: 04317633 Registered Office: Elmton Lodge Farm, Spring Lane, Elmton, Worksop, S80 4LX
Hi
I uploaed a build version.
Cheers
John
https://github.com/johndnlightnit/sql_exporter/blob/master/sql_exporter.zip
From: rajacoast [email protected] Sent: 27 August 2020 08:11 To: free/sql_exporter [email protected] Cc: John Denny [email protected]; Mention [email protected] Subject: Re: [free/sql_exporter] Run as a Windows service (#30)
Hi @johndnlightnithttps://github.com/johndnlightnit ,
I tried to compile your code but getting errors with reference to original fork. can you help me to compile the code or send me the exe you are using
Thanks, Rajasekhar
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/free/sql_exporter/issues/30#issuecomment-681661978, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK7DKZEPAFJ6ZB5K2VFJMX3SCYBJLANCNFSM4HFFYPGA.
LEGAL DISCLAIMER: This email and any files transmitted with it are confidential and intended solely for use by the individual or entity to whom they are addressed. If you have received this transmission in error please contact the sender or your system manager. Any views or opinions presented by the sender of this message are not necessarily those of nlightn-IT Ltd. The recipient should check this email and any attachments for the presence of viruses. nlightn-IT Ltd accepts no liability for any damage caused by any virus transmitted by this email. nlightn-IT Ltd, Registered in England No: 04317633 Registered Office: Elmton Lodge Farm, Spring Lane, Elmton, Worksop, S80 4LX
Thanks John,
But I have some problem with the service. MSSql_Exporter is getting created and started but the http link is working. Also I am not able to stop the service. I am testing this Windows server 2012
Thanks,
@rajacoast @johndnlightnit Hi everyone! :) I was able to register and run Sql Exporter as a Windows service with a bit less code and no invasion to /Windows/System32/ (as I described in my comment above). I'll release the update with proper instructions soon here: https://github.com/burningalchemist/sql_exporter. The change is tiny and can be backported to the original project too.
UPD: https://github.com/burningalchemist/sql_exporter/releases/tag/0.7.1 Please take a look at Windows service section in README.md.
Good work. As I have previously mentioned, I am not a developer, just cobbled it together to make it work, as there wasn't a version that worked as a service that I could see before, look forward to seeing you update ;0)
From: Sergei Zyubin [email protected] Sent: 30 August 2020 10:33 To: free/sql_exporter [email protected] Cc: John Denny [email protected]; Mention [email protected] Subject: Re: [free/sql_exporter] Run as a Windows service (#30)
@rajacoasthttps://github.com/rajacoast @johndnlightnithttps://github.com/johndnlightnit Hi everyone! :) I was able to register and run Sql Exporter as Windows service with a bit less code and invasion to /Windows/System32/ (as I described in the comment above). I'll release the update with instructions tomorrow here: https://github.com/burningalchemist/sql_exporter. The change is tiny and can be backported to the original project too.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/free/sql_exporter/issues/30#issuecomment-683398275, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK7DKZC5FOAFMR2OBRSL5VTSDIMFNANCNFSM4HFFYPGA.
LEGAL DISCLAIMER: This email and any files transmitted with it are confidential and intended solely for use by the individual or entity to whom they are addressed. If you have received this transmission in error please contact the sender or your system manager. Any views or opinions presented by the sender of this message are not necessarily those of nlightn-IT Ltd. The recipient should check this email and any attachments for the presence of viruses. nlightn-IT Ltd accepts no liability for any damage caused by any virus transmitted by this email. nlightn-IT Ltd, Registered in England No: 04317633 Registered Office: Elmton Lodge Farm, Spring Lane, Elmton, Worksop, S80 4LX
@johndnlightnit Thank you for looking into this, it's valuable! 🙂👍 The update is released.
No worries and brill will have a look as I sometimes had issues with service getting stuck on reboot.
From: Sergei Zyubin [email protected] Sent: 30 August 2020 21:05 To: free/sql_exporter [email protected] Cc: John Denny [email protected]; Mention [email protected] Subject: Re: [free/sql_exporter] Run as a Windows service (#30)
@johndnlightnithttps://github.com/johndnlightnit Thank you for looking into this, it's valuable! 🙂👍 The update is releasedhttps://github.com/burningalchemist/sql_exporter/releases/tag/0.7.1.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/free/sql_exporter/issues/30#issuecomment-683464268, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK7DKZBQPW7MBL2VKVLEICTSDKWKFANCNFSM4HFFYPGA.
LEGAL DISCLAIMER: This email and any files transmitted with it are confidential and intended solely for use by the individual or entity to whom they are addressed. If you have received this transmission in error please contact the sender or your system manager. Any views or opinions presented by the sender of this message are not necessarily those of nlightn-IT Ltd. The recipient should check this email and any attachments for the presence of viruses. nlightn-IT Ltd accepts no liability for any damage caused by any virus transmitted by this email. nlightn-IT Ltd, Registered in England No: 04317633 Registered Office: Elmton Lodge Farm, Spring Lane, Elmton, Worksop, S80 4LX
@johndnlightnit Cool, let me know! I haven't tested it extensively, but will be happy to look into edge cases 👍
Thanks @burningalchemist & @johndnlightnit. The exporter is working for me. I have to test the server reboot senario
@burningalchemist - I built your new release, ran as a service, but I am still unable to start the service unless the yaml files are in the /Windows/System32/ Folder, I'm not sure what I have missed. cheers J. It does now stop and start a treat though cheers.
Hi @johndnlightnit ! Could you provide the way you register the service? :) I think I can help with this.
All good, just needed to reference the sqlexporter config from the service startup, sorry was being a bit slow. All good now many thanks.
Yeah, great! 👍