Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide better info in the default netdata.conf, and unfiy it with the header used for generating config at runtime. #17733

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,18 @@ if(LINUX)
detect_systemd()
endif()

add_library(libnetdata STATIC ${LIBNETDATA_FILES})
add_custom_command(
COMMAND ${CMAKE_COMMAND}
-DSRC=${CMAKE_SOURCE_DIR}/system/netdata.conf
-DDEST=${CMAKE_BINARY_DIR}/netdata_conf_header.h
-DNAME=NETDATA_CONF_HEADER
-P ${CMAKE_SOURCE_DIR}/packaging/cmake/txt2header.cmake
OUTPUT netdata_conf_header.h
DEPENDS packaging/cmake/txt2header.cmake system/netdata.conf
COMMENT "Generating netdata_conf_header.h from system/netdata.conf"
)

add_library(libnetdata STATIC netdata_conf_header.h ${LIBNETDATA_FILES})

target_include_directories(libnetdata BEFORE PUBLIC ${CONFIG_H_DIR} ${CMAKE_SOURCE_DIR}/src)

Expand Down
42 changes: 42 additions & 0 deletions packaging/cmake/txt2header.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: GPL-3.0
#
# CMake script to generate a C header file from a text file.
#
# The source (SRC), destination (DEST), and define name (NAME) must be
# specified using `-D` options.

# Get CMake to shut up about empty list elements (we want the new behavior anyway).
cmake_policy(SET CMP0007 NEW)

# Read the source file as a list of lines.
file(STRINGS ${SRC} lines)

# Escape everything that needs to be escaped in C strings.
# The replacement arguments below use bracket arguments instead of
# quoted arguments, because some varieties of CMake seem to choke on \"
# in a single-line quoted argument.
list(TRANSFORM lines REPLACE "\\\\" [[\\\\]])
list(TRANSFORM lines REPLACE "\\\"" [[\\"]])
list(TRANSFORM lines REPLACE "'" [[\\']])
list(TRANSFORM lines REPLACE "\\\n" [[\\n]])
list(TRANSFORM lines REPLACE "\\\r" [[\\r]])
list(TRANSFORM lines REPLACE "\\\t" [[\\t]])

# Prepare each line to be a string in a multi-line macro.
list(TRANSFORM lines PREPEND "\"")
list(TRANSFORM lines APPEND "\\n\" \\\n")

# Add the required header lines
list(INSERT lines 0
"// DO NOT EDIT DIRECTLY\n"
"// Generated at build time by CMake from ${SRC}\n"
"\n"
"#define ${NAME} \\\n"
)
list(APPEND lines "\n")

# Join the lines into one string.
list(JOIN lines "" content)

# Write the output file
file(WRITE ${DEST} "${content}")
15 changes: 2 additions & 13 deletions src/libnetdata/config/appconfig.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "../libnetdata.h"
#include "netdata_conf_header.h"

/*
* @Input:
Expand Down Expand Up @@ -817,19 +818,7 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
}
}

buffer_strcat(wb,
"# netdata configuration\n"
"#\n"
"# You can download the latest version of this file, using:\n"
"#\n"
"# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
"# or\n"
"# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
"#\n"
"# You can uncomment and change any of the options below.\n"
"# The value shown in the commented settings, is the default value.\n"
"#\n"
"\n# global netdata configuration\n");
buffer_strcat(wb, NETDATA_CONF_HEADER);

for(i = 0; i <= 17 ;i++) {
appconfig_wrlock(root);
Expand Down
16 changes: 11 additions & 5 deletions system/netdata.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# netdata configuration
#
# You can get the latest version of this file, using:
# Documentation can be found at:
#
# netdatacli dumpconfig > /etc/netdata/netdata.conf
# https://learn.netdata.cloud/docs/netdata-agent/configuration/daemon-configuration
#
# You can also download it using:
# You can retrieve the current effective configuration of the Netdata agent
# while it is running using:
#
# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
# netdatacli dumpconfig
#
# Alternatively, it can be downloaded from the `/netdata.conf` endpoint
# of the web API of the agent:
#
# wget -O - http://localhost:19999/netdata.conf
# or
# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
# curl http://localhost:19999/netdata.conf
#