Exemple #1
0
    def get_metricdata(self, disk, disk_usage, name):
        ddev = os.path.basename(disk.device)
        for case in Switch(name):
            if case('df_bytes_total'):
                name = 'df.bytes.total/device={0},mount={1}'.format(ddev, disk.mountpoint)
                value = disk_usage.total

                return MetricData(name, value)
            if case('df_bytes_used'):
                name = 'df.bytes.used/device={0},mount={1}'.format(ddev, disk.mountpoint)
                value = disk_usage.used

                return MetricData(name, value)
            if case('df_bytes_free'):
                name = 'df.bytes.free/device={0},mount={1}'.format(ddev, disk.mountpoint)
                value = disk_usage.free

                return MetricData(name, value)
            if case('df_bytes_used_percentage'):
                name = 'df.bytes.used.percentage/device={0},mount={1}'.format(ddev, disk.mountpoint)
                value = disk_usage.percent

                return MetricData(name, value)
            if case():
                return None
Exemple #2
0
    def get_metricdata(self, mem_mem, mem_swap, name):
        tags = {}
        for case in Switch(name):
            if case('mem_memfree'):
                name = 'mem.memfree'
                value = mem_mem.free

                return MetricData(name, tags, value)
            if case('mem_memused_percentage'):
                name = 'mem.memused.percentage'
                value = mem_mem.percent

                return MetricData(name, tags, value)
            if case('mem_swapfree'):
                name = 'mem.swapfree'
                value = mem_swap.free

                return MetricData(name, tags, value)
            if case('mem_swapused_percentage'):
                name = 'mem.swapused.percentage'
                value = mem_swap.percent

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #3
0
    def get_metricdata(self, net_iface, net_count, name):
        tags = {'iface': net_iface}
        for case in Switch(name):
            if case('net_if_in_bytes_persec'):
                name = 'net.if.in.bytes.persec'
                value = net_count[0]

                return MetricData(name, tags, value)
            if case('net_if_out_bytes_persec'):
                name = 'net.if.out.bytes.persec'
                value = net_count[1]

                return MetricData(name, tags, value)
            if case('net_if_in_packets_persec'):
                name = 'net.if.in.packets.persec'
                value = net_count[2]

                return MetricData(name, tags, value)
            if case('net_if_out_packets_error'):
                name = 'net.if.out.packets.error'
                value = net_count[3]

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #4
0
    def get_metricdata(self, cpu_usage, name):
        tags = {}
        for case in Switch(name):
            if case('cpu_idle'):
                name = 'cpu.idle'
                value = cpu_usage.get('idle')

                return MetricData(name, tags, value)
            if case('cpu_user'):
                name = 'cpu.user'
                value = cpu_usage.get('user')

                return MetricData(name, tags, value)
            if case('cpu_iowait'):
                name = 'cpu.iowait'
                value = cpu_usage.get('iowait')

                return MetricData(name, tags, value)
            if case('cpu_system'):
                name = 'cpu.system'
                value = cpu_usage.get('system')

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #5
0
    def get_metricdata(self, disk, disk_usage, name):
        ddev = os.path.basename(disk.device)
        tags = {'device': ddev, 'mount': disk.mountpoint}
        for case in Switch(name):
            if case('df_bytes_total'):
                name = 'df.bytes.total'
                value = disk_usage.total

                return MetricData(name, tags, value)
            if case('df_bytes_used'):
                name = 'df.bytes.used'
                value = disk_usage.used

                return MetricData(name, tags, value)
            if case('df_bytes_free'):
                name = 'df.bytes.free'
                value = disk_usage.free

                return MetricData(name, tags, value)
            if case('df_bytes_used_percentage'):
                name = 'df.bytes.used.percentage'
                value = disk_usage.percent

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #6
0
    def get_metricdata(self, disk, disk_usage, name):
        tags = {'mount': disk.mountpoint}
        for case in Switch(name):
            if case('df_bytes_free'):
                name = 'df.bytes.free'
                value = disk_usage.free

                return MetricData(name, tags, value)
            if case('df_bytes_used_percentage'):
                name = 'df.bytes.used.percentage'
                value = disk_usage.percent

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #7
0
    def get_metricdata(self, redis_info, tags, name):
        for case in Switch(name):
            if case('p2p_redis_dbsize'):
                name = 'p2p.redis.dbsize'
                value = redis_info.get('keys')

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #8
0
    def get_metricdata(self, cpu_usage, name):
        tags = {}
        for case in Switch(name):
            if case('cpu_used_percentage'):
                name = 'cpu.used.percentage'
                value = 100 - cpu_usage.get('idle')

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #9
0
    def get_metricdata(self, load_usage, name):
        for case in Switch(name):
            if case('load_1min'):
                name = 'load.1min'
                value = load_usage[0]

                return MetricData(name, value)
            if case('load_5min'):
                name = 'load.5min'
                value = load_usage[1]

                return MetricData(name, value)
            if case('load_15min'):
                name = 'load.15min'
                value = load_usage[2]

                return MetricData(name, value)
            if case():
                return None
Exemple #10
0
    def get_metricdata(self, name):
        tags = {}
        for case in Switch(name):
            if case('procs_running'):
                name = 'procs.running'
                value = linux_metrics.procs_running()

                return MetricData(name, tags, value)
            if case():
                return None
Exemple #11
0
    def event_put(self, task, res):
        self._task_map.pop(task.requestID)

        for metric in res:
            if not metric.is_valid():
                logger.warning(
                    'Invalid monitor event data: {0}'.format(metric))
                continue
            logger.debug('Verified monitor event data: {0}'.format(metric))
            for item in metric.to_dict().itervalues():
                edata = MetricData.from_dict(item).to_json()
                event = self.event_handler.create_event(edata)
                self.channel_handler.wcache_handler.write(event.to_json())
Exemple #12
0
    def get_metricdata(self, net_iface, net_count, name):
        for case in Switch(name):
            if case('net_if_in_bytes_persec'):
                name = 'net.if.in.bytes.persec/iface={0}'.format(net_iface)
                value = net_count[0]

                return MetricData(name, value)
            if case('net_if_out_bytes_persec'):
                name = 'net.if.out.bytes.persec/iface={0}'.format(net_iface)
                value = net_count[1]

                return MetricData(name, value)
            if case('net_if_in_packets_persec'):
                name = 'net.if.in.packets.persec/iface={0}'.format(net_iface)
                value = net_count[2]

                return MetricData(name, value)
            if case('net_if_out_packets_error'):
                name = 'net.if.out.packets.error/iface={0}'.format(net_iface)
                value = net_count[3]

                return MetricData(name, value)
            if case():
                return None
Exemple #13
0
    def get_metricdata(self, mem_mem, mem_swap, name):
        for case in Switch(name):
            if case('mem_memtotal'):
                name = 'mem.memtotal'
                value = mem_mem.total

                return MetricData(name, value)
            if case('mem_memused'):
                name = 'mem.memused'
                value = mem_mem.used

                return MetricData(name, value)
            if case('mem_memfree'):
                name = 'mem.memfree'
                value = mem_mem.free

                return MetricData(name, value)
            if case('mem_memused_percentage'):
                name = 'mem.memused.percentage'
                value = mem_mem.percent

                return MetricData(name, value)
            if case('mem_swaptotal'):
                name = 'mem.swaptotal'
                value = mem_swap.total

                return MetricData(name, value)
            if case('mem_swapused'):
                name = 'mem.swapused'
                value = mem_swap.used

                return MetricData(name, value)
            if case('mem_swapfree'):
                name = 'mem.swapfree'
                value = mem_swap.free

                return MetricData(name, value)
            if case('mem_swapused_percentage'):
                name = 'mem.swapused.percentage'
                value = mem_swap.percent

                return MetricData(name, value)
            if case():
                return None
Exemple #14
0
    def get_metricdata(self, redis_info, tags, name):
        combinetag = self.get_combinetag(tags)
        for case in Switch(name):
            if case('redis_aof_last_rewrite_time'):
                name = 'redis.aof.last_rewrite_time{0}'.format(combinetag)
                value = redis_info.get('aof_last_rewrite_time_sec')

                return MetricData(name, value)
            if case('redis_aof_rewrite'):
                name = 'redis.aof.rewrite{0}'.format(combinetag)
                value = redis_info.get('aof_rewrite_in_progress')

                return MetricData(name, value)
            if case('redis_clients_biggest_input_buf'):
                name = 'redis.clients.biggest_input_buf{0}'.format(combinetag)
                value = redis_info.get('client_biggest_input_buf')

                return MetricData(name, value)
            if case('redis_clients_blocked'):
                name = 'redis.clients.blocked{0}'.format(combinetag)
                value = redis_info.get('blocked_clients')

                return MetricData(name, value)
            if case('redis_clients_longest_output_list'):
                name = 'redis.clients.longest_output_list{0}'.format(
                    combinetag)
                value = redis_info.get('client_longest_output_list')

                return MetricData(name, value)
            if case('redis_cpu_sys'):
                name = 'redis.cpu.sys{0}'.format(combinetag)
                value = redis_info.get('used_cpu_sys')

                return MetricData(name, value)
            if case('redis_cpu_sys_children'):
                name = 'redis.cpu.sys_children{0}'.format(combinetag)
                value = redis_info.get('used_cpu_sys_children')

                return MetricData(name, value)
            if case('redis_cpu_user'):
                name = 'redis.cpu.user{0}'.format(combinetag)
                value = redis_info.get('used_cpu_user')

                return MetricData(name, value)
            if case('redis_cpu_user_children'):
                name = 'redis.cpu.user_children{0}'.format(combinetag)
                value = redis_info.get('used_cpu_user_children')

                return MetricData(name, value)
            if case('redis_keys_evicted'):
                name = 'redis.keys.evicted{0}'.format(combinetag)
                value = redis_info.get('evicted_keys')

                return MetricData(name, value)
            if case('redis_keys_expired'):
                name = 'redis.keys.expired{0}'.format(combinetag)
                value = redis_info.get('expired_keys')

                return MetricData(name, value)
            if case('redis_mem_fragmentation_ratio'):
                name = 'redis.mem.fragmentation_ratio{0}'.format(combinetag)
                value = redis_info.get('mem_fragmentation_ratio')

                return MetricData(name, value)
            if case('redis_mem_lua'):
                name = 'redis.mem.lua{0}'.format(combinetag)
                value = redis_info.get('used_memory_lua')

                return MetricData(name, value)
            if case('redis_mem_rss'):
                name = 'redis.mem.rss{0}'.format(combinetag)
                value = redis_info.get('used_memory_rss')

                return MetricData(name, value)
            if case('redis_mem_used'):
                name = 'redis.mem.used{0}'.format(combinetag)
                value = redis_info.get('used_memory')

                return MetricData(name, value)
            if case('redis_net_clients'):
                name = 'redis.net.clients{0}'.format(combinetag)
                value = redis_info.get('connected_clients')

                return MetricData(name, value)
            if case('redis_net_commands'):
                name = 'redis.net.commands{0}'.format(combinetag)
                value = redis_info.get('total_commands_processed')

                return MetricData(name, value)
            if case('redis_net_rejected'):
                name = 'redis.net.rejected{0}'.format(combinetag)
                value = redis_info.get('rejected_connections')

                return MetricData(name, value)
            if case('redis_net_slaves'):
                name = 'redis.net.slaves{0}'.format(combinetag)
                value = redis_info.get('connected_slaves')

                return MetricData(name, value)
            if case('redis_perf_latest_fork_usec'):
                name = 'redis.perf.latest_fork_usec{0}'.format(combinetag)
                value = redis_info.get('latest_fork_usec')

                return MetricData(name, value)
            if case('redis_pubsub_channels'):
                name = 'redis.pubsub.channels{0}'.format(combinetag)
                value = redis_info.get('pubsub_channels')

                return MetricData(name, value)
            if case('redis_rdb_bgsave'):
                name = 'redis.rdb.bgsave{0}'.format(combinetag)
                value = redis_info.get('rdb_bgsave_in_progress')

                return MetricData(name, value)
            if case('redis_rdb_changes_since_last'):
                name = 'redis.rdb.changes_since_last{0}'.format(combinetag)
                value = redis_info.get('rdb_changes_since_last_save')

                return MetricData(name, value)
            if case('redis_rdb_last_bgsave_time'):
                name = 'redis.rdb.last_bgsave_time{0}'.format(combinetag)
                value = redis_info.get('rdb_last_bgsave_time_sec')

                return MetricData(name, value)
            if case('redis_replication_master_repl_offs'):
                name = 'redis.replication.master_repl_offs{0}'.format(
                    combinetag)
                value = redis_info.get('master_repl_offset')

                return MetricData(name, value)
            if case('redis_stats_keyspace_hits'):
                name = 'redis.stats.keyspace_hits{0}'.format(combinetag)
                value = redis_info.get('keyspace_hits')

                return MetricData(name, value)
            if case('redis_stats_keyspace_misses'):
                name = 'redis.stats.keyspace_misses{0}'.format(combinetag)
                value = redis_info.get('redis_stats_keyspace_misses')

                return MetricData(name, value)
            if case():
                return None