#include "dnxAgent.h"
#include "dnxServerMain.h"
#include "dnxTransport.h"
#include "dnxProtocol.h"
#include "dnxCfgParser.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxLogging.h"
#include "dnxStats.h"
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Go to the source code of this file.
Data Structures | |
struct | MgmtNodeStatsData |
Defines | |
#define | elemcount(x) (sizeof(x)/sizeof(*(x))) |
Functions | |
static char * | buildHelpReply (void) |
Build an allocated response buffer for the HELP request. | |
static int | appendString (char **spp, char *fmt,...) |
Append text to a string by reallocating the string buffer. | |
static int | dnxCountNodes (DnxNodeData *node, void *data) |
Count the number of active nodes in the node table. | |
static char * | buildMgmtStatsReply (char *req) |
Build an allocated response buffer for requested stats values. | |
static int | dnxBuildNodeStatsReply (DnxNodeData *node, void *data) |
Return an allocated stats buffer for a given active node. | |
static char * | buildMgmtNodeStatsReply (char *req) |
Build an allocated response buffer for requested stats values. | |
static int | dnxResetNodeStats (DnxNodeData *node, void *data) |
Reset (zero) the stats of this node. | |
static int | dnxNodeListBuilder (DnxNodeData *node, void *data) |
Append the active node address string to a list of node address strings. | |
static char * | buildMgmtNodeListReply (void) |
Build and return a response for a list of nodes. | |
static char * | buildMgmtCfgReply (void) |
Build an allocated response buffer for the current configuration. | |
static void * | dnxAgentServer (void *data) |
The agent thread control procedure. | |
void | dnxAgentSignalReconfig (void) |
The reconfigure signal from the process signal handler. | |
int | dnxInitAgent (char *agentUrl, DnxCfgParser *parser) |
Initializes the server management agent. | |
void | dnxReleaseAgent (void) |
Cleans up server management agent. | |
Variables | |
static char * | s_agentName = "Agent" |
The name of the agaent channel. | |
static DnxChannel * | s_agent |
The agent management channel. | |
static pthread_t | s_agentTid |
The agent thread id. | |
static DnxCfgParser * | s_parser |
The global configuration parser. | |
static int | s_shutdown = 0 |
The agent shutdown signal flag. | |
static int | s_reconfig = 0 |
The agent reconfigure signal flag. |
Definition in file dnxAgent.c.
#define elemcount | ( | x | ) | (sizeof(x)/sizeof(*(x))) |
Definition at line 48 of file dnxAgent.c.
static int appendString | ( | char ** | spp, | |
char * | fmt, | |||
... | ||||
) | [static] |
Append text to a string by reallocating the string buffer.
This is a var-args function. Additional parameters following the fmt
parameter are based on the content of the fmt
string.
[in] | spp | - the address of a dynamically allocated buffer pointer. |
[in] | fmt | - a printf-like format specifier string. |
Definition at line 113 of file dnxAgent.c.
References DNX_ERR_MEMORY, and xrealloc.
static char* buildHelpReply | ( | void | ) | [static] |
Build an allocated response buffer for the HELP request.
Definition at line 66 of file dnxAgent.c.
References xstrdup.
static char* buildMgmtCfgReply | ( | void | ) | [static] |
Build an allocated response buffer for the current configuration.
Definition at line 415 of file dnxAgent.c.
References dnxCfgParserGetCfg(), xfree, and xmalloc.
static char* buildMgmtNodeListReply | ( | void | ) | [static] |
Build and return a response for a list of nodes.
Definition at line 394 of file dnxAgent.c.
References dnxNodeListBuilder(), dnxStatsForEachNode(), and xstrdup.
Referenced by dnxAgentServer().
static char* buildMgmtNodeStatsReply | ( | char * | req | ) | [static] |
Build an allocated response buffer for requested stats values.
[in] | req | - The ip address followed by the requested stats in a comma-separated string format. |
Definition at line 333 of file dnxAgent.c.
References dnxBuildNodeStatsReply(), dnxStatsForNodeByAddrStr(), MgmtNodeStatsData::rsp, MgmtNodeStatsData::stats, and xstrdup.
Referenced by dnxAgentServer().
static char* buildMgmtStatsReply | ( | char * | req | ) | [static] |
Build an allocated response buffer for requested stats values.
[in] | req | - The requested stats in comma-separated string format. |
Definition at line 164 of file dnxAgent.c.
References appendString(), DISPATCHES_FAILED, DISPATCHES_OK, dnxCountNodes(), dnxStatsForEachNode(), dnxStatsGetServerStats(), elemcount, JOBS_HANDLED, JOBS_REJECTED_NO_NODES, JOBS_REJECTED_NO_SLOTS, POST_RESULTS_FAILED, POST_RESULTS_OK, REQUESTS_EXPIRED, REQUESTS_RECEIVED, RESULTS_FAILED, RESULTS_OK, RESULTS_TIMED_OUT, STATS_COUNT, and xfree.
static void* dnxAgentServer | ( | void * | data | ) | [static] |
The agent thread control procedure.
[in] | data | - thread data; not used. |
Definition at line 440 of file dnxAgent.c.
References DnxMgmtRequest::action, DnxMgmtRequest::address, buildHelpReply(), buildMgmtCfgReply(), buildMgmtNodeListReply(), buildMgmtNodeStatsReply(), buildMgmtStatsReply(), DNX_ERR_TIMEOUT, DNX_MAX_ADDRESS, DNX_MAX_ADDRSTR, DNX_OK, DNX_REQ_ACK, DNX_REQ_NAK, dnxDebug(), dnxErrorString(), dnxLog(), dnxNtop(), dnxReconfigure(), dnxResetNodeStats(), dnxSendMgmtReply(), dnxStatsForEachNode(), dnxStatsResetServerStats(), dnxWaitForMgmtRequest(), DnxMgmtReply::reply, s_reconfig, s_shutdown, DnxMgmtReply::status, versionText(), xfree, DnxMgmtRequest::xid, DnxMgmtReply::xid, and xstrdup.
Referenced by dnxInitAgent().
void dnxAgentSignalReconfig | ( | void | ) |
The reconfigure signal from the process signal handler.
Definition at line 536 of file dnxAgent.c.
References s_reconfig.
Referenced by sighandler().
static int dnxBuildNodeStatsReply | ( | DnxNodeData * | node, | |
void * | data | |||
) | [static] |
Return an allocated stats buffer for a given active node.
The results are built in data->rsp
;
[in] | node | - the node in this iteration. |
[in] | data | - the MgmtNodeStatsData structure. |
Definition at line 257 of file dnxAgent.c.
References appendString(), DISPATCHES_FAILED, DISPATCHES_OK, DNX_ERR_MEMORY, DNX_OK, elemcount, REQUESTS_EXPIRED, REQUESTS_RECEIVED, RESULTS_FAILED, RESULTS_OK, RESULTS_TIMED_OUT, MgmtNodeStatsData::rsp, DnxNodeData::stats, MgmtNodeStatsData::stats, and xfree.
Referenced by buildMgmtNodeStatsReply().
static int dnxCountNodes | ( | DnxNodeData * | node, | |
void * | data | |||
) | [static] |
Count the number of active nodes in the node table.
[in] | node | - the node in this iteration. |
[in] | data | - the address of an integer counter. |
Definition at line 148 of file dnxAgent.c.
References REQUESTS_RECEIVED, and DnxNodeData::stats.
Referenced by buildMgmtStatsReply().
int dnxInitAgent | ( | char * | agentUrl, | |
DnxCfgParser * | parser | |||
) |
Initializes the server management agent.
[in] | agentUrl | - the listen url of the agent. |
[in] | parser | - the global configuration parser. |
Definition at line 541 of file dnxAgent.c.
Referenced by dnxServerInit().
static int dnxNodeListBuilder | ( | DnxNodeData * | node, | |
void * | data | |||
) | [static] |
Append the active node address string to a list of node address strings.
[in] | node | - the node in this iteration. |
[in] | data | - the address of a character pointer containing the list. |
Definition at line 381 of file dnxAgent.c.
References DnxNodeData::addrstr, appendString(), REQUESTS_RECEIVED, and DnxNodeData::stats.
Referenced by buildMgmtNodeListReply().
void dnxReleaseAgent | ( | void | ) |
Cleans up server management agent.
Definition at line 568 of file dnxAgent.c.
Referenced by dnxServerDeInit().
static int dnxResetNodeStats | ( | DnxNodeData * | node, | |
void * | data | |||
) | [static] |
Reset (zero) the stats of this node.
[in] | node | - the node in this iteration. |
[in] | data | - the address of a character pointer containing the list. |
Definition at line 365 of file dnxAgent.c.
References DnxNodeData::stats.
Referenced by dnxAgentServer().
DnxChannel* s_agent [static] |
char* s_agentName = "Agent" [static] |
The name of the agaent channel.
Definition at line 51 of file dnxAgent.c.
Referenced by dnxInitAgent(), and dnxReleaseAgent().
pthread_t s_agentTid [static] |
The agent thread id.
Definition at line 53 of file dnxAgent.c.
Referenced by dnxInitAgent(), and dnxReleaseAgent().
DnxCfgParser* s_parser [static] |
int s_reconfig = 0 [static] |
int s_shutdown = 0 [static] |