collector.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/utils/logging/LogMacros.h>
23 #include <ros/ros.h>
24 #include <ros_monitoring_msgs/MetricList.h>
25 
26 #include <vector>
27 
28 using namespace Aws::Client;
29 using namespace ros_monitoring_msgs;
30 
31 
32 #define DEFAULT_INTERVAL_SEC 5
33 #define TOPIC_BUFFER_SIZE 1000
34 #define INTERVAL_PARAM_NAME "interval"
35 #define ROBOT_ID_DIMENSION "robot_id"
36 #define CATEGORY_DIMENSION "category"
37 #define HEALTH_CATEGORY "RobotHealth"
38 #define DEFAULT_ROBOT_ID "Default_Robot"
39 #define DEFAULT_NODE_NAME "health_metric_collector"
40 #define INTERVAL_PARAM_NAME "interval"
41 #define METRICS_TOPIC_NAME "metrics"
42 
43 
44 int main(int argc, char ** argv)
45 {
46  ros::init(argc, argv, DEFAULT_NODE_NAME);
47 
48  auto param_reader = std::make_shared<Ros1NodeParameterReader>();
49 
50  // get interval param
51  double interval = DEFAULT_INTERVAL_SEC;
52  param_reader->ReadParam(ParameterPath(INTERVAL_PARAM_NAME), interval);
53 
54  // get robot id
55  std::string robot_id = DEFAULT_ROBOT_ID;
56  param_reader->ReadParam(ParameterPath(ROBOT_ID_DIMENSION), robot_id);
57 
58  // advertise
59  ros::NodeHandle public_nh;
60  ros::Publisher publisher =
61  public_nh.advertise<ros_monitoring_msgs::MetricList>(METRICS_TOPIC_NAME, TOPIC_BUFFER_SIZE);
62  AWS_LOG_INFO(__func__, "Starting Health Metric Collector Node...");
63  MetricManager mg(publisher);
64  mg.AddDimension(ROBOT_ID_DIMENSION, robot_id);
66 
67  std::vector<MetricCollectorInterface *> collectors;
68  CPUMetricCollector cpu_collector(mg);
69  collectors.push_back(&cpu_collector);
70 
71  SysInfoCollector sys_collector(mg);
72  collectors.push_back(&sys_collector);
73 
74  // start metrics collection
75  CollectAndPublish f(mg, collectors);
76  ros::NodeHandle nh("~");
77  ros::Timer timer = nh.createTimer(ros::Duration(interval), f);
78 
79  ros::spin();
80  AWS_LOG_INFO(__func__, "Shutting down Health Metric Collector Node...");
81  return 0;
82 }
#define ROBOT_ID_DIMENSION
Definition: collector.cpp:35
f
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define DEFAULT_ROBOT_ID
Definition: collector.cpp:38
#define DEFAULT_NODE_NAME
Definition: collector.cpp:39
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
#define TOPIC_BUFFER_SIZE
Definition: collector.cpp:33
#define HEALTH_CATEGORY
Definition: collector.cpp:37
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
virtual void AddDimension(const std::string &name, const std::string &value) overridefinal
add global dimension (applies to all metrics).
#define INTERVAL_PARAM_NAME
Definition: collector.cpp:40
collects metrics from sysinfo.
#define DEFAULT_INTERVAL_SEC
Definition: collector.cpp:32
activates collectors and then publishes metrics.
int main(int argc, char **argv)
Definition: collector.cpp:44
Create, aggregate and publish metrics to ros topic.
#define CATEGORY_DIMENSION
Definition: collector.cpp:36
#define METRICS_TOPIC_NAME
Definition: collector.cpp:41


health_metric_collector
Author(s): AWS RoboMaker
autogenerated on Fri Mar 5 2021 03:32:41