collectables.py 1.73 KB
Newer Older
1 2
from metrics import *

3
 class collectables:
4 5

    __collectables = {
Nagy Gergő committed
6 7
        std.cpu.usage.name:                     [std.cpu.usage],
        std.memory.usage.name:                  [std.memory.usage],
8
        std.user.count.name:                    [std.user.count],
Nagy Gergő committed
9 10 11 12 13 14 15 16
        std.network.packages_sent.name:         [std.network.packages_sent],
        std.network.packages_received.name:     [std.network.packages_received],
        std.network.bytes_sent.name:            [std.network.bytes_sent],
        std.network.bytes_received.name:        [std.network.bytes_received],
        "network":                              [std.network.bytes_sent,
                                                std.network.bytes_received,
                                                std.network.packages_sent,
                                                std.network.packages_received],
17 18 19
    }

    @staticmethod
Nagy Gergő committed
20
    def listKeys():
21 22 23
        return list(collectables.__collectables.keys())

    @staticmethod
Nagy Gergő committed
24
    def listMetricsToKey(key):
25 26 27
        return collectables.__collectables[key]

    @staticmethod
Nagy Gergő committed
28 29 30
    def listMetricsNameToKey(key):
        return [x.name for x in collectables.__collectables[key]]

31
     @staticmethod
Nagy Gergő committed
32
    def provide(requests = []):
33 34
        valid_keys = collectables.listKeys()
        reqs = [request for request, value in requests.items() if value=="True"]
35
        collectors = []
36
        for request in reqs:
37 38 39 40 41 42 43 44
            for item in collectables.__collectables[request]:
                collectors.append(item.harvest)
        seen = set()
        seen_add = seen.add
        return [ x for x in collectors if x not in seen and not seen_add(x)]

    @staticmethod
    def provideAll():
Nagy Gergő committed
45
        return collectables.provide(collectables.listKeys())
46 47