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

Add more "core" Linux metrics #2030

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions checks.d/linux_proc_extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# project
from checks import AgentCheck
from utils.subprocess_output import get_subprocess_output
from collections import Counter

PROCESS_STATES = {
'D': 'uninterruptible',
'R': 'runnable',
'S': 'sleeping',
'T': 'stopped',
'W': 'paging',
'X': 'dead',
'Z': 'zombie',
}

PROCESS_PRIOS = {
'<': 'high',
'N': 'low',
'L': 'locked'
}

class MoreUnixCheck(AgentCheck):
def check(self, instance):
tags = instance.get('tags', [])

state_counts = Counter()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know i'm the one who told you to use a Counter but i forgot that Counter were not available on python 2.6. Can you use a defaultdict(int) instead ?


prio_counts = Counter()

with open('/proc/sys/fs/inode-nr', 'r') as inode_info:
inode_stats = inode_info.readline().split()
self.gauge('system.inodes.total', float(inode_stats[0]), tags=tags)
self.gauge('system.inodes.used', float(inode_stats[1]), tags=tags)

with open('/proc/stat', 'r') as stat_info:
lines = [line.strip() for line in stat_info.readlines()]

for line in lines:
if line.startswith('ctxt'):
ctxt_count = float(line.split(' ')[1])
self.monotonic_count('system.linux.context_switches', ctxt_count, tags=tags)
elif line.startswith('processes'):
process_count = int(line.split(' ')[1])
self.monotonic_count('system.linux.processes_created', process_count, tags=tags)
elif line.startswith('intr'):
interrupts = int(line.split(' ')[1])
self.monotonic_count('system.linux.interrupts', interrupts, tags=tags)

with open('/proc/sys/kernel/random/entropy_avail') as entropy_info:
entropy = entropy_info.readline()
self.gauge('system.entropy.available', float(entropy), tags=tags)

ps = get_subprocess_output(['ps', '--no-header', '-eo', 'stat'], self.log)
for state in ps[0]:
# Each process state is a flag in a list of characters. See ps(1) for details.
for flag in list(state):
if state in PROCESS_STATES:
state_counts[PROCESS_STATES[state]] += 1
elif state in PROCESS_PRIOS:
prio_counts[PROCESS_PRIOS[state]] += 1

for state in state_counts:
state_tags = list(tags)
state_tags.append("state:" + state)
self.gauge('system.processes.states', float(state_counts[state]), state_tags)

for prio in prio_counts:
prio_tags = list(tags)
prio_tags.append("priority:" + prio)
self.gauge('system.processes.priorities', float(prio_counts[prio]), prio_tags)
5 changes: 5 additions & 0 deletions conf.d/linux_proc_extras.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# There's no configuration necessary for this check.
init_config:

instances:
- tags: []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comment here to say that the configuration it doesn't need any specific parameters ?