collectables.py 1.62 KB
Newer Older
Bach Dániel committed
1
from metrics import std
2

3

4
class collectables:
5 6
    __collectables = {
        std.cpu.usage.name: [std.cpu.usage],
Gregory Nagy committed
7
        std.cpu.times.name: [std.cpu.times],
8 9 10 11 12 13 14 15 16 17 18
        std.memory.usage.name: [std.memory.usage],
        std.swap.usage.name: [std.swap.usage],
        std.user.count.name: [std.user.count],
        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],
        std.system.boot_time.name: [std.system.boot_time],
        "network": [std.network.bytes_sent, std.network.bytes_received,
                    std.network.packages_sent, std.network.packages_received],
    }
19

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

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

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

32 33 34 35 36 37 38 39 40 41 42 43
    @staticmethod
    def provide(requests=[]):
        #valid_keys = collectables.listKeys()
        reqs = []
        for requests, value in requests.items():
            if value > 0:
                reqs.append([requests, value])
        collectors = []
        for request in reqs:
            for item in collectables.__collectables[request[0]]:
                collectors.append([item.harvest, request[1]])
        return collectors
44

45 46 47
    @staticmethod
    def provideAll():
        return collectables.provide(collectables.listKeys())