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

Add configurable launch parameters #80

Merged
merged 3 commits into from Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions system_metrics_collector/CMakeLists.txt
Expand Up @@ -171,8 +171,10 @@ install(TARGETS
lib/${PROJECT_NAME}
)

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

ament_export_libraries(${PROJECT_NAME})
Expand Down
67 changes: 59 additions & 8 deletions system_metrics_collector/launch/system_cpu_and_memory.launch.py
Expand Up @@ -12,24 +12,75 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Launch system CPU and system memory metrics collector nodes."""


from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

# Launch argument names
CPU_NODE_NAME = 'linux_cpu_collector_node_name'
MEMORY_NODE_NAME = 'linux_memory_collector_node_name'
MEASUREMENT_PERIOD = 'measurement_period'
PUBLISH_PERIOD = 'publish_period'
PUBLISH_TOPIC = 'publish_topic'

# Default argument values
default_cpu_node_name = 'linux_cpu_collector'
default_memory_node_name = 'linux_memory_collector'
default_measurement_period_in_ms = '1000'
default_publish_period_in_ms = '60000'
default_publish_topic = 'system_metrics'


def generate_launch_description():
"""Launch system CPU and system memory metrics collector nodes."""
ld = LaunchDescription()

ld.add_action(DeclareLaunchArgument(
CPU_NODE_NAME,
default_value=default_cpu_node_name,
description='A custom name for the node that collects the total CPU usage'
' on a Linux system'))
ld.add_action(DeclareLaunchArgument(
MEMORY_NODE_NAME,
default_value=default_memory_node_name,
description='A custom name for the node that collects the total memory usage'
' on a Linux system'))
ld.add_action(DeclareLaunchArgument(
MEASUREMENT_PERIOD,
default_value=default_measurement_period_in_ms,
description='The period (in ms) between each subsequent metrics measurement made'
' by the collector nodes'))
ld.add_action(DeclareLaunchArgument(
PUBLISH_PERIOD,
default_value=default_publish_period_in_ms,
description='The period (in ms) between each subsequent metrics message published'
' by the collector nodes'))
ld.add_action(DeclareLaunchArgument(
PUBLISH_TOPIC,
default_value=default_publish_topic,
description='The name of the topic to which the collector nodes should publish'))

node_parameters = [
{MEASUREMENT_PERIOD: LaunchConfiguration(MEASUREMENT_PERIOD)},
{PUBLISH_PERIOD: LaunchConfiguration(PUBLISH_PERIOD)}]

"""Run system CPU and memory collector nodes using launch."""
ld = LaunchDescription([
ld.add_action(
Node(
package='system_metrics_collector',
node_executable='linux_cpu_collector',
output='screen'),
node_name=LaunchConfiguration(CPU_NODE_NAME),
parameters=node_parameters,
remappings=[('system_metrics', LaunchConfiguration(PUBLISH_TOPIC))],
output='screen'))
ld.add_action(
Node(
package='system_metrics_collector',
node_executable='linux_memory_collector',
output='screen'
),
])
node_name=LaunchConfiguration(MEMORY_NODE_NAME),
parameters=node_parameters,
remappings=[('system_metrics', LaunchConfiguration(PUBLISH_TOPIC))],
output='screen'))

return ld