def run_metrics_webserver(host: str = '0.0.0.0', port: int = 5000): log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app = Flask(__name__) from appmetrics.wsgi import AppMetricsMiddleware app.wsgi_app = AppMetricsMiddleware(app.wsgi_app, "app_metrics") app.run(host, port, debug=False)
@metrics.with_histogram("factorial-latency") @metrics.with_meter("throughput") def factorial(n): f = 1 for i in xrange(2, n + 1): f *= i return jsonify(factorial=str(f)) @app.route('/is-prime/<int:n>') @metrics.with_meter("primality-tp") @metrics.with_histogram("primality-latency") @metrics.with_meter("throughput") def is_prime(n): result = True if n % 2 == 0: result = False else: for i in xrange(3, int(n**0.5) + 1, 2): if n % i == 0: result = False return jsonify(is_prime=result) if __name__ == '__main__': from appmetrics.wsgi import AppMetricsMiddleware app.wsgi_app = AppMetricsMiddleware(app.wsgi_app) app.run(threaded=True, debug=True)
def factorial(n): f = 1 for i in xrange(2, n + 1): f *= i response.content_type = "application/json" return json.dumps(dict(factorial=str(f))) @route('/is-prime/<n:int>') @metrics.with_meter("primality-tp") @metrics.with_histogram("primality-latency") @metrics.with_meter("throughput") def is_prime(n): result = True if n % 2 == 0: result = False else: for i in xrange(3, int(n**0.5) + 1, 2): if n % i == 0: result = False response.content_type = "application/json" return json.dumps(dict(is_prime=result)) if __name__ == '__main__': from appmetrics.wsgi import AppMetricsMiddleware myapp = AppMetricsMiddleware(app()) run(app=myapp, port=5000, threaded=True, debug=True)
#!/usr/bin/env python # -*- coding:utf8 -*- import os from appmetrics.wsgi import AppMetricsMiddleware from flask_scalarest import create_app from flask_scalarest.extensions.jwt import jwt here = os.path.dirname(os.path.realpath(__file__)) config_file = os.path.join(here, 'test_settings.py') application = create_app(config_file) application.wsgi_app = AppMetricsMiddleware(application.wsgi_app) jwt.init_app(application) if __name__ == '__main__': application.run()
def run_metrics_webserver(host: str = '0.0.0.0', port: int = 5000): app = Flask(__name__) from appmetrics.wsgi import AppMetricsMiddleware app.wsgi_app = AppMetricsMiddleware(app.wsgi_app, "app_metrics") app.run(host, port, debug=False)