本文整理汇总了Python中xmlrpc.client.ServerProxy.getAllMonitored方法的典型用法代码示例。如果您正苦于以下问题:Python ServerProxy.getAllMonitored方法的具体用法?Python ServerProxy.getAllMonitored怎么用?Python ServerProxy.getAllMonitored使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpc.client.ServerProxy
的用法示例。
在下文中一共展示了ServerProxy.getAllMonitored方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GlancesClient
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import getAllMonitored [as 别名]
#.........这里部分代码省略.........
except ProtocolError as err:
# Others errors
if str(err).find(" 401 ") > 0:
print(_("Error: Connection to server failed: Bad password"))
else:
print(_("Error: Connection to server failed: {0}").format(err))
sys.exit(2)
if self.get_mode() == 'glances' and version[:3] == client_version[:3]:
# Init stats
self.stats = GlancesStatsClient()
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
elif self.get_mode() == 'snmp':
print (_("Info: Connection to Glances server failed. Trying fallback to SNMP..."))
# Then fallback to SNMP if needed
from glances.core.glances_stats import GlancesStatsClientSNMP
# Init stats
self.stats = GlancesStatsClientSNMP(args=self.args)
if not self.stats.check_snmp():
print(_("Error: Connection to SNMP server failed"))
sys.exit(2)
else:
ret = False
if ret:
# Load limits from the configuration file
# Each client can choose its owns limits
self.stats.load_limits(self.config)
# Init screen
self.screen = GlancesCurses(args=self.args)
# Return result
return ret
def update(self):
"""Update stats from Glances/SNMP server."""
if self.get_mode() == 'glances':
return self.update_glances()
elif self.get_mode() == 'snmp':
return self.update_snmp()
else:
print(_("Error: Unknown server mode: {0}").format(self.get_mode()))
sys.exit(2)
def update_glances(self):
"""Get stats from Glances server.
Return the client/server connection status:
- Connected: Connection OK
- Disconnected: Connection NOK
"""
# Update the stats
try:
server_stats = json.loads(self.client.getAll())
server_stats['monitor'] = json.loads(self.client.getAllMonitored())
except socket.error:
# Client cannot get server stats
return "Disconnected"
except Fault:
# Client cannot get server stats (issue #375)
return "Disconnected"
else:
# Put it in the internal dict
self.stats.update(server_stats)
return "Connected"
def update_snmp(self):
"""Get stats from SNMP server.
Return the client/server connection status:
- SNMP: Connection with SNMP server OK
- Disconnected: Connection NOK
"""
# Update the stats
try:
self.stats.update()
except:
# Client can not get SNMP server stats
return "Disconnected"
else:
# Grab success
return "SNMP"
def serve_forever(self):
"""Main client loop."""
while True:
# Update the stats
cs_status = self.update()
# Update the screen
self.screen.update(self.stats, cs_status=cs_status)
# print self.stats
# print self.stats.getAll()
def end(self):
"""End of the client session."""
self.screen.end()
示例2: GlancesClient
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import getAllMonitored [as 别名]
#.........这里部分代码省略.........
"Client and server not compatible: Client version: %s / Server version: %s" % (version, client_version))
else:
self.set_mode('snmp')
if self.get_mode() == 'snmp':
logger.info("Trying to grab stats by SNMP...")
# Fallback to SNMP if needed
from glances.core.glances_stats import GlancesStatsClientSNMP
# Init stats
self.stats = GlancesStatsClientSNMP(args=self.args)
if not self.stats.check_snmp():
logger.error("Connection to SNMP server failed")
if not return_to_browser:
sys.exit(2)
else:
return False
if ret:
# Load limits from the configuration file
# Each client can choose its owns limits
self.stats.load_limits(self.config)
# Init screen
self.screen = GlancesCursesClient(args=self.args)
# Return result
return ret
def update(self):
"""Update stats from Glances/SNMP server."""
if self.get_mode() == 'glances':
return self.update_glances()
elif self.get_mode() == 'snmp':
return self.update_snmp()
else:
self.end()
logger.critical("Unknown server mode: {0}".format(self.get_mode()))
sys.exit(2)
def update_glances(self):
"""Get stats from Glances server.
Return the client/server connection status:
- Connected: Connection OK
- Disconnected: Connection NOK
"""
# Update the stats
try:
server_stats = json.loads(self.client.getAll())
server_stats['monitor'] = json.loads(self.client.getAllMonitored())
except socket.error:
# Client cannot get server stats
return "Disconnected"
except Fault:
# Client cannot get server stats (issue #375)
return "Disconnected"
else:
# Put it in the internal dict
self.stats.update(server_stats)
return "Connected"
def update_snmp(self):
"""Get stats from SNMP server.
Return the client/server connection status:
- SNMP: Connection with SNMP server OK
- Disconnected: Connection NOK
"""
# Update the stats
try:
self.stats.update()
except Exception:
# Client cannot get SNMP server stats
return "Disconnected"
else:
# Grab success
return "SNMP"
def serve_forever(self, return_to_browser=False):
"""Main client loop."""
exitkey = False
while True and not exitkey:
# Update the stats
cs_status = self.update()
# Update the screen
exitkey = self.screen.update(self.stats,
cs_status=cs_status,
return_to_browser=return_to_browser)
return self.get_mode()
def end(self):
"""End of the client session."""
self.screen.end()