Last active
April 28, 2022 17:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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