From d9cb621811c2f6750b130f8c2432ca161ec96424 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 15 Aug 2021 00:25:22 +0200 Subject: [PATCH 01/10] Fix in send_info_daemon --- pastafaristats/send_info_daemon.py | 25 ++++++++++++++++++++++++- pastafaristats/utils/test.py | 6 ++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pastafaristats/utils/test.py diff --git a/pastafaristats/send_info_daemon.py b/pastafaristats/send_info_daemon.py index ef2310d..ca147be 100644 --- a/pastafaristats/send_info_daemon.py +++ b/pastafaristats/send_info_daemon.py @@ -17,6 +17,7 @@ import argparse import datetime import sched, time +from importlib import import_module #url="http://url/to/info" @@ -25,6 +26,8 @@ user_home=str(Path.home()) hostname=getfqdn() +modules_imported={} + def load_config(): yes_config=False @@ -74,6 +77,21 @@ def load_config(): if 'group' in config['DEFAULT']: group=config['DEFAULT']['group'] + + modules={} + + if 'modules' in config['DEFAULT']: + arr_modules=config['DEFAULT']['modules'].split(',') + + #load modules + + for module in arr_modules: + + if not module in modules_imported: + + modules_imported[module]=import_module(module) + + return url, group @@ -103,7 +121,12 @@ def run(url, group=''): mem_info=psutil.virtual_memory() - json_info=json.dumps({'net_info': network_info, 'cpu_idle': cpu_idle, 'cpus_idle': cpus_idle, 'cpu_number': cpu_number, 'disks_info': partitions, 'mem_info': mem_info, 'hostname': hostname, 'group': group}) + obj_stats={'net_info': network_info, 'cpu_idle': cpu_idle, 'cpus_idle': cpus_idle, 'cpu_number': cpu_number, 'disks_info': partitions, 'mem_info': mem_info, 'hostname': hostname, 'group': group} + + for module in modules_imported.values(): + obj_stats=module.stat(obj_stats) + + json_info=json.dumps(obj_stats) data = urllib.parse.urlencode({'data_json': json_info}) diff --git a/pastafaristats/utils/test.py b/pastafaristats/utils/test.py new file mode 100644 index 0000000..f7bc77e --- /dev/null +++ b/pastafaristats/utils/test.py @@ -0,0 +1,6 @@ + +def stat(obj_stats): + + obj_stats['test_data']={'pos': 0} + + return obj_stats From b4f05f7578dbadf13a3a38437c535d96ac7e9585 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 31 Aug 2021 16:19:39 +0200 Subject: [PATCH 02/10] Added apache plugin --- pastafaristats/send_info_daemon.py | 2 ++ pastafaristats/utils/apache.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pastafaristats/utils/apache.py diff --git a/pastafaristats/send_info_daemon.py b/pastafaristats/send_info_daemon.py index ca147be..e1dad49 100644 --- a/pastafaristats/send_info_daemon.py +++ b/pastafaristats/send_info_daemon.py @@ -190,6 +190,8 @@ def start(): #Wait seconds to + print('Syncing time collection...') + while True: sleep(2) diff --git a/pastafaristats/utils/apache.py b/pastafaristats/utils/apache.py new file mode 100644 index 0000000..e82f441 --- /dev/null +++ b/pastafaristats/utils/apache.py @@ -0,0 +1,30 @@ +import requests + +def stat(obj_stats): + + #new_obj_stats['apache_data']={'status': 1} + + url='http://127.0.0.1/server-status?auto' + + try: + + r=requests.get(url) + + data=r.text.split("\n") + + final_data={v.split(':')[0].strip():v.split(':')[1].strip() for v in data if v.find(':')!=-1} + + final_data['status']=1 + + obj_stats['apache_data']=final_data + + except: + obj_stats['apache_data']['status']=0 + + return obj_stats + +if __name__=='__main__': + + print(stat({})) + + From aacfa5052b885ce9daa305b07af3115d06defae1 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 31 Aug 2021 23:44:30 +0200 Subject: [PATCH 03/10] Fix in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e8618cf..95fad22 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ if sys.version_info < (3, 5): # If you install passlib and bcrypt, the password system will use bcrypt by default, if not, will use native crypt libc setup(name='pastafaristats', - version='1.0.0', + version='1.0.1', 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', From 8a0016756038745ee7fd09c4ecec5c3f0cbd7dbd Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 13 Nov 2021 17:14:43 +0100 Subject: [PATCH 04/10] Fixes in README --- README.md | 19 +++++++++++++++++++ pastafaristats/utils/__init__.py | 0 2 files changed, 19 insertions(+) create mode 100644 pastafaristats/utils/__init__.py diff --git a/README.md b/README.md index 15e4833..d189a50 100644 --- a/README.md +++ b/README.md @@ -96,4 +96,23 @@ There other options how I/O where you can define a file log for check errors if All's done!, you can init your service with **nssm start MonitService** and let's go. +# Developing plugins. + +You can add simple python scripts how plugins for add new collections to your data. + +The python scripts need have the next structure: + +```python +def stat(obj_stats): + + obj_stats['test_data']={'pos': 0} + + return obj_stats +``` + +You define a function with name *stat* and arguments *obj_stats* + +*obj_stats* is a python object. You can add new data or manipulate original collected data for your own proposites. + + diff --git a/pastafaristats/utils/__init__.py b/pastafaristats/utils/__init__.py new file mode 100644 index 0000000..e69de29 From 1f3a8e6f83aa9414a9005b194916409299ffda41 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 13 Nov 2021 19:36:36 +0100 Subject: [PATCH 05/10] Fixes in README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index d189a50..6639af0 100644 --- a/README.md +++ b/README.md @@ -114,5 +114,20 @@ You define a function with name *stat* and arguments *obj_stats* *obj_stats* is a python object. You can add new data or manipulate original collected data for your own proposites. +Next, you need modify your configuration with this line: + +``` + +``` + +``` +[DEFAULT] + +url_server=http://url_server_collect_data/ +group=server-group +modules=path.to.script, path.to.script2 +``` + +"path.to.script" is the python script path for import it into pastafaristats. You can use many scripts, but if you need many stats, is recommendable use starts collector how collectord, netdata, etc. From d1790aa0851ea36ac50587eccdf9ff66f22f70f9 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 13 Nov 2021 19:54:32 +0100 Subject: [PATCH 06/10] Fixes in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6639af0..3ace7cc 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ def stat(obj_stats): You define a function with name *stat* and arguments *obj_stats* -*obj_stats* is a python object. You can add new data or manipulate original collected data for your own proposites. +*obj_stats* is a python object. You can add new data or manipulate original collected data for your own proposites. The function returns *obj_stats* modified. Next, you need modify your configuration with this line: From 6852885148945bd9c3ce98e107b3e7f79d4b1b8b Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 13 Nov 2021 20:34:28 +0100 Subject: [PATCH 07/10] Fixes in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ace7cc..67bc3a0 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,6 @@ group=server-group modules=path.to.script, path.to.script2 ``` -"path.to.script" is the python script path for import it into pastafaristats. You can use many scripts, but if you need many stats, is recommendable use starts collector how collectord, netdata, etc. +"path.to.script" is the python script path for import it into pastafaristats. You can use many scripts, but if you need many stats, is recommendable use stats collectors how collectd, netdata, etc. From 86b0283eec58c37e1dc4a6e3e1c176cbc59839b8 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 26 Mar 2022 11:54:11 +0100 Subject: [PATCH 08/10] Little fix in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67bc3a0..b776c8f 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ def stat(obj_stats): You define a function with name *stat* and arguments *obj_stats* -*obj_stats* is a python object. You can add new data or manipulate original collected data for your own proposites. The function returns *obj_stats* modified. +*obj_stats* is a python dictionary. You can add new data or manipulate original collected data for your own proposites. The function returns *obj_stats* modified. Next, you need modify your configuration with this line: From e4b387613ab9cfda1027e31160147da8719ccaf0 Mon Sep 17 00:00:00 2001 From: absurdo Date: Thu, 13 Apr 2023 01:28:16 +0200 Subject: [PATCH 09/10] Fixes in setup --- setup.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 95fad22..e15a1c4 100644 --- a/setup.py +++ b/setup.py @@ -5,12 +5,8 @@ import os from setuptools import setup, find_packages -if sys.version_info < (3, 5): - raise NotImplementedError("Sorry, you need at least Python 3.5 for use pastafaristats.") - -#import paramecio -# Pillow should be installed after if you need ImageField -# If you install passlib and bcrypt, the password system will use bcrypt by default, if not, will use native crypt libc +if sys.version_info < (3, 6): + raise NotImplementedError("Sorry, you need at least Python 3.6 for use pastafaristats.") setup(name='pastafaristats', version='1.0.1', @@ -18,7 +14,7 @@ setup(name='pastafaristats', author='Antonio de la Rosa Caballero', author_email='antonio.delarosa@coesinfo.com', url='https://bitbucket.org/paramecio/pastafaristats/', - packages=['pastafaristats'], + packages=['pastafaristats', 'pastafaristats.utils'], include_package_data=True, install_requires=['psutil'], entry_points={'console_scripts': [ @@ -34,6 +30,7 @@ setup(name='pastafaristats', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9' + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10' ], ) From d4597a35716a8d2a3c983b5ec6fc29d8c1f41860 Mon Sep 17 00:00:00 2001 From: absurdo Date: Thu, 13 Apr 2023 01:29:08 +0200 Subject: [PATCH 10/10] Version change --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e15a1c4..28d255e 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ if sys.version_info < (3, 6): raise NotImplementedError("Sorry, you need at least Python 3.6 for use pastafaristats.") setup(name='pastafaristats', - version='1.0.1', + version='1.0.2', 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',