Skip to content

Instantly share code, notes, and snippets.

@jazzdan
Last active April 28, 2022 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzdan/4b5b526853f00316fa04f319dd25773c to your computer and use it in GitHub Desktop.
Save jazzdan/4b5b526853f00316fa04f319dd25773c to your computer and use it in GitHub Desktop.
Datadog custom agent check to get the number of processes on a linux machine
from checks import AgentCheck
from datadog_checks.base.utils.subprocess_output import get_subprocess_output
# Get number of processes from `vmstat`
class NumProcessesCheck(AgentCheck):
def check(self, instance):
out, err, retcode = get_subprocess_output(['vmstat', '1', '2'], self.log, raise_on_empty_output=True)
lines = out.strip().split("\n")
last_line = lines[-1]
words = list(filter(None, last_line.split(" ")))
first_word = words[0]
num_threads = int(first_word)
self.gauge('custom.num_scheduled_threads', num_threads)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment