mirror of
https://github.com/netdata/netdata.git
synced 2025-04-14 09:38:34 +00:00
port useful code from incomplete PRs (#16863)
* port useful code from incomplete PRs * change systemd-journal plugin default thread name
This commit is contained in:
parent
b84ccfa1dd
commit
3be077bb2a
9 changed files with 86 additions and 32 deletions
CMakeLists.txt
collectors/systemd-journal.plugin
libnetdata
web/server
|
@ -677,6 +677,7 @@ set(LIBNETDATA_FILES
|
|||
libnetdata/config/dyncfg.c
|
||||
libnetdata/config/dyncfg.h
|
||||
libnetdata/json/json-c-parser-inline.h
|
||||
libnetdata/template-enum.h
|
||||
)
|
||||
|
||||
if(ENABLE_PLUGIN_EBPF)
|
||||
|
|
|
@ -19,7 +19,7 @@ static bool journal_data_direcories_exist() {
|
|||
|
||||
int main(int argc __maybe_unused, char **argv __maybe_unused) {
|
||||
clocks_init();
|
||||
netdata_thread_set_tag("SDMAIN");
|
||||
netdata_thread_set_tag("sd-jrnl.plugin");
|
||||
nd_log_initialize_for_external_plugins("systemd-journal.plugin");
|
||||
|
||||
netdata_configured_host_prefix = getenv("NETDATA_HOST_PREFIX");
|
||||
|
|
|
@ -2,33 +2,21 @@
|
|||
|
||||
#include "../libnetdata.h"
|
||||
|
||||
const char *http_request_method2string(HTTP_REQUEST_MODE mode) {
|
||||
switch(mode) {
|
||||
case HTTP_REQUEST_MODE_OPTIONS:
|
||||
return "OPTIONS";
|
||||
ENUM_STR_MAP_DEFINE(HTTP_REQUEST_MODE) =
|
||||
{
|
||||
{ .name = "OPTIONS", .id = HTTP_REQUEST_MODE_OPTIONS },
|
||||
{ .name = "GET", .id = HTTP_REQUEST_MODE_GET },
|
||||
{ .name = "FILECOPY", .id = HTTP_REQUEST_MODE_FILECOPY },
|
||||
{ .name = "POST", .id = HTTP_REQUEST_MODE_POST },
|
||||
{ .name = "PUT", .id = HTTP_REQUEST_MODE_PUT },
|
||||
{ .name = "DELETE", .id = HTTP_REQUEST_MODE_DELETE },
|
||||
{ .name = "STREAM", .id = HTTP_REQUEST_MODE_STREAM },
|
||||
|
||||
case HTTP_REQUEST_MODE_GET:
|
||||
return "GET";
|
||||
// terminator
|
||||
{ .name = NULL, .id = 0 }
|
||||
};
|
||||
|
||||
case HTTP_REQUEST_MODE_FILECOPY:
|
||||
return "FILECOPY";
|
||||
|
||||
case HTTP_REQUEST_MODE_POST:
|
||||
return "POST";
|
||||
|
||||
case HTTP_REQUEST_MODE_PUT:
|
||||
return "PUT";
|
||||
|
||||
case HTTP_REQUEST_MODE_DELETE:
|
||||
return "DELETE";
|
||||
|
||||
case HTTP_REQUEST_MODE_STREAM:
|
||||
return "STREAM";
|
||||
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
ENUM_STR_DEFINE_FUNCTIONS(HTTP_REQUEST_MODE, 0, "UNKNOWN");
|
||||
|
||||
const char *http_response_code2string(int code) {
|
||||
switch(code) {
|
||||
|
|
|
@ -53,7 +53,8 @@ typedef enum __attribute__((__packed__)) {
|
|||
HTTP_REQUEST_MODE_STREAM = 7,
|
||||
} HTTP_REQUEST_MODE;
|
||||
|
||||
const char *http_request_method2string(HTTP_REQUEST_MODE mode);
|
||||
ENUM_STR_DEFINE_FUNCTIONS_EXTERN(HTTP_REQUEST_MODE);
|
||||
|
||||
const char *http_response_code2string(int code);
|
||||
HTTP_CONTENT_TYPE contenttype_for_filename(const char *filename);
|
||||
|
||||
|
|
|
@ -25,6 +25,29 @@
|
|||
} \
|
||||
} while(0)
|
||||
|
||||
#define JSONC_PARSE_TXT2BUFFER_OR_ERROR_AND_RETURN(jobj, path, member, dst, error, required) do { \
|
||||
json_object *_j; \
|
||||
if (json_object_object_get_ex(jobj, member, &_j) && json_object_is_type(_j, json_type_string)) { \
|
||||
const char *_s = json_object_get_string(_j); \
|
||||
if(!_s || !*_s) { \
|
||||
buffer_free(dst); \
|
||||
dst = NULL; \
|
||||
} \
|
||||
else { \
|
||||
if (dst) \
|
||||
buffer_flush(dst); \
|
||||
else \
|
||||
dst = buffer_create(0, NULL); \
|
||||
if (_s && *_s) \
|
||||
buffer_strcat(dst, _s); \
|
||||
} \
|
||||
} \
|
||||
else if(required) { \
|
||||
buffer_sprintf(error, "missing or invalid type for '%s.%s' string", path, member); \
|
||||
return false; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define JSONC_PARSE_TXT2PATTERN_OR_ERROR_AND_RETURN(jobj, path, member, dst, error) do { \
|
||||
json_object *_j; \
|
||||
if (json_object_object_get_ex(jobj, member, &_j) && json_object_is_type(_j, json_type_string)) { \
|
||||
|
|
|
@ -705,6 +705,7 @@ extern char *netdata_configured_host_prefix;
|
|||
#include "xxhash.h"
|
||||
|
||||
#include "uuid/uuid.h"
|
||||
#include "template-enum.h"
|
||||
#include "http/http_access.h"
|
||||
#include "http/content_type.h"
|
||||
#include "config/dyncfg.h"
|
||||
|
|
|
@ -444,7 +444,7 @@ int progress_function_result(BUFFER *wb, const char *hostname) {
|
|||
|
||||
buffer_json_add_array_item_uuid_compact(wb, &qp->transaction);
|
||||
buffer_json_add_array_item_uint64(wb, qp->started_ut);
|
||||
buffer_json_add_array_item_string(wb, http_request_method2string(qp->mode));
|
||||
buffer_json_add_array_item_string(wb, HTTP_REQUEST_MODE_2str(qp->mode));
|
||||
buffer_json_add_array_item_string(wb, buffer_tostring(qp->query));
|
||||
|
||||
if(!buffer_strlen(qp->client)) {
|
||||
|
|
40
libnetdata/template-enum.h
Normal file
40
libnetdata/template-enum.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#ifndef NETDATA_TEMPLATE_ENUM_H
|
||||
#define NETDATA_TEMPLATE_ENUM_H
|
||||
|
||||
#define ENUM_STR_MAP_DEFINE(type) \
|
||||
static struct { \
|
||||
type id; \
|
||||
const char *name; \
|
||||
} type ## _names[]
|
||||
|
||||
#define ENUM_STR_DEFINE_FUNCTIONS_EXTERN(type) \
|
||||
type type ## _2id(const char *str); \
|
||||
const char *type##_2str(type id);
|
||||
|
||||
#define ENUM_STR_DEFINE_FUNCTIONS(type, def, def_str) \
|
||||
type type##_2id(const char *str) \
|
||||
{ \
|
||||
if (!str || !*str) \
|
||||
return def; \
|
||||
\
|
||||
for (size_t i = 0; type ## _names[i].name; i++) { \
|
||||
if (strcmp(type ## _names[i].name, str) == 0) \
|
||||
return type ## _names[i].id; \
|
||||
} \
|
||||
\
|
||||
return def; \
|
||||
} \
|
||||
\
|
||||
const char *type##_2str(type id) \
|
||||
{ \
|
||||
for (size_t i = 0; type ## _names[i].name; i++) { \
|
||||
if (id == type ## _names[i].id) \
|
||||
return type ## _names[i].name; \
|
||||
} \
|
||||
\
|
||||
return def_str; \
|
||||
}
|
||||
|
||||
#endif //NETDATA_TEMPLATE_ENUM_H
|
|
@ -239,7 +239,7 @@ void web_client_log_completed_request(struct web_client *w, bool update_web_stat
|
|||
ND_LOG_FIELD_U64(NDF_CONNECTION_ID, w->id),
|
||||
ND_LOG_FIELD_UUID(NDF_TRANSACTION_ID, &w->transaction),
|
||||
ND_LOG_FIELD_TXT(NDF_NIDL_NODE, w->client_host),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, http_request_method2string(w->mode)),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, HTTP_REQUEST_MODE_2str(w->mode)),
|
||||
ND_LOG_FIELD_BFR(NDF_REQUEST, w->url_as_received),
|
||||
ND_LOG_FIELD_U64(NDF_RESPONSE_CODE, w->response.code),
|
||||
ND_LOG_FIELD_U64(NDF_RESPONSE_SENT_BYTES, sent),
|
||||
|
@ -635,7 +635,7 @@ int web_client_api_request(RRDHOST *host, struct web_client *w, char *url_path_f
|
|||
ND_LOG_FIELD_TXT(NDF_SRC_FORWARDED_HOST, w->forwarded_host),
|
||||
ND_LOG_FIELD_TXT(NDF_SRC_FORWARDED_FOR, w->forwarded_for),
|
||||
ND_LOG_FIELD_TXT(NDF_NIDL_NODE, w->client_host),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, http_request_method2string(w->mode)),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, HTTP_REQUEST_MODE_2str(w->mode)),
|
||||
ND_LOG_FIELD_BFR(NDF_REQUEST, w->url_as_received),
|
||||
ND_LOG_FIELD_U64(NDF_CONNECTION_ID, w->id),
|
||||
ND_LOG_FIELD_UUID(NDF_TRANSACTION_ID, &w->transaction),
|
||||
|
@ -1170,7 +1170,7 @@ int web_client_api_request_with_node_selection(RRDHOST *host, struct web_client
|
|||
// entry point for all API requests
|
||||
|
||||
ND_LOG_STACK lgs[] = {
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, http_request_method2string(w->mode)),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, HTTP_REQUEST_MODE_2str(w->mode)),
|
||||
ND_LOG_FIELD_BFR(NDF_REQUEST, w->url_as_received),
|
||||
ND_LOG_FIELD_U64(NDF_CONNECTION_ID, w->id),
|
||||
ND_LOG_FIELD_UUID(NDF_TRANSACTION_ID, &w->transaction),
|
||||
|
@ -1397,7 +1397,7 @@ void web_client_process_request_from_web_server(struct web_client *w) {
|
|||
ND_LOG_FIELD_TXT(NDF_SRC_FORWARDED_HOST, w->forwarded_host),
|
||||
ND_LOG_FIELD_TXT(NDF_SRC_FORWARDED_FOR, w->forwarded_for),
|
||||
ND_LOG_FIELD_TXT(NDF_NIDL_NODE, w->client_host),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, http_request_method2string(w->mode)),
|
||||
ND_LOG_FIELD_TXT(NDF_REQUEST_METHOD, HTTP_REQUEST_MODE_2str(w->mode)),
|
||||
ND_LOG_FIELD_BFR(NDF_REQUEST, w->url_as_received),
|
||||
ND_LOG_FIELD_U64(NDF_CONNECTION_ID, w->id),
|
||||
ND_LOG_FIELD_UUID(NDF_TRANSACTION_ID, &w->transaction),
|
||||
|
|
Loading…
Add table
Reference in a new issue