cloudwatch-metrics-client
Python CloudWatch metrics Client library utilising asyncio (along with sync variant)
This is yet another Python CloudWatch client. While there are alternatives, they are either not supporting asyncio or not actively maintained.
https://github.com/awslabs/cloudwatch-fluent-metrics
https://github.com/peterdemin/awsme
The client collects whatever metrics you feed it with and reports to CloudWatch regularly, though you can use it for ad-hoc reporting as well
NOTE: aioboto3 is not in the requirements, in case you only need sync version. If running under Python 3.6, you'll need async_generator>=1.10 as well
Usage:
import asyncio
from cloudwatch_metrics_client.aiocloudwatch import CloudWatchAsyncMetrics, CloudWatchAsyncMetricReporter
async def setup():
reporter = CloudWatchAsyncMetricReporter(report_interval=REPORT INTERVAL) # seconds
CloudWatchAsyncMetrics.with_namespace('<YOUR NAMESPACE').with_reporter(reporter)
# .with_client(aioboto3_cloudwatch_client) is you're not happy with default client
await reporter.run()
@CloudWatchAsyncMetrics.monitored_task
async def process_request(request):
# processing logic...
#
# request_type = ...
# request_specific_data =
# Set details on monitored call
CloudWatchAsyncMetrics\
.with_monitored_dimension('TypeOfRequest', request_type)\
.with_monitored_dimension('SpecificAttribute', request_specific_data)
# Put particular metric
await CloudWatchAsyncMetrics.put_metric(
MetricName='particular-metric-name',
Unit='Count',
Dimensions={'Kind': 'metric-kind', 'Sort': 'metric-sort'},
Value=value
)
# Record statistical value
await CloudWatchAsyncMetrics.put_statistic(
MetricName='particular-metric-name',
Unit='Count',
Dimensions={'Kind': 'metric-kind', 'Sort': 'metric-sort'},
Value=value
# Elapsed time will be recorded
Elapsed time of each call of process_request coroutine will be recorded in internal data structure and aggregated
statistics will be regularly sent to CloudWatch.
Individual metrics could be collected with put_metric call - they too would be stored for a while and then sent
to CloudWatch. put_metric keeps each unique value and sends list of them along with number of occurrencies of each
value, put_statistics only sends aggregated data over a bunch of metrics - Sum, SampleCount, Min and Max
(See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html#CloudWatch.Client.put_metric_data for details)
Reporter has async flush method for flushing metric data still not sent to CloudWatch. If regular reporting is not
needed, just don't call run coro and instead call flush when it is time to report metrics.
Sync version works in the very same way, it utilises separate thread for reporting.
from cloudwatch_metrics_client.cloudwatch import CloudWatchSyncMetrics, CloudWatchSyncMetricReporter
def setup():
reporter = CloudWatchSyncMetricReporter(report_interval=REPORT INTERVAL) # seconds
CloudWatchSyncMetrics.with_namespace('<YOUR NAMESPACE').with_reporter(reporter)
reporter.run()
@CloudWatchSyncMetrics.monitored_task
def process_request(request):
# Same here, but with CloudWatchSync*
Release files for cloudwatch-metrics-client 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cloudwatch-metrics-client-0.0.6.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cloudwatch_metrics_client-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / cloudwatch-metrics-client-0.0.6.tar.gz
| Download URL | cloudwatch-metrics-client-0.0.6.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f2c0eb7faea6b6e5171da6ebc23e5507ac66632dc280f7e74b01aaea078fa3b
|
|
BLAKE2b-256 checksum How to use checksums |
c84a72c04cc6fde364e101fdf7f947c95686fda5000b9822bf3b335c55ffe1b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3
|
Release files / cloudwatch_metrics_client-0.0.6-py3-none-any.whl
| Download URL | cloudwatch_metrics_client-0.0.6-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9fce839280dbf1d5a59900a33d29172f919ad38d41eda538fdfa5b0dfe842133
|
|
BLAKE2b-256 checksum How to use checksums |
cb57fa317bacacefc5e56c6ce6e1e576ce8812d6389c80042347987082900bca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3
|