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
-
Add header with request timestamp.
nginx:
proxy_set_header X-RequestTime $msec;
-
Read header value & send metric value
Django application
- 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'
- 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
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file request-time-tracker-0.0.17a2.tar.gz
.
File metadata
- Download URL: request-time-tracker-0.0.17a2.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 515dfe0cae5969de3ca2ef98a3ec25720e871d1b157901775d76b7f4629d12ae |
|
MD5 | ebfa9b21471bc3a5b9675d17b1b7456a |
|
BLAKE2b-256 | 9144ecf4addcb4caa6788fc9319c79d1d1edd84a8781f51027235b98d656e96c |
File details
Details for the file request_time_tracker-0.0.17a2-py3-none-any.whl
.
File metadata
- Download URL: request_time_tracker-0.0.17a2-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 002bf47a3b1ebc49e7e0081b6a645d501410bf89655f53610731e7fa8b3c0cb6 |
|
MD5 | 9358e1b08531bc05097d3ba16cc28561 |
|
BLAKE2b-256 | e94c5a8a91f0493b6837f357c1d7f5160a24487b347e325b5c4022be2e00bc8d |