Skip to content

Commit

Permalink
feature(centagent): first centagent executable (#1464)
Browse files Browse the repository at this point in the history
* first centagent executable

* use json configuration instead

* centreon-agent => centreon-monitoring-agent

* move process common

* Apply suggestions from code review

Co-authored-by: omercier <[email protected]>

* github issue

---------

Co-authored-by: omercier <[email protected]>
  • Loading branch information
jean-christophe81 and omercier committed Aug 20, 2024
1 parent 16b4707 commit 8c83919
Show file tree
Hide file tree
Showing 40 changed files with 1,483 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/scripts/collect-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tests/ut_engine --gtest_output=xml:ut_engine.xml
tests/ut_clib --gtest_output=xml:ut_clib.xml
tests/ut_connector --gtest_output=xml:ut_connector.xml
tests/ut_common --gtest_output=xml:ut_common.xml
tests/ut_agent --gtest_output=xml:ut_agent.xml
echo "---------------------------------------------------------- end of ut tests ------------------------------------------------"
2 changes: 2 additions & 0 deletions .github/workflows/centreon-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- agent/**
- bbdo/**
- broker/**
- ccc/**
Expand All @@ -34,6 +35,7 @@ on:
- master
- "[2-9][0-9].[0-9][0-9].x"
paths:
- agent/**
- bbdo/**
- broker/**
- ccc/**
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
if: ${{ matrix.package_extension == 'rpm' }}
run: |
cd selinux
for MODULE in "centreon-engine" "centreon-broker"; do
for MODULE in "centreon-engine" "centreon-broker" "centreon-monitoring-agent"; do
cd $MODULE
sed -i "s/@VERSION@/${{ inputs.major_version }}.${{ inputs.minor_version }}/g" $MODULE.te
make -f /usr/share/selinux/devel/Makefile
Expand Down Expand Up @@ -190,8 +190,9 @@ jobs:
"build/engine/modules/bench/centengine_bench_passive"
"build/connectors/perl/centreon_connector_perl"
"build/connectors/ssh/centreon_connector_ssh"
"build/ccc/ccc")
for file in "${exe[@]}"; do
"build/ccc/ccc"
"build/agent/centagent")
for file in ${exe[@]}; do
echo "Making a debug file of $file"
objcopy --only-keep-debug $file $file.debug
objcopy --strip-debug $file
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ log.html
output.xml
report.html

# agent
agent/scripts/centagent.service
opentelemetry-proto

# bbdo
bbdo/*_accessor.hh

Expand Down Expand Up @@ -140,3 +144,4 @@ tests/bench.unqlite
tests/resources/*_pb2.py
tests/resources/*_pb2_grpc.py
tests/resources/grpc_stream.proto
tests/resources/opentelemetry
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ endif()
set(USER_BROKER centreon-broker)
set(USER_ENGINE centreon-engine)


find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
Expand Down Expand Up @@ -236,6 +237,7 @@ add_subdirectory(bbdo)
add_subdirectory(engine)
add_subdirectory(connectors)
add_subdirectory(ccc)
add_subdirectory(agent)

if (WITH_MALLOC_TRACE)
add_subdirectory(malloc-trace)
Expand All @@ -247,9 +249,10 @@ add_custom_target(test-engine COMMAND tests/ut_engine)
add_custom_target(test-clib COMMAND tests/ut_clib)
add_custom_target(test-connector COMMAND tests/ut_connector)
add_custom_target(test-common COMMAND tests/ut_common)
add_custom_target(test-agent COMMAND tests/ut_agent)

add_custom_target(test DEPENDS test-broker test-engine test-clib test-connector
test-common)
test-common test-agent)

add_custom_target(test-coverage DEPENDS broker-test-coverage
engine-test-coverage clib-test-coverage)
177 changes: 177 additions & 0 deletions agent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#
# Copyright 2024 Centreon
#
# 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.
#
# For more information : [email protected]
#

# Global options.
project("Centreon agent" CXX)

# Set directories.
set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/inc/com/centreon/agent")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
set(SCRIPT_DIR "${PROJECT_SOURCE_DIR}/scripts")


add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1")
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)

option(WITH_LIBCXX "compiles and links cbd with clang++/libc++")

if(WITH_LIBCXX)
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -Werror -O1
# -fno-omit-frame-pointer")
endif()

#otel service
set(service_files
opentelemetry/proto/collector/metrics/v1/metrics_service
)

foreach(name IN LISTS service_files)
set(proto_file "${name}.proto")
add_custom_command(
OUTPUT "${SRC_DIR}/${name}.grpc.pb.cc"
COMMENT "Generating grpc files from the otl service file ${proto_file}"
DEPENDS opentelemetry-proto-files
COMMAND
${Protobuf_PROTOC_EXECUTABLE} ARGS
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
--proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto
--grpc_out=${SRC_DIR} ${proto_file}
VERBATIM
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

endforeach()

set(otl_protobuf_files
opentelemetry/proto/collector/metrics/v1/metrics_service
opentelemetry/proto/metrics/v1/metrics
opentelemetry/proto/common/v1/common
opentelemetry/proto/resource/v1/resource
)
foreach(name IN LISTS otl_protobuf_files)
set(proto_file "${name}.proto")
add_custom_command(
OUTPUT "${SRC_DIR}/${name}.pb.cc"
COMMENT "Generating interface files from the otl file ${proto_file}"
DEPENDS opentelemetry-proto-files
COMMAND
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${SRC_DIR}
--proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto ${proto_file}
VERBATIM)
endforeach()


#centagent server and client
add_custom_command(
DEPENDS ${PROJECT_SOURCE_DIR}/proto/agent.proto
COMMENT "Generating interface files from the conf centagent proto file (grpc)"
OUTPUT ${SRC_DIR}/agent.grpc.pb.cc
COMMAND
${Protobuf_PROTOC_EXECUTABLE} ARGS
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
--proto_path=${PROJECT_SOURCE_DIR}/proto --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto
--grpc_out=${SRC_DIR} ${PROJECT_SOURCE_DIR}/proto/agent.proto
DEPENDS ${PROJECT_SOURCE_DIR}/proto/agent.proto
COMMENT "Generating interface files from the conf centagent proto file (protobuf)"
OUTPUT ${SRC_DIR}/agent.pb.cc
COMMAND
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${SRC_DIR}
--proto_path=${PROJECT_SOURCE_DIR}/proto --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto
${PROJECT_SOURCE_DIR}/proto/agent.proto
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})


add_library(centagent_lib STATIC
${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc
${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc
${SRC_DIR}/opentelemetry/proto/metrics/v1/metrics.pb.cc
${SRC_DIR}/opentelemetry/proto/common/v1/common.pb.cc
${SRC_DIR}/opentelemetry/proto/resource/v1/resource.pb.cc
${SRC_DIR}/config.cc
)

include_directories(
${INCLUDE_DIR}
${SRC_DIR}
${CMAKE_SOURCE_DIR}/common/inc
${CMAKE_SOURCE_DIR}/common/grpc/inc
)

target_precompile_headers(centagent_lib PRIVATE precomp_inc/precomp.hh)

SET(CENTREON_AGENT centagent)

add_executable(${CENTREON_AGENT} ${SRC_DIR}/main.cc)

target_link_libraries(
${CENTREON_AGENT} PRIVATE
-L${PROTOBUF_LIB_DIR}
gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts
centagent_lib
centreon_common
centreon_grpc
-L${Boost_LIBRARY_DIR_RELEASE}
boost_program_options
fmt::fmt)

target_precompile_headers(${CENTREON_AGENT} REUSE_FROM centagent_lib)

target_include_directories(${CENTREON_AGENT} PRIVATE
${INCLUDE_DIR}
${SRC_DIR}
${CMAKE_SOURCE_DIR}/common/inc
)

set(AGENT_VAR_LOG_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-monitoring-agent")


install(TARGETS ${CENTREON_AGENT} RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")

if(WITH_TESTING)
add_subdirectory(test)
endif()


set(PREFIX_AGENT_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/centreon-monitoring-agent")
set(USER_AGENT centreon-monitoring-agent)


if(WITH_CONF)
add_subdirectory(conf)
endif()

# Generate Systemd script.
message(STATUS "Generating systemd startup script.")
configure_file("${SCRIPT_DIR}/centagent.service.in"
"${SCRIPT_DIR}/centagent.service")

# Startup dir.
if(WITH_STARTUP_DIR)
set(STARTUP_DIR "${WITH_STARTUP_DIR}")
else()
set(STARTUP_DIR "/etc/systemd/system")
endif()

# Script install rule.
install(
PROGRAMS "${SCRIPT_DIR}/centagent.service"
DESTINATION "${STARTUP_DIR}"
COMPONENT "runtime")
43 changes: 43 additions & 0 deletions agent/conf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Copyright 2024 Centreon
#
# 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.
#
# For more information : [email protected]
#

# Set directories.
set(SRC_DIR "${PROJECT_SOURCE_DIR}/conf")

# Configure files.
configure_file("${SRC_DIR}/centagent.json.in"
"${SRC_DIR}/centagent.json")

# Install files if necessary.
option(WITH_SAMPLE_CONFIG "Install sample configuration files." ON)
if (WITH_SAMPLE_CONFIG)
install(DIRECTORY "${SRC_DIR}/"
DESTINATION "${PREFIX_AGENT_CONF}"
COMPONENT "runtime"
FILES_MATCHING PATTERN "*.cfg")

install(CODE "
function(my_chown user group file)
if (APPLE OR (UNIX AND NOT CYGWIN))
execute_process(COMMAND \"chown\" \"\${user}:\${group}\" \"\${file}\")
endif ()
endfunction()
my_chown(\"${USER_AGENT}\" \"${USER_AGENT}\" \"${PREFIX_AGENT_CONF}/centagent.json\")
")
endif ()
15 changes: 15 additions & 0 deletions agent/conf/centagent.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"log_file":"@AGENT_VAR_LOG_DIR@/@[email protected]",
"log_level":"info",
"log_type":"file",
"log_max_file_size":10,
"log_max_files":3,
"endpoint":"<poller ip>:4317",
"encryption":false,
"certificate":"",
"private_key":"",
"ca_certificate":"",
"ca_name":"",
"host":"my-centreon-host",
"reversed_grpc_streaming":false
}
23 changes: 23 additions & 0 deletions agent/doc/agent-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Centreon Monitoring Agent documentation {#mainpage}

## Introduction

The purpose of this program is to run checks on the Windows and Linux operating systems. It is entirely asynchronous, with the exception of the gRPC layers. It is also single-threaded and therefore needs no mutexes, except in the gRPC part.
This is why, when a request is received, it is posted to ASIO for processing in the main thread.

## Configuration
The configuration is given by Engine by an AgentConfiguration message sent over gRPC.
The configuration object is embedded in MessageToAgent::config

## Scheduler
We try to spread checks over the check_period.
Example: We have 10 checks to execute during one second. Check1 will start at now, second at now + 0.1s..

When the Agent receives the configuration, all checks are recreated.
For example, we have 100 checks to execute in 10 minutes, at it is 12:00:00.
The first service check will start right now, the second one at 12:00:06, third at 12:00:12... and the last one at 12:09:54
We don't care about the duration of tests, we work with time points.
In the previous example, the second check for the first service will be scheduled at 12:00:10 even if all other checks has not been yet started.

In case of check duration is too long, we might exceed maximum of concurrent checks. In that case checks will be executed as soon one will be ended.
This means that the second check may start later than the scheduled time point (12:00:10) if the other first checks are too long. The order of checks is always respected even in case of a bottleneck.
Binary file added agent/doc/pictures/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8c83919

Please sign in to comment.