Skip to content

Commit

Permalink
Merge pull request #373 from Qblack/feature/micro-service-support
Browse files Browse the repository at this point in the history
Feature/micro service support
  • Loading branch information
FlyingBird95 committed Apr 2, 2021
2 parents b83fb3b + e69f137 commit 309b2b4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 17 deletions.
33 changes: 20 additions & 13 deletions flask_monitoringdashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ def loc():
blueprint = Blueprint('dashboard', __name__, template_folder=loc() + 'templates')


def bind(app, schedule=True):
def bind(app, schedule=True, include_dashboard=True):
"""Binding the app to this object should happen before importing the routing-
methods below. Thus, the importing statement is part of this function.
:param app: the app for which the performance has to be tracked
:param schedule: flag telling if the background scheduler should be started
:param include_dashboard: flag telling if the views should be added or not.
"""
blueprint.name = config.blueprint_name
config.app = app
Expand All @@ -44,18 +45,19 @@ def bind(app, schedule=True):
app.secret_key = 'my-secret-key'

# Add all route-functions to the blueprint
from flask_monitoringdashboard.views import (
deployment,
custom,
endpoint,
outlier,
request,
profiler,
version,
auth,
reporting,
)
import flask_monitoringdashboard.views
if include_dashboard:
from flask_monitoringdashboard.views import (
deployment,
custom,
endpoint,
outlier,
request,
profiler,
version,
auth,
reporting,
)
import flask_monitoringdashboard.views

# Add wrappers to the endpoints that have to be monitored
from flask_monitoringdashboard.core.measurement import init_measurement
Expand All @@ -76,6 +78,11 @@ def bind(app, schedule=True):

atexit.register(flush_cache)

if not include_dashboard:
@app.teardown_request
def teardown(_):
flush_cache()


def add_graph(title, func, trigger="interval", **schedule):
"""Add a custom graph to the dashboard. You must specify the following arguments:
Expand Down
14 changes: 14 additions & 0 deletions requirements-micro.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
click
apscheduler
flask>=0.9 # for monitoring the web-service
sqlalchemy>=1.1.9 # for database support
configparser # for parsing the config-file
psutil # for logging extra CPU-info
colorhash # for hashing a string into a color
numpy # for computing median and other stats
pytz # for timezone info
tzlocal==2.0 # for figuring out the local timezone; frozen to 2.0 because 3.0 conflicts the latest version of appscheduler (as of jan.2020)

# pinning this to avoid flask pulling in a later one which breaks python3.6
jinja2==2.11.1; python_version < '3.7'
jinja2; python_version >= '3.7'
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r requirements-micro.txt
click
apscheduler
flask>=0.9 # for monitoring the web-service
Expand Down
37 changes: 33 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import json
import os
import sys

import setuptools

loc = os.path.dirname(os.path.abspath(__file__))

micro = False
if '--micro' in sys.argv:
micro = True
sys.argv.remove('--micro')
print('In micro mode')


def get_description():
with open(loc + '/docs/README.rst') as readme:
Expand All @@ -13,18 +20,40 @@ def get_description():
return info + '\n\n' + changelog.read()


with open(loc + '/requirements.txt') as f:
with open(loc + '/requirements-micro.txt') as f:
required = f.read().splitlines()
if not micro:
with open(loc + '/requirements.txt') as f:
required.extend([req for req in f.read().splitlines() if req != '-r requirements-micro.txt'])

with open('flask_monitoringdashboard/constants.json', 'r') as f:
constants = json.load(f)

if micro:
packages = setuptools.find_packages(include=[
'flask_monitoringdashboard',
'flask_monitoringdashboard.database',
'flask_monitoringdashboard.core',
'flask_monitoringdashboard.core.config',
'flask_monitoringdashboard.core.custom_graph',
'flask_monitoringdashboard.core.profiler',
'flask_monitoringdashboard.core.profiler.*',
],
exclude=['flask_monitoringdashboard.controllers.*',
'flask_monitoringdashboard.frontend.*',
'flask_monitoringdashboard.views.*',
'flask_monitoringdashboard.static.*',
'tests', 'test.*']
)
else:
packages = setuptools.find_packages()

setuptools.setup(
name="Flask-MonitoringDashboard",
name="Flask-MonitoringDashboard" if not micro else "Flask-MonitoringDashboard-Micro",
version=constants['version'],
setup_requires=['setuptools_scm'],
packages=setuptools.find_packages(),
include_package_data=True,
packages=packages,
include_package_data=not micro, # This is all the html files and things which are not needed in micro mode
platforms='Any',
zip_safe=False,
test_suite='tests.get_test_suite',
Expand Down

0 comments on commit 309b2b4

Please sign in to comment.