Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
104 changes: 0 additions & 104 deletions glances/events_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,110 +40,6 @@
{'msg': 'High memory consumption', 'thresholds': ['mem'], 'thresholds_min': 2},
]

# TODO: change the algo to use the following decision tree
# Source: Inspire by https://scoutapm.com/blog/slow_server_flow_chart
# _yes means threshold >= 2
# _no means threshold < 2
# With threshold:
# - 0: OK
# - 1: CAREFUL
# - 2: WARNING
# - 3: CRITICAL
tree_new = {
'cpu_iowait': {
'_yes': {
'memswap': {
'_yes': {
'mem': {
'_yes': {
# Once you've identified the offenders, the resolution will again
# depend on whether their memory usage seems business-as-usual or not.
# For example, a memory leak can be satisfactorily addressed by a one-time
# or periodic restart of the process.
# - if memory usage seems anomalous: kill the offending processes.
# - if memory usage seems business-as-usual: add RAM to the server,
# or split high-memory using services to other servers.
'_msg': "Memory issue"
},
'_no': {
# ???
'_msg': "Swap issue"
},
}
},
'_no': {
# Low swap means you have a "real" IO wait problem. The next step is to see what's hogging your IO.
# iotop is an awesome tool for identifying io offenders. Two things to note:
# unless you've already installed iotop, it's probably not already on your system.
# Recommendation: install it before you need it - - it's no fun trying to install a troubleshooting
# tool on an overloaded machine (iotop requires a Linux of 2.62 or above)
'_msg': "I/O issue"
},
}
},
'_no': {
'cpu_total': {
'_yes': {
'cpu_user': {
'_yes': {
# We expect the user-time percentage to be high.
# There's most likely a program or service you've configured on you server that's
# hogging CPU.
# Checking the % user time just confirms this. When you see that the % user-time is high,
# it's time to see what executable is monopolizing the CPU
# Once you've confirmed that the % usertime is high, check the process list(also provided
# by top).
# Be default, top sorts the process list by % CPU, so you can just look at the top process
# or processes.
# If there's a single process hogging the CPU in a way that seems abnormal, it's an
# anomalous situation
# that a service restart can fix. If there are are multiple processes taking up CPU
# resources, or it
# there's one process that takes lots of resources while otherwise functioning normally,
# than your setup
# may just be underpowered. You'll need to upgrade your server(add more cores),
# or split services out onto
# other boxes. In either case, you have a resolution:
# - if situation seems anomalous: kill the offending processes.
# - if situation seems typical given history: upgrade server or add more servers.
'_msg': "CPU issue with user process(es)"
},
'_no': {
'cpu_steal': {
'_yes': {
'_msg': "CPU issue with stolen time. System running the hypervisor may be too busy."
},
'_no': {'_msg': "CPU issue with system process(es)"},
}
},
}
},
'_no': {
'_yes': {
# ???
'_msg': "Memory issue"
},
'_no': {
# Your slowness isn't due to CPU or IO problems, so it's likely an application-specific issue.
# It's also possible that the slowness is being caused by another server in your cluster, or
# by an external service you rely on.
# start by checking important applications for uncharacteristic slowness(the DB is a good place
# to start), think through which parts of your infrastructure could be slowed down externally.
# For example, do you use an externally hosted email service that could slow down critical
# parts of your application ?
# If you suspect another server in your cluster, strace and lsof can provide information on
# what the process is doing or waiting on. Strace will show you which file descriptors are
# being read or written to (or being attempted to be read from) and lsof can give you a
# mapping of those file descriptors to network connections.
'_msg': "External issue"
},
},
}
},
}
}


def build_global_message():
"""Parse the decision tree and return the message.

Expand Down
50 changes: 1 addition & 49 deletions glances/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@
import multiprocessing
import os
import platform
import queue
import re
import socket
import subprocess
import sys
import weakref
from collections import OrderedDict
from configparser import ConfigParser, NoOptionError, NoSectionError
from datetime import datetime
from operator import itemgetter, methodcaller
from statistics import mean
from typing import Any, Optional, Union
from urllib.error import HTTPError, URLError
from typing import Any
from urllib.parse import urlparse
from urllib.request import Request, urlopen

Expand Down Expand Up @@ -95,11 +92,6 @@ def _json_default(v: Any) -> Any:
# Alias errors
PermissionError = OSError

# Alias methods
viewkeys = methodcaller('keys')
viewvalues = methodcaller('values')
viewitems = methodcaller('items')

# Multiprocessing start method (on POSIX system)
if LINUX or BSD or SUNOS or MACOS:
ctx_mp_fork = multiprocessing.get_context('fork')
Expand All @@ -124,18 +116,9 @@ def to_ascii(s):
return s.encode('ascii', 'ignore').decode()


def listitems(d):
return list(d.items())


def listkeys(d):
return list(d.keys())


def listvalues(d):
return list(d.values())


def u(s, errors='replace'):
if isinstance(s, text_type):
return s
Expand Down Expand Up @@ -232,13 +215,6 @@ def is_admin():
return os.getuid() == 0


def key_exist_value_not_none(k, d):
# Return True if:
# - key k exists
# - d[k] is not None
return k in d and d[k] is not None


def key_exist_value_not_none_not_v(k, d, value='', length=None):
# Return True if:
# - key k exists
Expand Down Expand Up @@ -272,33 +248,9 @@ def safe_makedirs(path):
raise


def get_time_diffs(ref, now):
if isinstance(ref, int):
diff = now - datetime.fromtimestamp(ref)
elif isinstance(ref, datetime):
diff = now - ref
elif not ref:
diff = 0

return diff


def get_first_true_val(conds):
return next(key for key, val in conds.items() if val)


def maybe_add_plural(count):
return "s" if count > 1 else ""


def build_str_when_more_than_seven_days(day_diff, unit):
scale = {'week': 7, 'month': 30, 'year': 365}[unit]

count = day_diff // scale

return str(count) + " " + unit + maybe_add_plural(count)


def pretty_date(ref, now=None):
"""
Get a datetime object or a int() Epoch timestamp and return a
Expand Down
1 change: 0 additions & 1 deletion glances/outputs/glances_stdout_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
class GlancesStdoutJson:
"""This class manages the Stdout JSON display."""

DEFAULT_DURATION: int = 3
FALLBACK_ERROR_JSON: str = '{"error": "Failed to serialize stats"}'

def __init__(self, config: Any | None = None, args: Any | None = None):
Expand Down
3 changes: 0 additions & 3 deletions glances/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

# from glances.logger import logger

# This constant defines the list of available processes sort key
sort_programs_key_list = ['cpu_percent', 'memory_percent', 'cpu_times', 'io_counters', 'name']


def create_program_dict(p):
"""Create a new entry in the dict (new program)"""
Expand Down
Loading