1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of Glances. |
4
|
|
|
# |
5
|
|
|
# Copyright (C) 2017 Nicolargo <[email protected]> |
6
|
|
|
# |
7
|
|
|
# Glances is free software; you can redistribute it and/or modify |
8
|
|
|
# it under the terms of the GNU Lesser General Public License as published by |
9
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
# (at your option) any later version. |
11
|
|
|
# |
12
|
|
|
# Glances is distributed in the hope that it will be useful, |
13
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
# GNU Lesser General Public License for more details. |
16
|
|
|
# |
17
|
|
|
# You should have received a copy of the GNU Lesser General Public License |
18
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
|
20
|
|
|
"""The stats server manager.""" |
21
|
|
|
|
22
|
|
|
import collections |
23
|
|
|
|
24
|
|
|
from glances.stats import GlancesStats |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class GlancesStatsServer(GlancesStats): |
28
|
|
|
|
29
|
|
|
"""This class stores, updates and gives stats for the server.""" |
30
|
|
|
|
31
|
|
|
def __init__(self, |
32
|
|
|
config=None, |
33
|
|
|
args=None): |
34
|
|
|
# Init the stats |
35
|
|
|
super(GlancesStatsServer, self).__init__(config=config, args=args) |
36
|
|
|
|
37
|
|
|
# Init the all_stats dict used by the server |
38
|
|
|
# all_stats is a dict of dicts filled by the server |
39
|
|
|
self.all_stats = collections.defaultdict(dict) |
40
|
|
|
|
41
|
|
|
def update(self, input_stats=None): |
42
|
|
|
"""Update the stats.""" |
43
|
|
|
input_stats = input_stats or {} |
44
|
|
|
|
45
|
|
|
# Force update of all the stats |
46
|
|
|
super(GlancesStatsServer, self).update() |
47
|
|
|
|
48
|
|
|
# Build all_stats variable (concatenation of all the stats) |
49
|
|
|
self.all_stats = self._set_stats(input_stats) |
50
|
|
|
|
51
|
|
|
def _set_stats(self, input_stats): |
52
|
|
|
"""Set the stats to the input_stats one.""" |
53
|
|
|
# Build the all_stats with the get_raw() method of the plugins |
54
|
|
|
return {p: self._plugins[p].get_raw() for p in self._plugins if self._plugins[p].is_enable()} |
55
|
|
|
|
56
|
|
|
def getAll(self): |
57
|
|
|
"""Return the stats as a list.""" |
58
|
|
|
return self.all_stats |
59
|
|
|
|