Skip to main content

monitor api request count

Project description

Django-request-counter

Install this app to get django api request count

Installation

Install my-project with pip

  pip install request-counter

In settings.py add below Add the app in installed apps

INSTALLED_APPS = [
    ...
    "request_counter",
]

Add middleware

MIDDLEWARE = [
    ...
    "request_counter.middlewares.APICounterMiddleware",
]

To check using API Add

urlpartterns = [
    ...
    path("",include("request_counter.urls")),
]

Set environment variable in settings.py file

# set up redis ur;
# REDIS_URL = "redis://localhost:6379/7" # by default when not set
REDIS_URL = "<your redis url path>"

# api path that starts with that needs monitoring
RC_API_START_PATH = "/api/" # by default set "" for monitoring all path default /api/ when not set 
RC_API_START_PATH = "<your starting path>"

# database where you want to store the result after running script
# RC_DATABASE = "default" # by default it is set as default database when not set
RC_DATABASE = "<your desired database>"

# when saving on 1 database but have many environment
RC_ENVIRONMENT = "" # add prefix on your database path to identify
RC_ENVIRONMENT = "<your environment>"

RC_REDIS_EXPIRE_SECONDS = 86400 # redis key ttl expiry seconds

You need to setup cron to periodically save the data into default database

python manage.py store_api_count

Now make api request with admin user

curl --location '<base-url>/api-count/' \
--header '<your authentication header>'

curl --location '<base-url>/api-count/redis' \
--header '<your authentication header>'

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

request_counter-1.6.0-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

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