Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

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

Uploaded Source

Built Distribution

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

request_time_tracker-0.0.21a4-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: request-time-tracker-0.0.21a4.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.16

File hashes

Hashes for request-time-tracker-0.0.21a4.tar.gz
Algorithm Hash digest
SHA256 8c94769562b86f9b2390b91cd9bb279175a4f20c893ce78c46b45cb8728ae6b1
MD5 1b03d2f5c4dbbfa021e39f198c8bb63f
BLAKE2b-256 b07153a44d4fd4fcf9e65ef7aa9c706c9d9c58b8540b0ee92a78f6459b829eeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for request_time_tracker-0.0.21a4-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf83540509125c94659a898a49e1de4ce6a1da2b37a9bbb2bfa51578357bc20
MD5 d76616d1b82fbf57e8b0b0fa8992e126
BLAKE2b-256 3959f2ad7cee4249519f5d91205603b172d591ba1b1b972e9eac6745aa81090b

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