#!/usr/bin/env python
#
# Glances is a simple CLI monitoring tool based on libstatgrab
#
# Pre-requisites: python-statgrab 0.5 or >
#
# Copyright (C) Nicolargo 2012 <nicolas@nicolargo.com>
#
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.";
#
from __future__ import generators
try:
import os
import getopt
import sys
import signal
import time
import datetime
import multiprocessing
import gettext
except KeyboardInterrupt:
pass
# i18n
#=====
application = 'glances'
__version__ = "1.3.7"
gettext.install(application)
try:
import statgrab
except:
print _('Statgrab initialization failed, Glances cannot start.')
print
sys.exit(1)
try:
import curses
import curses.panel
except:
print _('Textmode GUI initialization failed, Glances cannot start.')
print
sys.exit(1)
# Classes
#========
class Timer():
"""
The timer class
"""
def __init__(self, duration):
self.started(duration)
def started(self, duration):
self.target = time.time() + duration
def finished(self):
return time.time() > self.target
class glancesLimits():
"""
Manage the limit OK,CAREFUL,WARNING,CRITICAL for each stats
"""
# The limit list is stored in an hash table:
# limits_list[STAT] = [ CAREFUL , WARNING , CRITICAL ]
# Exemple:
# limits_list['STD'] = [ 50, 70 , 90 ]
__limits_list = { # CAREFUL WARNING CRITICAL
'STD': [50, 70, 90],
'LOAD': [0.7, 1.0, 5.0]
}
def getSTDCareful(self):
return self.__limits_list['STD'][0]
def getSTDWarning(self):
return self.__limits_list['STD'][1]
def getSTDCritical(self):
return self.__limits_list['STD'][2]
def getLOADCareful(self, core = 1):
return self.__limits_list['LOAD'][0] * core
def getLOADWarning(self, core = 1):
return self.__limits_list['LOAD'][1] * core
def getLOADCritical(self, core = 1):
return self.__limits_list['LOAD'][2] * core
class glancesLogs():
"""
The main class to manage logs inside the Glances software
Logs is a list of list:
[["begin", "end", "WARNING|CRITICAL", "CPU|LOAD|MEM", MAX, AVG, MIN, SUM, COUNT],...]
"""
def __init__(self):
"""
Init the logs classe
"""
# Maximum size of the logs list
self.logs_max = 10
# Init the logs list
self.logs_list = []
def get(self):
"""
Return the logs list (RAW)
"""
return self.logs_list
def len(self):
"""
Return the number of item in the log list
"""
return self.logs_list.__len__()
def __itemexist__(self, item_type):
"""
An item exist in the list if:
* end is < 0
* item_type is matching
"""
for i in range(self.len()):
if ((self.logs_list[i][1] < 0)<