glances.stats_server.GlancesStatsServer.update()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
#
2
# This file is part of Glances.
3
#
4
# SPDX-FileCopyrightText: 2022 Nicolas Hennion <[email protected]>
5
#
6
# SPDX-License-Identifier: LGPL-3.0-only
7
#
8
9
"""The stats server manager."""
10
11
import collections
12
13
from glances.logger import logger
14
from glances.stats import GlancesStats
15
16
17
class GlancesStatsServer(GlancesStats):
18
    """This class stores, updates and gives stats for the server."""
19
20
    def __init__(self, config=None, args=None):
21
        # Init the stats
22
        super().__init__(config=config, args=args)
23
24
        # Init the all_stats dict used by the server
25
        # all_stats is a dict of dicts filled by the server
26
        self.all_stats = collections.defaultdict(dict)
27
28
        # In the update method, disable extended process stats
29
        logger.info("Disable extended processes stats in server mode")
30
31
    def update(self, input_stats=None):
32
        """Update the stats."""
33
        input_stats = input_stats or {}
34
35
        # Force update of all the stats
36
        super().update()
37
38
        # Disable the extended processes stats because it cause an high CPU load
39
        self._plugins['processcount'].disable_extended()
40
41
        # Build all_stats variable (concatenation of all the stats)
42
        self.all_stats = self._set_stats(input_stats)
43
44
    def _set_stats(self, input_stats):
45
        """Set the stats to the input_stats one."""
46
        # Build the all_stats with the get_raw() method of the plugins
47
        return {p: self._plugins[p].get_raw() for p in self._plugins if self._plugins[p].is_enabled()}
48
49
    def getAll(self):
50
        """Return the stats as a list."""
51
        return self.all_stats
52