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

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file request_counter-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for request_counter-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2773f47ba11baba5c6d1d1c2b8107340a06e49e1f89b5a50aafa9756df29b16d
MD5 cc3770b1fde2d70e6e04c80a5666fcc2
BLAKE2b-256 d31c1df13cd8ece188715800768e70565f2a9eb8ddb6204199931bb454412765

See more details on using hashes here.

Supported by

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