Commit c40e3336 authored by Chris Hines's avatar Chris Hines
Browse files

add setup

parent 692d69df
Pipeline #12782 failed with stages
This code queries InfluxDB and does some HTTP Gets and an SSH connection to determine the status of various bits of a cluster. It then updates a statuspage.io page
"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='statuspage_integration',
setup_requires=[],
desktop_entries={
},
version='0.0.1',
description='Query influx and other things to determine the state of a cluster. Update statuspage.io',
long_description=long_description,
# The project's main homepage.
url='https://gitlab.erc.monash.edu.au/hpc-team/statuspag_integration',
# Author details
author='Chris Hines',
author_email='help@massive.org.au',
# Choose your license
license='MIT',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',
# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: MIT License',
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
# What does your project relate to?
keywords='statuspage.io influxdb HPC',
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
# Alternatively, if you want to distribute just a my_module.py, uncomment
# this:
# py_modules=["my_module"],
# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=[
'influxdb==5.2.2',
'statuspageio',
'pyyaml',
'paramiko'
],
data_files = [],
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={
'console_scripts': ['update_status=statuspage_integration.__main__:main' ],
'gui_scripts': []
},
)
......@@ -10,7 +10,7 @@ def main():
import argparse
import yaml
parser = argparse.ArgumentParser()
parser.add_argument('--config', default='./config.yml')
parser.add_argument('--config', default='./config_test.yml')
args = parser.parse_args()
......@@ -28,6 +28,8 @@ def main():
spClient = statuspagewrapper.Client.configure(config['statuspageio'])
spcomponents = {}
for c in spClient.components.list():
spcomponents[c['name']] = c
for name,c in config['components'].items():
msgs = []
......
......@@ -28,6 +28,11 @@ class NFSFS():
self.database = database
self.fsname = kwargs['name']
self.export = kwargs['export']
if 'time' in kwargs:
import dateutil
self.time = dateutil.parser.parse(kwargs['time'])
else:
self.time = None
self.nfs = [InfluxDBRate(client = influxClient,
database = self.database,
tags = {'export': self.export},
......@@ -39,7 +44,15 @@ class NFSFS():
field = 'vfswritepage',
measurement = 'mountstats')]
def test(self):
if sum(map(lambda x: x.ratequery(), self.nfs)) > 0:
if self.time is None:
import datetime
time = datetime.datetime.now()
else:
time=self.time
print("testing NFS {} {}".format(self.time, self.nfs[0].ratequery(t1=None,t2=time)))
print("testing NFS {} {}".format(self.time, self.nfs[1].ratequery(t1=None,t2=time)))
if sum(map(lambda x: x.ratequery(t1=None,t2=time), self.nfs)) > 0:
msgstring = """The {fsname} filesystem is OK""".format(fsname=self.fsname)
return {'status': Status.operational, 'msg': msgstring}
msgstring = """The {fsname} filesystem is down""".format(fsname = self.fsname)
......@@ -70,6 +83,11 @@ class LustreFS():
self.componentid = "Not Implemented"
influxClient = influxClient
self.fsname = kwargs['name']
if 'time' in kwargs:
import dateutil
self.time = dateutil.parser.parse(kwargs['time'])
else:
self.time = None
mdt0=kwargs['mdt0']
mdt1=kwargs['mdt1']
self.mdt0 = [ InfluxDBRate(client = influxClient,
......@@ -78,40 +96,40 @@ class LustreFS():
field = 'open',
measurement = 'lustre2'),
InfluxDBRate(client = influxClient,
database = self.database,
tags = {'name': mdt0},
field = 'close',
measurement = 'lustre2'),
InfluxDBRate(client = influxClient,
database = self.database,
tags = {'name': mdt0},
field = 'statfs',
measurement = 'lustre2')]
self.mdt1 = [ InfluxDBRate(client = influxClient,
database = self.database,
tags = {'name': mdt1},
field = 'open',
measurement = 'lustre2'),
InfluxDBRate(client = influxClient,
database = self.database,
tags = {'name': mdt1},
field = 'close',
measurement = 'lustre2'),
InfluxDBRate(client = influxClient,
database = self.database,
tags = {'name': mdt1},
field = 'statfs',
measurement = 'lustre2')]
def test(self):
if sum(map(lambda x: x.ratequery(), self.mdt0)) > 0:
if self.time is None:
import datetime
time = datetime.datetime.now()
else:
time=self.time
if sum(map(lambda x: x.ratequery(t1=None,t2=time), self.mdt0)) > 0:
msgstring = """The {fsname} filesystem is OK""".format(fsname=self.fsname)
return {'status': Status.operational, 'msg': msgstring}
if sum(map(lambda x: x.ratequery(), self.mdt1)) > 0:
if sum(map(lambda x: x.ratequery(t1=None,t2=time), self.mdt1)) > 0:
msgstring = """The {fsname} is partially degraded""".format(fsname = self.fsname)
return {'status': Status.partial_outage, 'msg': msgstring}
msgstring = """The {fsname} filesystem is down""".format(fsname = self.fsname)
......
......@@ -60,7 +60,7 @@ class InfluxDBRate():
Compare the value of a specific measurment across the entire cluster at to different points in time
"""
if t1 is None:
t1 = t2 - datetime.timedelta(minutes=30)
t1 = t2 - datetime.timedelta(minutes=5)
a1 = self.sumlastquery(t1)
a2 = self.sumlastquery(t2)
return (a2-a1)/(t2-t1).total_seconds()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment