1
0
mirror of https://github.com/netdata/netdata.git synced 2021-06-06 23:03:21 +03:00
Files
netdata/daemon/commands.h
Austin S. Hemmelgarn ed8a6bea17 Added health check functionality to our Docker images. (#9172)
* Add a `ping` command to netdatacli to check if agent is alive.

This provides a way to trivially check if the agent itself appears to be
running (namely, the command parser for netdatacli in the agent itself
is working and responding), allowing users to check this without having
to rely on us continuing to have `help` be a command sent to the agent
instead of executing locally.

* Add a basic health check to our docke rimages.

This adds a relatively basic health checker script to our Docker images.
By default it verifies that the `/api/v1/info` endpoint returns a 200
status code.

It also supports checking different endpoints or using `netdatacli ping`
to check that Netdata is running, all controlled by a new Docker
environment variable: `NETDATA_HEALTH_CHECK`.

* Avoid unnessecary `chmod` in Dockerfile.

Suggested by @prologic.

* Fix typo in docs.

* Update environment variable name to be more clear.

Also add `-L` to `curl` command in health check to follow redirects.
2020-05-28 18:29:56 +10:00

82 lines
2.3 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef NETDATA_COMMANDS_H
#define NETDATA_COMMANDS_H 1
#ifdef _WIN32
# define PIPENAME "\\\\?\\pipe\\netdata-cli"
#else
# define PIPENAME "/tmp/netdata-ipc"
#endif
#define MAX_COMMAND_LENGTH 4096
#define MAX_EXIT_STATUS_LENGTH 23 /* Can't ever be bigger than "X-18446744073709551616" */
typedef enum cmd {
CMD_HELP = 0,
CMD_RELOAD_HEALTH,
CMD_SAVE_DATABASE,
CMD_REOPEN_LOGS,
CMD_EXIT,
CMD_FATAL,
CMD_RELOAD_CLAIMING_STATE,
CMD_RELOAD_LABELS,
CMD_READ_CONFIG,
CMD_WRITE_CONFIG,
CMD_PING,
CMD_TOTAL_COMMANDS
} cmd_t;
typedef enum cmd_status {
CMD_STATUS_SUCCESS = 0,
CMD_STATUS_FAILURE,
CMD_STATUS_BUSY
} cmd_status_t;
#define CMD_PREFIX_INFO 'O' /* Following string should go to cli stdout */
#define CMD_PREFIX_ERROR 'E' /* Following string should go to cli stderr */
#define CMD_PREFIX_EXIT_CODE 'X' /* Following string is cli integer exit code */
typedef enum cmd_type {
/*
* No other command is allowed to run at the same time (except for CMD_TYPE_HIGH_PRIORITY).
*/
CMD_TYPE_EXCLUSIVE = 0,
/*
* Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) but calls to this command are
* serialized.
*/
CMD_TYPE_ORTHOGONAL,
/*
* Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) as are calls to this command.
*/
CMD_TYPE_CONCURRENT,
/*
* Those commands are always allowed to run.
*/
CMD_TYPE_HIGH_PRIORITY
} cmd_type_t;
/**
* Executes a command and returns the status.
*
* @param args a string that may contain additional parameters to be parsed
* @param message allocate and return a message if need be (up to MAX_COMMAND_LENGTH bytes)
* @return CMD_FAILURE or CMD_SUCCESS
*/
typedef cmd_status_t (command_action_t) (char *args, char **message);
typedef struct command_info {
char *cmd_str; // the command string
command_action_t *func; // the function that executes the command
cmd_type_t type; // Concurrency control information for the command
} command_info_t;
typedef void (command_lock_t) (unsigned index);
cmd_status_t execute_command(cmd_t idx, char *args, char **message);
extern void commands_init(void);
extern void commands_exit(void);
#endif //NETDATA_COMMANDS_H