metric_publisher.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #include <aws/core/Aws.h>
17 #include <aws/monitoring/CloudWatchClient.h>
18 #include <aws/monitoring/model/PutMetricDataRequest.h>
19 
21 
24 
25 #include <memory>
26 
29 
30 
31 namespace Aws {
32 namespace CloudWatchMetrics {
33 
35  const std::string & metrics_namespace,
36  const Aws::Client::ClientConfiguration & client_config)
37 {
38  this->metrics_namespace_ = metrics_namespace;
39  this->client_config_ = client_config;
40 }
41 
42 MetricPublisher::MetricPublisher(const std::string & metrics_namespace,
43  std::shared_ptr<Utils::CloudWatchMetricsFacade> cloudwatch_metrics_facade)
44 {
45  this->metrics_namespace_ = metrics_namespace;
46  this->cloudwatch_metrics_facade_ = std::move(cloudwatch_metrics_facade);
47 }
48 
50 
51  if (!this->cloudwatch_metrics_facade_) {
52  this->cloudwatch_metrics_facade_ = std::make_shared<CloudWatchMetricsFacade>(this->client_config_);
53  }
54  return Service::start();
55 }
56 
58  return true;
59 }
60 
62 {
63 
64  if (data.empty()) {
66  }
67 
68  CloudWatchMetricsStatus status = this->cloudwatch_metrics_facade_->SendMetricsToCloudWatch(this->metrics_namespace_, data);
69  switch(status) {
70  case CloudWatchMetricsStatus::SUCCESS:
71  return Aws::DataFlow::UploadStatus::SUCCESS;
72  case CloudWatchMetricsStatus::INVALID_DATA:
73  return Aws::DataFlow::UploadStatus::INVALID_DATA;
74  default:
75  return Aws::DataFlow::UploadStatus::FAIL;
76  }
77 }
78 
79 } // namespace CloudWatchMetrics
80 } // namespace Aws
std::list< Aws::CloudWatch::Model::MetricDatum > MetricDatumCollection
Definition: definitions.h:23
std::shared_ptr< Aws::CloudWatchMetrics::Utils::CloudWatchMetricsFacade > cloudwatch_metrics_facade_
This class is a simple Facade over the CloudWatch client. This class is a very small abstraction over...
MetricPublisher(const std::string &metrics_namespace, const Aws::Client::ClientConfiguration &client_config)
Aws::Client::ClientConfiguration client_config_
Aws::DataFlow::UploadStatus publishData(MetricDatumCollection &data) override
virtual bool start()


cloudwatch_metrics_common
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:25