mirror of
https://github.com/nicolargo/glances.git
synced 2026-03-14 12:00:14 -04:00
Server starts working :)
This commit is contained in:
@@ -25,4 +25,4 @@ outputs/
|
||||
glances_curse.py The Curse (console) interface
|
||||
glances_csv.py The CSV interface
|
||||
glances_html.py The HTML interface
|
||||
...
|
||||
...
|
||||
|
||||
@@ -166,99 +166,122 @@ class GlancesInstance():
|
||||
# Return the processes monitored list
|
||||
return json.dumps(monitors.getAll())
|
||||
|
||||
def getSystem(self):
|
||||
# Return operating system info
|
||||
# No need to update...
|
||||
#~ self.__update__()
|
||||
return json.dumps(self.stats.getSystem())
|
||||
def __getattr__(self, item):
|
||||
"""
|
||||
Overwrite the getattr in case of attribute is not found
|
||||
The goal is to dynamicaly generate the API get'Stats'() methods
|
||||
"""
|
||||
|
||||
header = 'get'
|
||||
# Check if the attribute starts with 'get'
|
||||
if (item.startswith(header)):
|
||||
try:
|
||||
# !!! Update the stat
|
||||
self.stats.update()
|
||||
# Return the attribute
|
||||
return getattr(self.stats, item)
|
||||
except Exception, e:
|
||||
# The method is not found for the plugin
|
||||
raise AttributeError(item)
|
||||
else:
|
||||
# Default behavior
|
||||
raise AttributeError(item)
|
||||
|
||||
def getCore(self):
|
||||
# Update and return number of Core
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getCore())
|
||||
# !!! Check the 2.0 cover before deleted the following comments
|
||||
|
||||
# def getSystem(self):
|
||||
# # Return operating system info
|
||||
# # No need to update...
|
||||
# #~ self.__update__()
|
||||
# return json.dumps(self.stats.getSystem())
|
||||
|
||||
def getCpu(self):
|
||||
# Update and return CPU stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getCpu())
|
||||
# def getCore(self):
|
||||
# # Update and return number of Core
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getCore())
|
||||
|
||||
def getLoad(self):
|
||||
# Update and return LOAD stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getLoad())
|
||||
# def getCpu(self):
|
||||
# # Update and return CPU stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getCpu())
|
||||
|
||||
def getMem(self):
|
||||
# Update and return MEM stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getMem())
|
||||
# def getLoad(self):
|
||||
# # Update and return LOAD stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getLoad())
|
||||
|
||||
def getMemSwap(self):
|
||||
# Update and return MEMSWAP stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getMemSwap())
|
||||
# def getMem(self):
|
||||
# # Update and return MEM stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getMem())
|
||||
|
||||
def getSensors(self):
|
||||
# Update and return SENSORS stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getSensors())
|
||||
# def getMemSwap(self):
|
||||
# # Update and return MEMSWAP stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getMemSwap())
|
||||
|
||||
def getHDDTemp(self):
|
||||
# Update and return HDDTEMP stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getHDDTemp())
|
||||
# def getSensors(self):
|
||||
# # Update and return SENSORS stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getSensors())
|
||||
|
||||
def getNetwork(self):
|
||||
# Update and return NET stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getNetwork())
|
||||
# def getHDDTemp(self):
|
||||
# # Update and return HDDTEMP stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getHDDTemp())
|
||||
|
||||
def getDiskIO(self):
|
||||
# Update and return DISK IO stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getDiskIO())
|
||||
# def getNetwork(self):
|
||||
# # Update and return NET stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getNetwork())
|
||||
|
||||
def getFs(self):
|
||||
# Update and return FS stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getFs())
|
||||
# def getDiskIO(self):
|
||||
# # Update and return DISK IO stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getDiskIO())
|
||||
|
||||
def getProcessCount(self):
|
||||
# Update and return ProcessCount stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getProcessCount())
|
||||
# def getFs(self):
|
||||
# # Update and return FS stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getFs())
|
||||
|
||||
def getProcessList(self):
|
||||
# Update and return ProcessList stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getProcessList())
|
||||
# def getProcessCount(self):
|
||||
# # Update and return ProcessCount stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getProcessCount())
|
||||
|
||||
def getBatPercent(self):
|
||||
# Update and return total batteries percent stats
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getBatPercent())
|
||||
# def getProcessList(self):
|
||||
# # Update and return ProcessList stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getProcessList())
|
||||
|
||||
def getNow(self):
|
||||
# Update and return current date/hour
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getNow().strftime(_("%Y-%m-%d %H:%M:%S")))
|
||||
# def getBatPercent(self):
|
||||
# # Update and return total batteries percent stats
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getBatPercent())
|
||||
|
||||
def getUptime(self):
|
||||
# Update and return system uptime
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.getUptime().strftime(_("%Y-%m-%d %H:%M:%S")))
|
||||
# def getNow(self):
|
||||
# # Update and return current date/hour
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getNow().strftime(_("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
def __getTimeSinceLastUpdate(self, IOType):
|
||||
assert(IOType in ['net', 'disk', 'process_disk'])
|
||||
return getTimeSinceLastUpdate(IOType)
|
||||
# def getUptime(self):
|
||||
# # Update and return system uptime
|
||||
# self.__update__()
|
||||
# return json.dumps(self.stats.getUptime().strftime(_("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
def getNetTimeSinceLastUpdate(self):
|
||||
return getTimeSinceLastUpdate('net')
|
||||
# def __getTimeSinceLastUpdate(self, IOType):
|
||||
# assert(IOType in ['net', 'disk', 'process_disk'])
|
||||
# return getTimeSinceLastUpdate(IOType)
|
||||
|
||||
def getDiskTimeSinceLastUpdate(self):
|
||||
return getTimeSinceLastUpdate('net')
|
||||
# def getNetTimeSinceLastUpdate(self):
|
||||
# return getTimeSinceLastUpdate('net')
|
||||
|
||||
def getProcessDiskTimeSinceLastUpdate(self):
|
||||
return getTimeSinceLastUpdate('process_disk')
|
||||
# def getDiskTimeSinceLastUpdate(self):
|
||||
# return getTimeSinceLastUpdate('net')
|
||||
|
||||
# def getProcessDiskTimeSinceLastUpdate(self):
|
||||
# return getTimeSinceLastUpdate('process_disk')
|
||||
|
||||
|
||||
class GlancesServer():
|
||||
|
||||
50
glances/plugins/glances_core.py
Normal file
50
glances/plugins/glances_core.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Glances - An eye on your system
|
||||
#
|
||||
# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
|
||||
#
|
||||
# Glances is free software; you can redistribute it and/or modify
|
||||
# it 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/>.
|
||||
|
||||
# Import system libs
|
||||
# Check for PSUtil already done in the glances_core script
|
||||
from psutil import NUM_CPUS
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
"""
|
||||
Glances' Core Plugin
|
||||
Get stats about CPU core number
|
||||
|
||||
stats is integer (number of core)
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
GlancesPlugin.__init__(self)
|
||||
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update core stats
|
||||
"""
|
||||
|
||||
# !!! Note: The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
|
||||
# !!! TODO: We had to return a dict (with both hys and log cpu number) instead of a integer
|
||||
try:
|
||||
self.stats = NUM_CPUS
|
||||
except Exception, e:
|
||||
self.stats = None
|
||||
@@ -58,4 +58,3 @@ class Plugin(GlancesPlugin):
|
||||
self.stats['os_version'] = ' '.join(os_version[::2])
|
||||
else:
|
||||
self.stats['os_version'] = ""
|
||||
|
||||
|
||||
50
glances/plugins/glances_load.py
Normal file
50
glances/plugins/glances_load.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Glances - An eye on your system
|
||||
#
|
||||
# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
|
||||
#
|
||||
# Glances is free software; you can redistribute it and/or modify
|
||||
# it 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/>.
|
||||
|
||||
# Import system libs
|
||||
# Check for PSUtil already done in the glances_core script
|
||||
from os import getloadavg
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
"""
|
||||
Glances's Load Plugin
|
||||
|
||||
stats is a dict
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
GlancesPlugin.__init__(self)
|
||||
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update load stats
|
||||
"""
|
||||
try:
|
||||
load = getloadavg()
|
||||
|
||||
self.stats = {'min1': load[0],
|
||||
'min5': load[1],
|
||||
'min15': load[2]}
|
||||
except Exception, err:
|
||||
self.stats = {}
|
||||
Reference in New Issue
Block a user