Skip to main content

Requests time tracker from being captured by proxy (e.g. nginx) till being executed by wsgi handler

Project description

#Queue time tracker Reads time when request was processed by nginx & send time spent in queue before it was handled by wsgi.
Designed mostly for autoscaling. Instance cpu is not trustworthy enough, sometimes there can be external bottlenecks, so even if instance cpu is fine, application can hang in queue between nginx(for example) and gunicorn or another wsgi processor.

##Configuration

  1. Add header with request timestamp.

    nginx:

    proxy_set_header X-RequestTime $msec;
    
  2. Read header value & send metric value

Django application

  1. Configure django settings:
    • QUEUE_TIME_TRACKER_NOTIFY_EVERY_SECONDS = 10
    • QUEUE_TIME_TRACKER_HEADER = 'HTTP_X_REQUESTTIME'
    • QUEUE_TIME_TRACKER_CACHE_NAME = 'default'
    • QUEUE_TIME_TRACKER_CACHE_KEY_PREFIX = 'foobar'
    • QUEUE_TIME_TRACKER_CLOUDWATCH_NAMESPACE = 'FooBar Web'
    • QUEUE_TIME_TRACKER_CLOUDWATCH_ACCESS_KEY = 'AK****A'
    • QUEUE_TIME_TRACKER_CLOUDWATCH_SECRET_KEY = 'so******BS'
    • QUEUE_TIME_TRACKER_CLOUDWATCH_REGION = 'us-west-1'
  2. Wrap wsgi application with time tracker:
from request_time_tracker.django_wsgi import CloudWatchQueueTimeTracker

application = get_wsgi_application()

application = CloudWatchQueueTimeTracker(application)

Non-django application

  1. Wrap wsgi application with time tracker. Example:
from functools import partial
from request_time_tracker.trackers.cache.redis import RedisCacheQueueTimeTracker
from request_time_tracker.notifiers.cloudwatch import CloudWatchNotifier

tracker = partial(
    RedisCacheQueueTimeTracker, 
    queue_time_header_name='HTTP_X_REQUESTTIME',
    redis_url='redis://localhost:6379/0',
    notifier=CloudWatchNotifier(
        namespace='FooBar Web',
        aws_access_key='AK****A',
        aws_secret_key='so******BS',
        aws_region='us-west-1',
    ),
)

wsgi_application = tracker(wsgi_application)

##Cloudwatch role policy:

{
    “Version”: “2012-10-17",
    “Statement”: [
        {
            “Sid”: “VisualEditor0”,
            “Effect”: “Allow”,
            “Action”: [“cloudwatch:PutMetricData”],
            “Resource”: “*”
        }
    ]
}

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

request-time-tracker-0.0.6.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

request_time_tracker-0.0.6-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file request-time-tracker-0.0.6.tar.gz.

File metadata

  • Download URL: request-time-tracker-0.0.6.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for request-time-tracker-0.0.6.tar.gz
Algorithm Hash digest
SHA256 cbdffb61b17f0abca2dc19a6b3a50c352f67bb3179f1dde700ca78dfed8e0ec8
MD5 0163a30178424eb43d6ace08deb0cc8d
BLAKE2b-256 552b74bf12369cc72866a94768c03c01805c700d1850abd59740a5b13d60e891

See more details on using hashes here.

File details

Details for the file request_time_tracker-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: request_time_tracker-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for request_time_tracker-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a0e0b0ebca15c1f80ba6841ba43c0a36429316d29a3850a67eb54b7687676d1e
MD5 f3ac5d39a4f79bf8443dd0a9fe6f82a0
BLAKE2b-256 145d05894587363eb409011d4c1c60f8049f3db988a623b5e3c1eff99b3b04b8

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