Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegraf as Windows Service #860

Closed
fzavalloni opened this issue Mar 16, 2016 · 32 comments
Closed

Telegraf as Windows Service #860

fzavalloni opened this issue Mar 16, 2016 · 32 comments

Comments

@fzavalloni
Copy link

Hi,

Is it possible to use the Telegraf for windows as Windows Service?

I tried to add it as service but did not work.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe "C:\Program File
s\Telegraf\telegraf.exe"
Microsoft (R) .NET Framework Installation utility Version 4.0.30319.33440
Copyright (C) Microsoft Corporation. All rights reserved.

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Prog
ram Files\Telegraf\telegraf.exe' or one of its dependencies. The module was expe
cted to contain an assembly manifest..

Tks Fabrizio

@sparrc sparrc mentioned this issue Mar 16, 2016
@sparrc
Copy link
Contributor

sparrc commented Mar 16, 2016

agreed, I believe @cwegener has been doing some work on this and might have a PR available soon

@fzavalloni
Copy link
Author

Great! I will wait for that.

Tks

@ricardclau
Copy link
Contributor

Hi

We are running telegraf in Windows boxes using NSSM. I even wrote a blog post about it here: https://www.ricardclau.com/2016/03/running-go-executables-consul-telegraf-as-windows-services/ (the principles apply equally to things like Consul in the Agent mode and effectively any Go binary)

So, essentially it is all about:

  • Install chocolatey
  • Install NSSM via chocolatey
  • And install the service via NSSM

Hope this helps, happy to contribute to the official docs if the maintainers of the project want to!

Thanks for creating telegraf!

@sparrc
Copy link
Contributor

sparrc commented Apr 1, 2016

cool, thanks @ricardclau, I've seen NSSM before and it seems like a much better way to get a service running in Windows. What command generates the service, would it just be something like this?:

nssm install Telegraf C:\telegraf\telegraf.exe agent -config C:\telegraf\telegraf.conf

@sparrc
Copy link
Contributor

sparrc commented Apr 1, 2016

also, if you could write up a readme and submit it that would be great, you could put it in docs/WINDOWS_SERVICE.md

@ricardclau
Copy link
Contributor

@sparrc the command would be

nssm install Telegraf C:\telegraf\telegraf.exe -config C:\telegraf\telegraf.conf

The agent bit is for the Consul deamon I am afraid :) (https://www.consul.io/intro/getting-started/install.html)

Will do a PR with some md this weekend, thanks!

@sparrc
Copy link
Contributor

sparrc commented Apr 1, 2016

OK, if you put that into the blog post too I can probably get our marketing folks to tweet/promote it ;-)

@ricardclau
Copy link
Contributor

@sparrc Just amended my blog post with specific examples for Telegraf and mentioning the TICK stack. Hopefully good enough for your marketing folks! :)

Will work a bit now on the docs for Telegraf.

Thanks!

@elvarb
Copy link

elvarb commented Apr 12, 2016

I have used nssm in the past with good success, for example to run the whole ELK stack. There is no need for chocolatey, can just be downloaded to the telegraf directory and run from there.

@ricardclau
Copy link
Contributor

Yeah, the chocolatey bit is just to make it easier to automate in an idempotent way. Similar to using apt, yum and friends.
It is nice package system for Windows but of course you can always download nssm from http://nssm.cc/ and install it yourself

@StianOvrevage
Copy link
Contributor

I would really want to run telegraf as a Windows service as well. But since I have little or no control over the environment which telegraf will run I would STRONGLY prefer not to have to deal with nssm, which seems to be non-standard in the way that it registers itself and acts as an intermediary and relies a lot on GUI stuff which is hard to automate and use properly. So all in all NSSM might be nice but it doesn't smell that good from a reliability and compatibility point of view.

Bosun's scollector has a simple -winsvc switch that can install and remove itself as a Windows service without any dependencies ( https://godoc.org/bosun.org/cmd/scollector ).

@StianOvrevage
Copy link
Contributor

Just found the other issue where @cwegener said he is working on getting native -service-install in the binary. Any updates? :)

@elvarb
Copy link

elvarb commented Jun 16, 2016

Anyone just tried to use sc.exe to register the service?

@StianOvrevage
Copy link
Contributor

@elvarb Oh yes, for an hour or two. Seems telegraf.exe refuses to start when called as a service. I also tried a trick I saw on SO about calling it like "cmd /c telegraf.exe" which in theory should launch it in some kind of command session but to no avail.

Eventually just gave up and now running it manually in the foreground, hoping someone will fix it soon :)

@ricardclau
Copy link
Contributor

nssm is the only reliable way we have found to run Go binaries as Windows services as it acts as an intermediary between the Windows API and the Go signaling so that you can restart the services and so on

Plus, it seems to be getting popular and even tools like Ansible have modules to interact with it

Of course, having a native installer would be better but at the moment it seems to be the best (or least bad) way, even if it is not a Windows standard

@StianOvrevage
Copy link
Contributor

My 2c: scollector (Go) has been running without problems here for weeks as a Windows service. Ofc, there are checks to detect if it stops sending data to detect problems, but that has not happened yet.

@ricardclau
Copy link
Contributor

Interesting! We had a look at Consul and Telegraf and they did not have that option, this is why we went NSSM. I agree it is far from ideal.

https://github.com/bosun-monitor/bosun/blob/master/cmd/scollector/service_windows.go seems to be where the magic happens. It would be great to be able to remove NSSM!

@sparrc
Copy link
Contributor

sparrc commented Jun 21, 2016

FWIW there is a guide for setting up the exe as a service using NSSM here: https://github.com/influxdata/telegraf/blob/master/docs/WINDOWS_SERVICE.md

@steverweber
Copy link

not sure if this is helpfull..
https://godoc.org/golang.org/x/sys/windows/svc/mgr

@ricardclau
Copy link
Contributor

Yeah this is one of the packages being used in bosun :)

@aaaaa12322
Copy link

telegraf的windows版本,请问什么时候可以正式发布?
我的需求比较基础,没有什么高级需求:
1,cpu;
2,硬盘使用量;
3,硬盘读写(未实现);
4,内存;
5,网络流量监控(未实现);

@aaaaa12322
Copy link

最开始我打算使用bosun作云平台的监控功能,研究了几天,最后放弃了,在我的需求不是很复杂的情况下,我不想使用分布式的HBase,相对于java我更喜欢使用golang,我们公司所有软件项目也都在使用golang,非常期待telegraf的windows正式版发布。实际上bosun已经发布了windows的scollector,希望telegraf可以早日实现。我都有冲动自己改造bosun的scollector,让它支持influxdb

@sparrc
Copy link
Contributor

sparrc commented Jul 15, 2016

@aaaaa12322 sorry but we'll have to keep the conversation in English on the github page

@butitsnotme
Copy link
Contributor

For me using NSSM is not desirable, so I'm working on turning it into an actual Windows Service, I will submit a pull request once it is working. You can find the progress here: https://github.com/butitsnotme/telegraf/tree/windows-service

@SoleAngelus
Copy link
Contributor

@butitsnotme Can anyone say if this made it into the latest windows binaries? (1.0.0-beta3) Couldn't get this setup as a service when I tired earlier? PS was passing telegraf --service as a parameter and returning an error.

@sparrc
Copy link
Contributor

sparrc commented Aug 23, 2016

it's not there yet, will be available in 1.0 release candidate 1

@ricardclau
Copy link
Contributor

I somehow missed the development of this feature! Really nice to see it merged, will try to test from binaries ASAP!

Telegraf only keeps getting better and better! Good stuff!

@sparrc
Copy link
Contributor

sparrc commented Aug 23, 2016

release candidate 1 is now available to download from the README, please test out the new windows service functionality and open any issues that you find!

@elvarb
Copy link

elvarb commented Nov 28, 2016

Telegraf now has native service handling which is awesome but sadly now NSSM does not work with Telegraf.

Of the binaries I have the last version that worked with NSSM is 1.0.0-Beta3
The version after that which does not work is 1.0.1

@aszulinski
Copy link

aszulinski commented Apr 27, 2017

Hi,
basing on https://github.com/influxdata/telegraf/blob/master/docs/WINDOWS_SERVICE.md is there some way to specify custom name of service?
i.e.
telegraf.exe --service install --name "Telegraf custom"
It could help me to create two instances of service.

@butitsnotme
Copy link
Contributor

There is not currently, although it should not be too difficult to add...

@aszulinski
Copy link

My temporary fix for that is to rename it in registry via powershell:

Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\services\telegraf\" -Name "DisplayName" -Value "telegrafServiceName"
Rename-Item "HKLM:\SYSTEM\CurrentControlSet\services\telegraf" -NewName "telegrafServiceName"
Rename-Item "HKLM:\SYSTEM\CurrentControlSet\services\EventLog\Application\telegraf" -NewName "telegrafServiceName"

and restart of windows machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants