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

dd-agent fails to get gunicorn process on linux #706

Closed
nxvl opened this issue Oct 25, 2013 · 11 comments
Closed

dd-agent fails to get gunicorn process on linux #706

nxvl opened this issue Oct 25, 2013 · 11 comments
Milestone

Comments

@nxvl
Copy link

nxvl commented Oct 25, 2013

dd-agent try to gets unicorn master process by name using this line [1]:

   return  "gunicorn: master [%s]" % name

However, psutil trims the process name removing spaces, in this line [2]:

  name = f.read().split(' ')[1].replace('(', '').replace(')', '')

which return "gunicorn:" as process name, generating the following error:

  • instance #0 [ERROR]: GUnicornCheckError('Found no master process with name: gunicorn: master [PROCESS_NAME]',)
  1. https://github.com/DataDog/dd-agent/blob/master/checks.d/gunicorn.py#L129
  2. https://code.google.com/p/psutil/source/browse/psutil/_pslinux.py#472
@clutchski
Copy link
Contributor

Thanks for reporting. Two questions:

@nxvl
Copy link
Author

nxvl commented Oct 25, 2013

The line returned by f.read() looks like this:
'13979 (gunicorn: maste) S 1 13979 13979 0 -1 4202752 10282 3030 0 0 44 18 0 0 20 0 1 0 6171640 81555456 5808 18446744073709551615 4194304 6749740 140736594413936 140736594358920 140083335243587 0 0 16781312 137447943 18446744071580459545 0 0 17 0 0 0 0 0 0\n'
Linux trims the process name to 15 characters, making it imposible to match with the process full name.

@nxvl
Copy link
Author

nxvl commented Oct 25, 2013

Sure, this is ps | aux

root 13979 0.0 3.8 79644 23232 ? Ss 16:38 0:00 gunicorn: master [PROCESS_NAME]
USER 13994 0.0 4.3 84868 26308 ? S 16:38 0:00 gunicorn: worker [PROCESS_NAME]
USER 13995 0.0 4.3 84880 26320 ? S 16:38 0:00 gunicorn: worker [PROCESS_NAME]
USER 13996 0.0 4.3 84892 26328 ? S 16:38 0:00 gunicorn: worker [PROCESS_NAME]

Configuring the proc name as of that example won't help, since it will only change the value of PROCESS_NAME, which isn't shown by psutil

@nxvl
Copy link
Author

nxvl commented Oct 25, 2013

import psutil
[p.name for p in psutil.process_iter() if p.name == 'gunicorn:']
['gunicorn:', 'gunicorn:', 'gunicorn:', 'gunicorn:']

@nxvl
Copy link
Author

nxvl commented Oct 25, 2013

p.cmldine returns ['gunicorn: master [PROCESS_NAME]'] which is what dd-agent is looking for

@nxvl
Copy link
Author

nxvl commented Oct 25, 2013

Changing [1]:

        master_procs = [p for p in psutil.process_iter() if p.name == master_name]

For:

        master_procs = [p for p in psutil.process_iter() if p.cmdline and p.cmdline[0] == master_name]

Fixed the issue for me.

  1. https://github.com/DataDog/dd-agent/blob/master/checks.d/gunicorn.py#L114

@clutchski
Copy link
Contributor

Ok great. Thank for digging into that. We'll include it in our next release.

@nxvl
Copy link
Author

nxvl commented Oct 25, 2013

screenshot from 2013-10-25 15 52 47

The dashboard still shows the process as "gunicorn:" (doesn't hurt, just letting you know)

@remh remh closed this as completed in b8c8e71 Jan 24, 2014
@remh
Copy link
Contributor

remh commented Jan 24, 2014

Thanks @nxvl !

@ghost
Copy link

ghost commented Feb 12, 2016

For the posteriors,

I was having trouble getting these to work and realized I didn't have the necessary setproctitle pip package installed in the gunicorn env. This package makes the gunicorn --name field actually work instead of silently fail.

@ramtinms
Copy link

ramtinms commented Sep 9, 2016

sudo /usr/local/bin/pip install psutil solved my problem

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

4 participants