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:

aws:

  • 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'

azure:

  • QUEUE_TIME_TRACKER_AZURE_REGION = 'eastus'
  • QUEUE_TIME_TRACKER_AZURE_SUBSCRIPTION_ID = '*****'
  • QUEUE_TIME_TRACKER_AZURE_RESOURCE_GROUP_NAME = 'example_group'
  • QUEUE_TIME_TRACKER_AZURE_PROVIDER_NAME = 'Microsoft.ContainerService'
  • QUEUE_TIME_TRACKER_AZURE_RESOURCE_TYPE = 'managedClusters'
  • QUEUE_TIME_TRACKER_AZURE_RESOURCE_ID = 'example-k8s-cluster'
  1. Wrap wsgi application with time tracker: aws:
from request_time_tracker.wsgi_django.cloudwatch import CloudWatchQueueTimeTracker

application = get_wsgi_application()

application = CloudWatchQueueTimeTracker(application)

azure:

from request_time_tracker.wsgi_django.azure import AzureMonitoringQueueTimeTracker

application = get_wsgi_application()

application = AzureMonitoringQueueTimeTracker(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”: “*”
        }
    ]
}

Azure

role definition: Monitoring Metrics Publisher https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#monitoring-metrics-publisher

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.17a4.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

request_time_tracker-0.0.17a4-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file request-time-tracker-0.0.17a4.tar.gz.

File metadata

File hashes

Hashes for request-time-tracker-0.0.17a4.tar.gz
Algorithm Hash digest
SHA256 a386b1b95f380862952084d163513b1ae79739b625ff7b20b676794f7a5377fd
MD5 e62757991bf2a9a387ac434d8370bd8b
BLAKE2b-256 8ee79cbc6a5f5c718e9a6da39f0f382ca33c1f4d307e6fe109c5ef96c7ee975b

See more details on using hashes here.

File details

Details for the file request_time_tracker-0.0.17a4-py3-none-any.whl.

File metadata

File hashes

Hashes for request_time_tracker-0.0.17a4-py3-none-any.whl
Algorithm Hash digest
SHA256 ee496f154e325bd9b28e4e2e095c121e5a24f911aefa1c2f64abdb13402a76bc
MD5 5e2841dacec60e506b28e1b8140c3d15
BLAKE2b-256 b9be9a5054ac2a6b257479272ee7b7f7d085f215675efc842a001ad559ba5c16

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