Improve default configuration values for IO stats

This commit is contained in:
Nicolargo 2016-04-27 11:55:21 +02:00
parent b7ac674b35
commit 4934d78d8e
2 changed files with 69 additions and 63 deletions

View File

@ -11,16 +11,12 @@ swap_warning=70
swap_critical=90 swap_critical=90
[cpu] [cpu]
# Define CPU thresholds in % # Default values if not defined: 50/70/90 (except for iowait)
# Default values if not defined: 50/70/90
user_careful=50 user_careful=50
user_warning=70 user_warning=70
user_critical=90 user_critical=90
#user_log=False #user_log=False
#user_critical_action=echo `date` - {{user}} > /tmp/cpu.alert #user_critical_action=echo {{user}} {{value}} {{max}} > /tmp/cpu.alert
iowait_careful=50
iowait_warning=70
iowait_critical=90
system_careful=50 system_careful=50
system_warning=70 system_warning=70
system_critical=90 system_critical=90
@ -28,6 +24,11 @@ steal_careful=50
steal_warning=70 steal_warning=70
steal_critical=90 steal_critical=90
#steal_log=True #steal_log=True
# I/O wait percentage should be lower than 1/# (of CPU cores)
# Let blanck to default config (1/#-20% / 1/# / 1/#+20%)
#iowait_careful=20
#iowait_warning=25
#iowait_critical=30
# Context switch limit per core / second # Context switch limit per core / second
# For example, if you have 2 Core, critical limit will be 28000/sec # For example, if you have 2 Core, critical limit will be 28000/sec
ctx_switches_careful=10000 ctx_switches_careful=10000

View File

@ -21,6 +21,7 @@
import os import os
import sys import sys
import multiprocessing
from io import open from io import open
from glances import __appname__ from glances import __appname__
@ -108,95 +109,94 @@ class Config(object):
# Quicklook # Quicklook
if not self.parser.has_section('quicklook'): if not self.parser.has_section('quicklook'):
self.parser.add_section('quicklook') self.parser.add_section('quicklook')
self.parser.set('quicklook', 'cpu_careful', '50') self.set_default('quicklook', 'cpu_careful', '50')
self.parser.set('quicklook', 'cpu_warning', '70') self.set_default('quicklook', 'cpu_warning', '70')
self.parser.set('quicklook', 'cpu_critical', '90') self.set_default('quicklook', 'cpu_critical', '90')
self.parser.set('quicklook', 'mem_careful', '50') self.set_default('quicklook', 'mem_careful', '50')
self.parser.set('quicklook', 'mem_warning', '70') self.set_default('quicklook', 'mem_warning', '70')
self.parser.set('quicklook', 'mem_critical', '90') self.set_default('quicklook', 'mem_critical', '90')
self.parser.set('quicklook', 'swap_careful', '50') self.set_default('quicklook', 'swap_careful', '50')
self.parser.set('quicklook', 'swap_warning', '70') self.set_default('quicklook', 'swap_warning', '70')
self.parser.set('quicklook', 'swap_critical', '90') self.set_default('quicklook', 'swap_critical', '90')
# CPU # CPU
if not self.parser.has_section('cpu'): if not self.parser.has_section('cpu'):
self.parser.add_section('cpu') self.parser.add_section('cpu')
self.parser.set('cpu', 'user_careful', '50') self.set_default('cpu', 'user_careful', '50')
self.parser.set('cpu', 'user_warning', '70') self.set_default('cpu', 'user_warning', '70')
self.parser.set('cpu', 'user_critical', '90') self.set_default('cpu', 'user_critical', '90')
self.parser.set('cpu', 'iowait_careful', '50') self.set_default('cpu', 'system_careful', '50')
self.parser.set('cpu', 'iowait_warning', '70') self.set_default('cpu', 'system_warning', '70')
self.parser.set('cpu', 'iowait_critical', '90') self.set_default('cpu', 'system_critical', '90')
self.parser.set('cpu', 'system_careful', '50') self.set_default('cpu', 'steal_careful', '50')
self.parser.set('cpu', 'system_warning', '70') self.set_default('cpu', 'steal_warning', '70')
self.parser.set('cpu', 'system_critical', '90') self.set_default('cpu', 'steal_critical', '90')
self.parser.set('cpu', 'steal_careful', '50') # By default I/O wait should be lower than 1/number of CPU cores
self.parser.set('cpu', 'steal_warning', '70') iowait_bottleneck = (1.0 / multiprocessing.cpu_count()) * 100.0
self.parser.set('cpu', 'steal_critical', '90') self.set_default('cpu', 'iowait_careful', str(iowait_bottleneck - (iowait_bottleneck * 0.20)))
self.set_default('cpu', 'iowait_warning', str(iowait_bottleneck))
self.set_default('cpu', 'iowait_critical', str(iowait_bottleneck + (iowait_bottleneck * 0.20)))
# Per-CPU # Per-CPU
if not self.parser.has_section('percpu'): if not self.parser.has_section('percpu'):
self.parser.add_section('percpu') self.parser.add_section('percpu')
self.parser.set('percpu', 'user_careful', '50') self.set_default('percpu', 'user_careful', '50')
self.parser.set('percpu', 'user_warning', '70') self.set_default('percpu', 'user_warning', '70')
self.parser.set('percpu', 'user_critical', '90') self.set_default('percpu', 'user_critical', '90')
self.parser.set('percpu', 'iowait_careful', '50') self.set_default('percpu', 'system_careful', '50')
self.parser.set('percpu', 'iowait_warning', '70') self.set_default('percpu', 'system_warning', '70')
self.parser.set('percpu', 'iowait_critical', '90') self.set_default('percpu', 'system_critical', '90')
self.parser.set('percpu', 'system_careful', '50')
self.parser.set('percpu', 'system_warning', '70')
self.parser.set('percpu', 'system_critical', '90')
# Load # Load
if not self.parser.has_section('load'): if not self.parser.has_section('load'):
self.parser.add_section('load') self.parser.add_section('load')
self.parser.set('load', 'careful', '0.7') self.set_default('load', 'careful', '0.7')
self.parser.set('load', 'warning', '1.0') self.set_default('load', 'warning', '1.0')
self.parser.set('load', 'critical', '5.0') self.set_default('load', 'critical', '5.0')
# Mem # Mem
if not self.parser.has_section('mem'): if not self.parser.has_section('mem'):
self.parser.add_section('mem') self.parser.add_section('mem')
self.parser.set('mem', 'careful', '50') self.set_default('mem', 'careful', '50')
self.parser.set('mem', 'warning', '70') self.set_default('mem', 'warning', '70')
self.parser.set('mem', 'critical', '90') self.set_default('mem', 'critical', '90')
# Swap # Swap
if not self.parser.has_section('memswap'): if not self.parser.has_section('memswap'):
self.parser.add_section('memswap') self.parser.add_section('memswap')
self.parser.set('memswap', 'careful', '50') self.set_default('memswap', 'careful', '50')
self.parser.set('memswap', 'warning', '70') self.set_default('memswap', 'warning', '70')
self.parser.set('memswap', 'critical', '90') self.set_default('memswap', 'critical', '90')
# FS # FS
if not self.parser.has_section('fs'): if not self.parser.has_section('fs'):
self.parser.add_section('fs') self.parser.add_section('fs')
self.parser.set('fs', 'careful', '50') self.set_default('fs', 'careful', '50')
self.parser.set('fs', 'warning', '70') self.set_default('fs', 'warning', '70')
self.parser.set('fs', 'critical', '90') self.set_default('fs', 'critical', '90')
# Sensors # Sensors
if not self.parser.has_section('sensors'): if not self.parser.has_section('sensors'):
self.parser.add_section('sensors') self.parser.add_section('sensors')
self.parser.set('sensors', 'temperature_core_careful', '60') self.set_default('sensors', 'temperature_core_careful', '60')
self.parser.set('sensors', 'temperature_core_warning', '70') self.set_default('sensors', 'temperature_core_warning', '70')
self.parser.set('sensors', 'temperature_core_critical', '80') self.set_default('sensors', 'temperature_core_critical', '80')
self.parser.set('sensors', 'temperature_hdd_careful', '45') self.set_default('sensors', 'temperature_hdd_careful', '45')
self.parser.set('sensors', 'temperature_hdd_warning', '52') self.set_default('sensors', 'temperature_hdd_warning', '52')
self.parser.set('sensors', 'temperature_hdd_critical', '60') self.set_default('sensors', 'temperature_hdd_critical', '60')
self.parser.set('sensors', 'battery_careful', '80') self.set_default('sensors', 'battery_careful', '80')
self.parser.set('sensors', 'battery_warning', '90') self.set_default('sensors', 'battery_warning', '90')
self.parser.set('sensors', 'battery_critical', '95') self.set_default('sensors', 'battery_critical', '95')
# Process list # Process list
if not self.parser.has_section('processlist'): if not self.parser.has_section('processlist'):
self.parser.add_section('processlist') self.parser.add_section('processlist')
self.parser.set('processlist', 'cpu_careful', '50') self.set_default('processlist', 'cpu_careful', '50')
self.parser.set('processlist', 'cpu_warning', '70') self.set_default('processlist', 'cpu_warning', '70')
self.parser.set('processlist', 'cpu_critical', '90') self.set_default('processlist', 'cpu_critical', '90')
self.parser.set('processlist', 'mem_careful', '50') self.set_default('processlist', 'mem_careful', '50')
self.parser.set('processlist', 'mem_warning', '70') self.set_default('processlist', 'mem_warning', '70')
self.parser.set('processlist', 'mem_critical', '90') self.set_default('processlist', 'mem_critical', '90')
@property @property
def loaded_config_file(self): def loaded_config_file(self):
@ -211,6 +211,11 @@ class Config(object):
"""Return info about the existence of a section.""" """Return info about the existence of a section."""
return self.parser.has_section(section) return self.parser.has_section(section)
def set_default(self, section, option, default):
"""If the option did not exist, create a default value."""
if not self.parser.has_option(section, option):
self.parser.set(section, option, default)
def get_value(self, section, option, default=None): def get_value(self, section, option, default=None):
"""Get the value of an option, if it exists.""" """Get the value of an option, if it exists."""
try: try: