Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dmuhs/falcon-stats
A falcon middleware for gathering request-response statistics
https://github.com/dmuhs/falcon-stats
api falcon falcon-stats middleware mysql rest rest-api statistics
Last synced: 5 days ago
JSON representation
A falcon middleware for gathering request-response statistics
- Host: GitHub
- URL: https://github.com/dmuhs/falcon-stats
- Owner: dmuhs
- License: mit
- Created: 2017-07-10T17:18:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T19:43:32.000Z (6 months ago)
- Last Synced: 2024-10-24T07:32:14.306Z (13 days ago)
- Topics: api, falcon, falcon-stats, middleware, mysql, rest, rest-api, statistics
- Language: Python
- Homepage:
- Size: 30.3 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Falcon Stats
[![Build Status](https://travis-ci.org/dmuhs/falcon-stats.svg?branch=master)](https://travis-ci.org/dmuhs/falcon-stats)
[![PyPI](https://img.shields.io/pypi/status/falcon-stats.svg)](https://pypi.python.org/pypi/falcon-stats)
[![PyPI](https://img.shields.io/pypi/v/falcon-stats.svg)](https://pypi.python.org/pypi/falcon-stats)
[![PyPI](https://img.shields.io/pypi/format/falcon-stats.svg)](https://pypi.python.org/pypi/falcon-stats)`falcon-stats` is a simple usage statistics middleware for the [Falcon REST framework](https://falconframework.org/). It should primarily enable later analysis that separately gets relevant data from the DB.
## Data Collection
*Falcon Stats* gathers data on incoming requests and their processed responses. Currently the following features are saved:- Response Timestamp
- Processing Time between Request and Response
- Request Method
- User Agent
- Request URI (domain, endpoint and query string)
- Remote IP (closest to the server)
- Request Content-Type
- Response Status
- Request Content LengthNote that logging and database access add overhead to the processing time. Furthermore it will add a few milliseconds on every response.
## Installation
... is as easy as```
pip install falcon-stats
```Installation assumes you have the packages found in *requirements.txt* installed. Please note the development build of SQLAlchemy that is pulled from the official git repository.
## Usage
In your main falcon file import the `FalconStatsMiddleware` and add it to the middleware list of your API instance. That's it.```python
from falconstats import FalconStatsMiddleware
...
fsm = FalconStatsMiddleware(
db_user="root",
db_pass="my-secret-pw",
db_addr="localhost:3306",
db_name="stats"
)
app = falcon.API(middleware=[fsm])
```This will connect to the given MySQL database and start to add request-response data. For now only MySQL is supported - *PRs welcome*!
## Compatibility
The middleware is used with Python 3.5 and 3.6. I don't plan on supporting Python 2.7 but it still might work.