-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(centagent): first centagent executable (#1464)
* 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
1 parent
16b4707
commit 8c83919
Showing
40 changed files
with
1,483 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.