mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-15 12:33:28 +03:00
63 lines
2.7 KiB
Python
63 lines
2.7 KiB
Python
#!/usr/bin/python
|
||
# -*- coding: utf-8 -*-
|
||
# Author: Cemre ALPSOY <cemre.alpsoy@agem.com.tr>
|
||
# Author: Emre Akkaya <emre.akkaya@agem.com.tr>
|
||
|
||
from psutil import disk_io_counters
|
||
from base.plugin.abstract_plugin import AbstractPlugin
|
||
import json
|
||
from base.system.disk_info import DiskInfo
|
||
|
||
class ResourceUsage(AbstractPlugin):
|
||
def __init__(self, data, context):
|
||
super(AbstractPlugin, self).__init__()
|
||
self.data = data
|
||
self.context = context
|
||
self.logger = self.get_logger()
|
||
self.message_code = self.get_message_code()
|
||
|
||
def handle_task(self):
|
||
try:
|
||
device = ""
|
||
self.logger.debug("Gathering resource usage for disk, memory and CPU.")
|
||
|
||
ssd_list, hdd_list = DiskInfo.get_all_disks()
|
||
|
||
for part in self.Hardware.Disk.partitions():
|
||
if len(device) != 0:
|
||
device += ", "
|
||
device = device + part.device
|
||
|
||
data = {'System': self.Os.name(), 'Release': self.Os.kernel_release(),
|
||
'Version': self.Os.distribution_version(), 'Machine': self.Os.architecture(),
|
||
'CPU Physical Core Count': self.Hardware.Cpu.physical_core_count(),
|
||
'Total Memory': self.Hardware.Memory.total(),
|
||
'Usage': self.Hardware.Memory.used(),
|
||
'Total Disc': self.Hardware.Disk.total(),
|
||
'Usage Disc': self.Hardware.Disk.used(),
|
||
'Processor': self.Hardware.Cpu.brand(),
|
||
'Device': device,
|
||
'CPU Logical Core Count': self.Hardware.Cpu.logical_core_count(),
|
||
'CPU Actual Hz': self.Hardware.Cpu.hz_actual(),
|
||
'CPU Advertised Hz': self.Hardware.Cpu.hz_advertised()
|
||
}
|
||
|
||
if len(ssd_list) > 0:
|
||
data['hardware.disk.ssd.info'] = ssd_list
|
||
|
||
if len(hdd_list) > 0:
|
||
data['hardware.disk.hdd.info'] = hdd_list
|
||
|
||
self.logger.debug("Resource usage info gathered.")
|
||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||
message='Anlık kaynak kullanım bilgisi başarıyla toplandı.',
|
||
data=json.dumps(data), content_type=self.get_content_type().APPLICATION_JSON.value)
|
||
except Exception as e:
|
||
self.logger.error(str(e))
|
||
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
||
message='Anlık kaynak kullanım bilgisi toplanırken hata oluştu: {0}'.format(str(e)))
|
||
|
||
|
||
def handle_task(task, context):
|
||
plugin = ResourceUsage(task, context)
|
||
plugin.handle_task()
|