Added first files

This commit is contained in:
Antonio de la Rosa 2020-06-28 21:25:47 +02:00
commit ba591d1810
5 changed files with 255 additions and 0 deletions

104
.gitignore vendored Normal file
View file

@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
.static_storage/
.media/
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/

View file

View file

@ -0,0 +1,109 @@
#!/usr/bin/env python3
import psutil
import json
import urllib.request
import urllib.parse
import ssl
from time import sleep
import configparser
import os
from sys import exit
from pathlib import Path
#url="http://url/to/info"
# Get config from /etc/pastafari or ~/.config/pastafari
def start():
yes_config=False
user_home=str(Path.home())
config = configparser.ConfigParser()
if os.path.isfile(user_home+'/.config/pastafari/stats.cfg'):
config.read(user_home+'/.config/pastafari/stats.cfg')
yes_config=True
elif os.path.isfile('/etc/pastafari/stats.cfg'):
config.read('/etc/pastafari/stats.cfg')
yes_config=True
if not yes_config:
print("Sorry, cannot load config file")
exit(1)
if not 'DEFAULT' in config:
print("Sorry, config file need [DEFAULT] section")
exit(1)
if not 'url_server' in config['DEFAULT']:
print("Sorry, config file need url_server variable in [DEFAULT] section")
exit(1)
url=config['DEFAULT']['url_server']
while True:
network_info=psutil.net_io_counters(pernic=False)
network_devices=psutil.net_if_addrs()
cpu_idle=psutil.cpu_percent(interval=1)
cpu_number=psutil.cpu_count()
disk_info=psutil.disk_partitions()
partitions={}
for disk in disk_info:
partition=str(disk[1])
partitions[partition]=psutil.disk_usage(partition)
#print(partition+"="+str(partitions[partition]))
dev_info={}
mem_info=psutil.virtual_memory()
json_info=json.dumps({'net_info': network_info, 'cpu_idle': cpu_idle, 'cpu_number': cpu_number, 'disks_info': partitions, 'mem_info': mem_info})
data = urllib.parse.urlencode({'data_json': json_info})
data = data.encode('ascii')
try:
if url[:5]=='https':
# For nexts versions 3.5
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
content=urllib.request.urlopen(url, data, context=ctx)
else:
content=urllib.request.urlopen(url, data)
except Exception as e:
print('Cannot connect to data server -> '+str(e))
sleep(120)
if __name__=='__main__':
start()

3
setup.cfg Normal file
View file

@ -0,0 +1,3 @@
[metadata]
description-file = README.md

39
setup.py Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import sys
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
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.',
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=['psutils'],
entry_points={'console_scripts': [
'pastafaristats = pastafaristats.send_info_daemon:start',
]},
zip_safe=False,
license='GPLV3',
platforms = 'any',
classifiers=['Development Status :: 1 - Beta',
'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'
],
)