16 #include <aws/core/Aws.h> 17 #include <aws/core/utils/logging/LogMacros.h> 19 #include <aws/monitoring/model/MetricDatum.h> 20 #include <aws/monitoring/model/PutMetricDataRequest.h> 30 namespace CloudWatchMetrics {
34 #define MAX_METRIC_DATUMS_PER_REQUEST 20 38 this->
cw_client_ = std::make_shared<Aws::CloudWatch::CloudWatchClient>(client_config);
47 const Aws::CloudWatch::Model::PutMetricDataRequest & request)
51 auto response = this->
cw_client_->PutMetricData(request);
53 if (!response.IsSuccess()) {
55 AWS_LOGSTREAM_DEBUG( __func__,
"CloudWatchMetricsFacade: failed to send metric request: " 56 << static_cast<int>(response.GetError().GetErrorType()));
58 switch(response.GetError().GetErrorType()) {
60 case Aws::CloudWatch::CloudWatchErrors::NETWORK_CONNECTION:
63 case Aws::CloudWatch::CloudWatchErrors::INVALID_PARAMETER_VALUE:
64 case Aws::CloudWatch::CloudWatchErrors::INVALID_PARAMETER_COMBINATION:
65 case Aws::CloudWatch::CloudWatchErrors::MISSING_PARAMETER:
79 Aws::CloudWatch::Model::PutMetricDataRequest request;
80 Aws::Vector<Aws::CloudWatch::Model::MetricDatum> datums;
82 if (metrics.empty()) {
83 AWS_LOGSTREAM_DEBUG( __func__,
"CloudWatchMetricsFacade: no metrics to send");
87 request.SetNamespace(metric_namespace.c_str());
90 for (
auto & metric : metrics) {
91 datums.push_back(metric);
94 request.SetMetricData(datums);
105 if (datums.size() > 0) {
106 request.SetMetricData(datums);
std::list< Aws::CloudWatch::Model::MetricDatum > MetricDatumCollection
CloudWatchMetricsFacade()=default
CloudWatchMetricsStatus SendMetricsRequest(const Aws::CloudWatch::Model::PutMetricDataRequest &request)
#define MAX_METRIC_DATUMS_PER_REQUEST
std::shared_ptr< Aws::CloudWatch::CloudWatchClient > cw_client_
virtual CloudWatchMetricsStatus SendMetricsToCloudWatch(const std::string &metric_namespace, MetricDatumCollection &metrics)
Sends a list of metrics to CloudWatch Used to send a list of metrics to CloudWatch.