Skip to main content

Flask Monitor module

Project description

Flask-monitor

Generate time of execution and send data on multi destination

  • log

  • influxdb (and so grafana)

  • rabbitmq

  • zeromq

  • statsd

Installation

pip install flask-monitor

Or

git clone https://github.com/fraoustin/flask-monitor.git
cd flask-monitor
python setup.py install

Usage

from flask import Flask, request
from flask_monitor import Monitor , ObserverLog
import logging

app = Flask(__name__)
monitor = Monitor('monitor', __name__)
app.register_blueprint(monitor)
monitor.add_observer(ObserverLog())

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.logger.setLevel(logging.INFO)
    for h in app.logger.handlers:
        h.setLevel(logging.INFO)
    app.run(port=8080)

You can add a filter of event

from flask import Flask, request
from flask_monitor import Monitor , ObserverLog

def filterExt(event):
    return event.response.status_code == 400

app = Flask(__name__)
monitor = Monitor('monitor', __name__)
app.register_blueprint(monitor)
monitor.add_observer(ObserverLog(filter=filterExt))

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(port=8080)

You can create your own observer

from flask import Flask, request
from flask_monitor import Monitor , ObserverLog

class myeventlog(ObserverMetrics):

    def __init__(self):
        ObserverMetrics.__init__(self, filter=self.filter)

    def action(self, event):
        logging.getLogger().error(event.json)

    def filter(self, event):
        return event.response.status_code != 400

app = Flask(__name__)
monitor = Monitor('monitor', __name__)
app.register_blueprint(monitor)
monitor.add_observer(myeventlog())

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(port=8080)

Influxdb

pip install influxdb

Usage

from flask_monitor.influxdb import ObserverInfluxdb
monitor.add_observer(ObserverInfluxdb(host='127.0.0.1',
                                    port=8086,
                                    user='root',
                                    password='root',
                                    db='mydb'))

RabbitMq

pip install pika

Usage

from flask_monitor.rabbitmq import ObserverRabbit
import pika

monitor.add_observer(ObserverRabbit(host='127.0.0.1',
                            credentials = pika.PlainCredentials('guest', 'guest')))

ZeroMq

pip install zmq

Usage

from flask_monitor.zeromq import ObserverZmq
import zmq

monitor.add_observer(ObserverZmq(context=zmq.Context(),
                                    addr='tcp://127.0.0.1:8080'))

Statsd

pip install statsd

Usage

from flask_monitor.statsd import ObserverStatsd
monitor.add_observer(ObserverStatsd(host='127.0.0.1', port=8125, format="{RequestUrl}"))

V. 0.2.6

  • hotfix Issue#5 manage import influxdb

V. 0.2.5

  • hotfix requirement

V. 0.2.4

  • Add ssl, verify_ssl as options for ObserverInfluxdb

V. 0.2.3

  • correction setup.py by sujaymansingh

V. 0.2.2

  • correction statd by sujaymansingh

V. 0.2.1

  • add logger debug for start end finish request

V. 0.2.0

  • change manage logger of ObserverMetrics

V. 0.1.3

  • hotfix for name pkg

V. 0.1.2

  • manage logger default

V. 0.1.1

  • manage setup.py generic

V. 0.1.0

  • init

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-monitor-0.2.6.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file flask-monitor-0.2.6.tar.gz.

File metadata

File hashes

Hashes for flask-monitor-0.2.6.tar.gz
Algorithm Hash digest
SHA256 04a91bd674f685df142d0880cec5c873ee7ec2d4b3b129eb41abaefabedc27a0
MD5 46090ef663288edcac97ab1c02725d28
BLAKE2b-256 32d816e23cd6ac4006253fe38d5ba54f8da1206cb20a96185027b71906e7510d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page