mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
ssd and hdd list function added
This commit is contained in:
parent
58b25abdd2
commit
d2b6599cb0
4 changed files with 110 additions and 2 deletions
|
@ -6,6 +6,7 @@ import json
|
||||||
from base.scope import Scope
|
from base.scope import Scope
|
||||||
from base.system.system import System
|
from base.system.system import System
|
||||||
from base.util.util import Util
|
from base.util.util import Util
|
||||||
|
from base.system.disk_info import DiskInfo
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ class Messaging(object):
|
||||||
return str(json_data)
|
return str(json_data)
|
||||||
|
|
||||||
def login_msg(self, username,ip=None):
|
def login_msg(self, username,ip=None):
|
||||||
|
ssd_list, hdd_list = DiskInfo.get_all_disks()
|
||||||
data = dict()
|
data = dict()
|
||||||
data['type'] = 'LOGIN'
|
data['type'] = 'LOGIN'
|
||||||
data['username'] = username
|
data['username'] = username
|
||||||
|
@ -82,13 +84,18 @@ class Messaging(object):
|
||||||
|
|
||||||
self.logger.debug('USER IP : '+ str(ip)+ ' IPADDRESSES : '+ str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''))
|
self.logger.debug('USER IP : '+ str(ip)+ ' IPADDRESSES : '+ str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''))
|
||||||
|
|
||||||
|
|
||||||
data['hardware.monitors'] = str(System.Hardware.monitors()),
|
data['hardware.monitors'] = str(System.Hardware.monitors()),
|
||||||
data['hardware.screens'] = str(System.Hardware.screens()),
|
data['hardware.screens'] = str(System.Hardware.screens()),
|
||||||
data['hardware.usbDevices'] = str(System.Hardware.usb_devices()),
|
data['hardware.usbDevices'] = str(System.Hardware.usb_devices()),
|
||||||
data['hardware.printers'] = str(System.Hardware.printers()),
|
data['hardware.printers'] = str(System.Hardware.printers()),
|
||||||
data['hardware.systemDefinitions'] = str(System.Hardware.system_definitions()),
|
data['hardware.systemDefinitions'] = str(System.Hardware.system_definitions()),
|
||||||
|
|
||||||
|
if len(ssd_list) > 0:
|
||||||
|
data['hardware.disk.ssd.info'] = ssd_list
|
||||||
|
|
||||||
|
if len(hdd_list) > 0:
|
||||||
|
data['hardware.disk.hdd.info'] = hdd_list
|
||||||
|
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('Login message was created')
|
self.logger.debug('Login message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
|
@ -20,6 +20,7 @@ from base.registration.execute_cancel_sssd_authentication import ExecuteCancelSS
|
||||||
from base.registration.execute_sssd_authentication import ExecuteSSSDAuthentication
|
from base.registration.execute_sssd_authentication import ExecuteSSSDAuthentication
|
||||||
from base.registration.execute_sssd_ad_authentication import ExecuteSSSDAdAuthentication
|
from base.registration.execute_sssd_ad_authentication import ExecuteSSSDAdAuthentication
|
||||||
from base.registration.execute_cancel_sssd_ad_authentication import ExecuteCancelSSSDAdAuthentication
|
from base.registration.execute_cancel_sssd_ad_authentication import ExecuteCancelSSSDAdAuthentication
|
||||||
|
from base.system.disk_info import DiskInfo
|
||||||
|
|
||||||
class Registration:
|
class Registration:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -297,6 +298,12 @@ class Registration:
|
||||||
'agentVersion': Util.get_agent_version(),
|
'agentVersion': Util.get_agent_version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssd_list, hdd_list = DiskInfo.get_all_disks()
|
||||||
|
if len(ssd_list) > 0:
|
||||||
|
params['hardware.disk.ssd.info'] = ssd_list
|
||||||
|
if len(hdd_list) > 0:
|
||||||
|
params['hardware.disk.hdd.info'] = hdd_list
|
||||||
|
|
||||||
return json.dumps(params)
|
return json.dumps(params)
|
||||||
|
|
||||||
def unregister(self):
|
def unregister(self):
|
||||||
|
|
82
usr/share/ahenk/base/system/disk_info.py
Normal file
82
usr/share/ahenk/base/system/disk_info.py
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: Agah Hulusi ÖZ <enghulusi@gmail.com>
|
||||||
|
|
||||||
|
from base.util.util import Util
|
||||||
|
|
||||||
|
# HDD and SSD disk information
|
||||||
|
class DiskInfo():
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_all_disks():
|
||||||
|
result_code, p_out, p_err = Util.execute("lsblk -b -o NAME,TYPE,ROTA,SIZE,RM,HOTPLUG,FSUSED | grep -v loop | awk '$5 == \"0\" { print $0 }'")
|
||||||
|
txt = p_out.split("\n")
|
||||||
|
while '' in txt:
|
||||||
|
txt.remove('')
|
||||||
|
detail_txt = []
|
||||||
|
ssd_list = []
|
||||||
|
hdd_list = []
|
||||||
|
# Ignore USB from list
|
||||||
|
for item in txt:
|
||||||
|
item = item.split()
|
||||||
|
detail_txt.append(item)
|
||||||
|
# SSD and HDD list
|
||||||
|
for disk in detail_txt:
|
||||||
|
# Second element of disk equal to rotation type.
|
||||||
|
# Rotation type show that disk is SSD or HDD
|
||||||
|
# If it equals to "0" SSD
|
||||||
|
# If it equals to "1" HDD
|
||||||
|
if disk[2] == "0" and disk[1] == "disk":
|
||||||
|
ssd_list.append({
|
||||||
|
"name": disk[0],
|
||||||
|
"type": "SSD",
|
||||||
|
"total": disk[3],
|
||||||
|
"used": 0,
|
||||||
|
})
|
||||||
|
elif disk[2] == "1" and disk[1] == "disk":
|
||||||
|
hdd_list.append({
|
||||||
|
"name": disk[0],
|
||||||
|
"type": "HDD",
|
||||||
|
"total": disk[3],
|
||||||
|
"used": 0,
|
||||||
|
})
|
||||||
|
# Calculate the usage
|
||||||
|
used = 0
|
||||||
|
ssd_list_counter = 0
|
||||||
|
hdd_list_counter = 0
|
||||||
|
is_first_disk = True
|
||||||
|
for item in detail_txt:
|
||||||
|
if item[1] == "disk":
|
||||||
|
if is_first_disk:
|
||||||
|
total = item[3]
|
||||||
|
name = item[0]
|
||||||
|
type = item[2]
|
||||||
|
is_first_disk = False
|
||||||
|
else:
|
||||||
|
if type == "0":
|
||||||
|
ssd_list[ssd_list_counter]["used"] = used
|
||||||
|
ssd_list_counter += 1
|
||||||
|
elif type == "1":
|
||||||
|
hdd_list[hdd_list_counter]["used"] = used
|
||||||
|
hdd_list_counter += 1
|
||||||
|
name = item[0]
|
||||||
|
used = 0
|
||||||
|
total = item[3]
|
||||||
|
type = item[2]
|
||||||
|
else:
|
||||||
|
if len(item) > 6 and item[0] != "NAME":
|
||||||
|
used += int(item[6])
|
||||||
|
if type == "0":
|
||||||
|
ssd_list[ssd_list_counter]["used"] = used
|
||||||
|
ssd_list_counter += 1
|
||||||
|
elif type == "1":
|
||||||
|
hdd_list[hdd_list_counter]["used"] = used
|
||||||
|
hdd_list_counter += 1
|
||||||
|
for item in ssd_list:
|
||||||
|
item["total"]= int(int(item["total"]) / (1000 * 1000))
|
||||||
|
item["used"] = int(int(item["used"]) / (1000 * 1000))
|
||||||
|
for item in hdd_list:
|
||||||
|
item["total"] = int(int(item["total"]) / (1000 * 1000))
|
||||||
|
item["used"] = int(int(item["used"]) / (1000 * 1000))
|
||||||
|
|
||||||
|
return ssd_list, hdd_list
|
|
@ -3,9 +3,10 @@
|
||||||
# Author: Cemre ALPSOY <cemre.alpsoy@agem.com.tr>
|
# Author: Cemre ALPSOY <cemre.alpsoy@agem.com.tr>
|
||||||
# Author: Emre Akkaya <emre.akkaya@agem.com.tr>
|
# Author: Emre Akkaya <emre.akkaya@agem.com.tr>
|
||||||
|
|
||||||
|
from psutil import disk_io_counters
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
import json
|
import json
|
||||||
|
from base.system.disk_info import DiskInfo
|
||||||
|
|
||||||
class ResourceUsage(AbstractPlugin):
|
class ResourceUsage(AbstractPlugin):
|
||||||
def __init__(self, data, context):
|
def __init__(self, data, context):
|
||||||
|
@ -19,10 +20,14 @@ class ResourceUsage(AbstractPlugin):
|
||||||
try:
|
try:
|
||||||
device = ""
|
device = ""
|
||||||
self.logger.debug("Gathering resource usage for disk, memory and CPU.")
|
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():
|
for part in self.Hardware.Disk.partitions():
|
||||||
if len(device) != 0:
|
if len(device) != 0:
|
||||||
device += ", "
|
device += ", "
|
||||||
device = device + part.device
|
device = device + part.device
|
||||||
|
|
||||||
data = {'System': self.Os.name(), 'Release': self.Os.kernel_release(),
|
data = {'System': self.Os.name(), 'Release': self.Os.kernel_release(),
|
||||||
'Version': self.Os.distribution_version(), 'Machine': self.Os.architecture(),
|
'Version': self.Os.distribution_version(), 'Machine': self.Os.architecture(),
|
||||||
'CPU Physical Core Count': self.Hardware.Cpu.physical_core_count(),
|
'CPU Physical Core Count': self.Hardware.Cpu.physical_core_count(),
|
||||||
|
@ -36,6 +41,13 @@ class ResourceUsage(AbstractPlugin):
|
||||||
'CPU Actual Hz': self.Hardware.Cpu.hz_actual(),
|
'CPU Actual Hz': self.Hardware.Cpu.hz_actual(),
|
||||||
'CPU Advertised Hz': self.Hardware.Cpu.hz_advertised()
|
'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.logger.debug("Resource usage info gathered.")
|
||||||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||||||
message='Anlık kaynak kullanım bilgisi başarıyla toplandı.',
|
message='Anlık kaynak kullanım bilgisi başarıyla toplandı.',
|
||||||
|
|
Loading…
Reference in a new issue