collectables.py 1.86 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],
root committed
8
        std.swap.usage.name:                    [std.swap.usage],
9
        std.user.count.name:                    [std.user.count],
Nagy Gergő committed
10 11 12 13
        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],
root committed
14
        std.system.boot_time.name:              [std.system.boot_time],
Nagy Gergő committed
15 16 17 18
        "network":                              [std.network.bytes_sent,
                                                std.network.bytes_received,
                                                std.network.packages_sent,
                                                std.network.packages_received],
19 20 21
    }

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

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

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

33
    @staticmethod
Nagy Gergő committed
34
    def provide(requests = []):
35
        valid_keys = collectables.listKeys()
36
        reqs = [request for request, value in requests.items() if value=="True"]
37
        collectors = []
38
        for request in reqs:
39
            for item in collectables.__collectables[request]:
40
                collectors.append(item.harvest)
41 42 43 44 45 46
        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
47
        return collectables.provide(collectables.listKeys())
48 49