HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/local/qcloud/monitor/barad/plugin/collector/vm/cpu.py
import sys
import os,time
sys.path.append(os.getcwd() + '/../../../comm/')
import constant
from plugin_base import VmBaseCollector
from utils.collect_tool import CpuCollect
from utils.metric_handler import MetricHandler


class CpuCollector(VmBaseCollector):
    def init(self):
        self.set_frequency(10)
        self.collector = CpuCollect()
        self.handler = MetricHandler()
        self.handler.namespace = 'qce/cvm'
        self.handler.dimensions = ['vm_uuid', 'vmip']

    def do_collect(self):
        now = int(time.time())
        (cpu_load_1, cpu_load_5, cpu_load_15, cpu_queue_length, total_threads) = self.collector.get_cpu_load()
        entire_cpu_usage = self.collector.get_cpu_usage()
        softirq_package_lost = self.collector.get_softirq_package_lost()
        vm_uuid = self.get_vm_uuid()
        vmip = self.get_vmip()
        dimensions = {'vm_uuid': vm_uuid, 'vmip': vmip } # not in docker cluster
        batch_metric = [
            {'name': 'cpu_usage', 'value': entire_cpu_usage},
            {'name': 'cpu_load_1', 'value': cpu_load_1},
            {'name': 'cpu_load_5', 'value': cpu_load_5},
            {'name': 'cpu_load_15', 'value': cpu_load_15},
            {'name': 'cpu_queue_length', 'value': cpu_queue_length},
            {'name': 'total_threads', 'value': total_threads},
        ]
        if softirq_package_lost != -1:
            metric = {'name': 'softirq_package_lost', 'value': softirq_package_lost}
            batch_metric.append(metric)
        self.handler.add_batch_metric(batch=batch_metric, dimensions=dimensions, timestamp=now)
        if (len( self.handler.get_metrics()) > 0) :
            data = {'sender':'nws_sender', 'datas': self.handler.pop_metrics()}
            self.put_data(data)

def main():
    collector = CpuCollector()
    collector.init()
    collector.collect()
    collector.dump_data()

if __name__ == '__main__':
    main()