Added pastafariagent
This commit is contained in:
parent
b1698487ca
commit
f08c99800d
3 changed files with 201 additions and 92 deletions
102
pastafaristats/pastafariagent.py
Normal file
102
pastafaristats/pastafariagent.py
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtCore import *
|
||||
from pastafaristats import send_info_daemon
|
||||
from time import sleep
|
||||
import os
|
||||
import psutil
|
||||
|
||||
def quit_app():
|
||||
print('Quitting Application...')
|
||||
#print(QThreadPool.globalInstance().activeThreadCount())
|
||||
#QThreadPool.globalInstance().exit()
|
||||
"""
|
||||
thread=QThread.currentThread()
|
||||
print(thread)
|
||||
thread.quit()
|
||||
"""
|
||||
#QThreadPool.globalInstance().tryTake(p)
|
||||
app.quit()
|
||||
|
||||
# Get pid
|
||||
|
||||
pid=os.getpid()
|
||||
|
||||
p=psutil.Process(pid)
|
||||
|
||||
p.terminate()
|
||||
|
||||
exit(0)
|
||||
|
||||
# Killing using pid
|
||||
|
||||
#p.stop()
|
||||
|
||||
def send_data():
|
||||
print('Init daemon...')
|
||||
while True:
|
||||
|
||||
send_info_daemon.run()
|
||||
|
||||
sleep(120)
|
||||
|
||||
|
||||
class ProcessRunnable(QRunnable):
|
||||
|
||||
def __init__(self, target, args):
|
||||
QRunnable.__init__(self)
|
||||
#self.setAutoDelete(True)
|
||||
#self.waitForDone(100)
|
||||
self.t = target
|
||||
self.args = args
|
||||
|
||||
def run(self):
|
||||
self.t(*self.args)
|
||||
|
||||
def start(self):
|
||||
#QThreadPool.globalInstance().waitForDone(100)
|
||||
QThreadPool.globalInstance().start(self)
|
||||
"""
|
||||
def stop(self):
|
||||
print('Stopping daemon...')
|
||||
del self.t
|
||||
"""
|
||||
|
||||
app = QApplication([])
|
||||
app.setQuitOnLastWindowClosed(False)
|
||||
|
||||
# Adding an icon
|
||||
icon = QIcon("icon.png")
|
||||
|
||||
# Adding item on the menu bar
|
||||
tray = QSystemTrayIcon()
|
||||
tray.setIcon(icon)
|
||||
tray.setVisible(True)
|
||||
|
||||
# Creating the options
|
||||
|
||||
menu = QMenu()
|
||||
|
||||
option1 = QAction("Pastafari monitoring")
|
||||
menu.addAction(option1)
|
||||
"""
|
||||
option2 = QAction("GFG")
|
||||
menu.addAction(option2)
|
||||
"""
|
||||
|
||||
# To quit the app
|
||||
quit = QAction("Quit")
|
||||
quit.triggered.connect(quit_app)
|
||||
menu.addAction(quit)
|
||||
|
||||
# Adding options to the System Tray
|
||||
tray.setContextMenu(menu)
|
||||
|
||||
# Begin background process
|
||||
|
||||
p = ProcessRunnable(target=send_data, args=())
|
||||
p.start()
|
||||
|
||||
# Begin tray loop
|
||||
|
||||
app.exec_()
|
||||
|
|
@ -16,13 +16,7 @@ import signal
|
|||
|
||||
# Get config from /etc/pastafari or ~/.config/pastafari
|
||||
|
||||
def catch_signal(sig, frame):
|
||||
print('Exiting...')
|
||||
exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, catch_signal)
|
||||
|
||||
def start():
|
||||
# Load configuration
|
||||
|
||||
yes_config=False
|
||||
|
||||
|
|
@ -57,7 +51,7 @@ def start():
|
|||
|
||||
url=config['DEFAULT']['url_server']
|
||||
|
||||
while True:
|
||||
def run():
|
||||
|
||||
network_info=psutil.net_io_counters(pernic=False)
|
||||
|
||||
|
|
@ -65,6 +59,8 @@ def start():
|
|||
|
||||
cpu_idle=psutil.cpu_percent(interval=1)
|
||||
|
||||
cpus_idle=psutil.cpu_percent(interval=1, percpu=True)
|
||||
|
||||
cpu_number=psutil.cpu_count()
|
||||
|
||||
disk_info=psutil.disk_partitions()
|
||||
|
|
@ -107,9 +103,20 @@ def start():
|
|||
|
||||
print('Cannot connect to data server -> '+str(e))
|
||||
|
||||
def start():
|
||||
|
||||
while True:
|
||||
|
||||
run()
|
||||
|
||||
sleep(120)
|
||||
|
||||
def catch_signal(sig, frame):
|
||||
print('Exiting...')
|
||||
exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, catch_signal)
|
||||
|
||||
if __name__=='__main__':
|
||||
|
||||
start()
|
||||
|
|
|
|||
8
setup.py
8
setup.py
|
|
@ -14,13 +14,13 @@ if sys.version_info < (3, 5):
|
|||
|
||||
setup(name='pastafaristats',
|
||||
version='1.0.0',
|
||||
description='Simple scripts for send basic data of a server how complement to other stats solutions more comples.',
|
||||
description='Simple scripts for send basic data of a server how complement to other stats solutions more complex.',
|
||||
author='Antonio de la Rosa Caballero',
|
||||
author_email='antonio.delarosa@coesinfo.com',
|
||||
url='https://bitbucket.org/paramecio/pastafaristats/',
|
||||
packages=['pastafaristats'],
|
||||
include_package_data=True,
|
||||
install_requires=['psutil'],
|
||||
install_requires=['psutil', 'pyqt5'],
|
||||
entry_points={'console_scripts': [
|
||||
'pastafaristats = pastafaristats.send_info_daemon:start',
|
||||
]},
|
||||
|
|
@ -31,9 +31,9 @@ setup(name='pastafaristats',
|
|||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: GPLV3 License',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Programming Language :: Python :: 3.7',
|
||||
'Programming Language :: Python :: 3.8'
|
||||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.9'
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue