Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Add launch file to launch system CPU and Memory collector nodes #63

Merged
merged 4 commits into from Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion system_metrics_collector/CMakeLists.txt
Expand Up @@ -54,6 +54,14 @@ add_executable(main src/system_metrics_collector/main.cpp)
target_link_libraries(main system_metrics_collector)
ament_target_dependencies(main)

add_executable(linux_cpu_collector src/system_metrics_collector/linux_cpu_collector.cpp)
target_link_libraries(linux_cpu_collector system_metrics_collector)
ament_target_dependencies(linux_cpu_collector)

add_executable(linux_memory_collector src/system_metrics_collector/linux_memory_collector.cpp)
target_link_libraries(linux_memory_collector system_metrics_collector)
ament_target_dependencies(linux_memory_collector)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(ament_cmake_gtest REQUIRED)
Expand Down Expand Up @@ -114,18 +122,31 @@ if(BUILD_TESTING)
lib/${PROJECT_NAME})
endif()

# Install launch files.
# Install launch files
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)

# Install entry points
install(TARGETS
main
DESTINATION
lib/${PROJECT_NAME}
)

install(TARGETS
linux_cpu_collector
DESTINATION
lib/${PROJECT_NAME}
)

install(TARGETS
linux_memory_collector
DESTINATION
lib/${PROJECT_NAME}
)

install(TARGETS ${PROJECT_NAME}
DESTINATION lib
)
Expand Down
Expand Up @@ -24,7 +24,12 @@ def generate_launch_description():
ld = LaunchDescription([
Node(
package='system_metrics_collector',
node_executable='main',
node_executable='linux_cpu_collector',
output='screen'),
Node(
package='system_metrics_collector',
node_executable='linux_memory_collector',
output='screen'
),
])
return ld
@@ -0,0 +1,60 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "rcutils/logging_macros.h"

#include "../../src/system_metrics_collector/linux_cpu_measurement_node.hpp"
piraka9011 marked this conversation as resolved.
Show resolved Hide resolved

namespace
{
constexpr const char kStatisticsTopicName[] = "system_metrics";
prajakta-gokhale marked this conversation as resolved.
Show resolved Hide resolved
constexpr const std::chrono::seconds kDefaultCollectPeriod{1};
constexpr const std::chrono::minutes kDefaultPublishPeriod{1};
}

prajakta-gokhale marked this conversation as resolved.
Show resolved Hide resolved
int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);

using namespace std::chrono_literals;
const auto cpu_node = std::make_shared<system_metrics_collector::LinuxCpuMeasurementNode>(
"linuxCpuCollector",
kDefaultCollectPeriod,
kStatisticsTopicName,
kDefaultPublishPeriod);

rclcpp::executors::MultiThreadedExecutor ex;
cpu_node->Start();

{
const auto r =
prajakta-gokhale marked this conversation as resolved.
Show resolved Hide resolved
rcutils_logging_set_logger_level(cpu_node->get_name(), RCUTILS_LOG_SEVERITY_DEBUG);
if (r != 0) {
RCUTILS_LOG_ERROR_NAMED("linux_cpu_main",
"Unable to set debug logging for the cpu node: %s\n",
rcutils_get_error_string().str);
}
}

ex.add_node(cpu_node);
ex.spin();

rclcpp::shutdown();
cpu_node->Stop();
return 0;
}
@@ -0,0 +1,59 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "rcutils/logging_macros.h"

#include "../../src/system_metrics_collector/linux_memory_measurement_node.hpp"

namespace
{
constexpr const char kStatisticsTopicName[] = "system_metrics";
constexpr const std::chrono::seconds kDefaultCollectPeriod{1};
constexpr const std::chrono::minutes kDefaultPublishPeriod{1};
}

prajakta-gokhale marked this conversation as resolved.
Show resolved Hide resolved
int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);

using namespace std::chrono_literals;
const auto mem_node = std::make_shared<system_metrics_collector::LinuxMemoryMeasurementNode>(
"linuxMemoryCollector",
kDefaultCollectPeriod,
kStatisticsTopicName,
kDefaultPublishPeriod);

rclcpp::executors::MultiThreadedExecutor ex;
mem_node->Start();

{
const auto r =
prajakta-gokhale marked this conversation as resolved.
Show resolved Hide resolved
rcutils_logging_set_logger_level(mem_node->get_name(), RCUTILS_LOG_SEVERITY_DEBUG);
if (r != 0) {
RCUTILS_LOG_ERROR_NAMED("linux_mem_main",
"Unable to set debug logging for the memory node: %s\n",
rcutils_get_error_string().str);
}
}

ex.add_node(mem_node);
ex.spin();

rclcpp::shutdown();
mem_node->Stop();
return 0;
}