提交 cf433ec9 编写于 作者: S Shengliang Guan

feat: check server status

上级 07ae7839
...@@ -844,6 +844,14 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de ...@@ -844,6 +844,14 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de
goto _OVER; goto _OVER;
} }
if (fqdn == NULL) {
fqdn = tsLocalFqdn;
}
if (port == 0) {
port = tsServerPort;
}
tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN); tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN);
epSet.eps[0].port = (uint16_t)port; epSet.eps[0].port = (uint16_t)port;
rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp); rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp);
...@@ -859,7 +867,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de ...@@ -859,7 +867,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de
} }
code = statusRsp.statusCode; code = statusRsp.statusCode;
if (details != NULL) { if (details != NULL && statusRsp.details != NULL) {
tstrncpy(details, statusRsp.details, maxlen); tstrncpy(details, statusRsp.details, maxlen);
} }
......
...@@ -145,7 +145,7 @@ void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { ...@@ -145,7 +145,7 @@ void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
static void dmGetServerStatus(SDnode *pDnode, SServerStatusRsp *pStatus) { static void dmGetServerStatus(SDnode *pDnode, SServerStatusRsp *pStatus) {
if (pDnode->status == DND_STAT_INIT) { if (pDnode->status == DND_STAT_INIT) {
pStatus->statusCode = TSDB_SRV_STATUS_NETWORK_OK; pStatus->statusCode = TSDB_SRV_STATUS_NETWORK_OK;
} else if (pDnode->status != DND_STAT_STOPPED) { } else if (pDnode->status == DND_STAT_STOPPED) {
pStatus->statusCode = TSDB_SRV_STATUS_EXTING; pStatus->statusCode = TSDB_SRV_STATUS_EXTING;
} else { } else {
pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK; pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK;
...@@ -172,7 +172,7 @@ void dmProcessServerStatusReq(SDnode *pDnode, SRpcMsg *pReq) { ...@@ -172,7 +172,7 @@ void dmProcessServerStatusReq(SDnode *pDnode, SRpcMsg *pReq) {
SServerStatusRsp statusRsp = {0}; SServerStatusRsp statusRsp = {0};
dmGetServerStatus(pDnode, &statusRsp); dmGetServerStatus(pDnode, &statusRsp);
SRpcMsg rspMsg = {.handle = pReq->handle, .handle = pReq->ahandle}; SRpcMsg rspMsg = {.handle = pReq->handle, .ahandle = pReq->ahandle};
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp); int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
if (rspLen < 0) { if (rspLen < 0) {
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY; rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
......
...@@ -50,6 +50,8 @@ typedef struct SShellArguments { ...@@ -50,6 +50,8 @@ typedef struct SShellArguments {
char dir[TSDB_FILENAME_LEN]; char dir[TSDB_FILENAME_LEN];
int threadNum; int threadNum;
int check; int check;
bool status;
bool verbose;
char* commands; char* commands;
int abort; int abort;
int port; int port;
...@@ -72,7 +74,6 @@ void read_history(); ...@@ -72,7 +74,6 @@ void read_history();
void write_history(); void write_history();
void source_file(TAOS* con, char* fptr); void source_file(TAOS* con, char* fptr);
void source_dir(TAOS* con, SShellArguments* args); void source_dir(TAOS* con, SShellArguments* args);
void shellCheck(TAOS* con, SShellArguments* args);
void get_history_path(char* history); void get_history_path(char* history);
void shellCheck(TAOS* con, SShellArguments* args); void shellCheck(TAOS* con, SShellArguments* args);
void cleanup_handler(void* arg); void cleanup_handler(void* arg);
......
...@@ -35,6 +35,7 @@ static char args_doc[] = ""; ...@@ -35,6 +35,7 @@ static char args_doc[] = "";
TdThread pid; TdThread pid;
static tsem_t cancelSem; static tsem_t cancelSem;
extern void taos_init();
static struct argp_option options[] = { static struct argp_option options[] = {
{"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."}, {"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."},
...@@ -52,6 +53,8 @@ static struct argp_option options[] = { ...@@ -52,6 +53,8 @@ static struct argp_option options[] = {
{"check", 'k', "CHECK", 0, "Check tables."}, {"check", 'k', "CHECK", 0, "Check tables."},
{"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."}, {"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."},
{"timezone", 'z', "TIMEZONE", 0, "Time zone of the shell, default is local."}, {"timezone", 'z', "TIMEZONE", 0, "Time zone of the shell, default is local."},
{"status", 't', NULL, 0, "Check the service status."},
{"verbose", 'v', NULL, 0, "Check the details of the service status."},
{"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync|speed|fqdn."}, {"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync|speed|fqdn."},
{"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."}, {"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."},
{"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."}, {"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."},
...@@ -138,6 +141,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -138,6 +141,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case 'k': case 'k':
arguments->check = atoi(arg); arguments->check = atoi(arg);
break; break;
case 't':
arguments->status = true;
break;
case 'v':
arguments->verbose = true;
break;
case 'd': case 'd':
arguments->database = arg; arguments->database = arg;
break; break;
...@@ -608,10 +617,9 @@ int main(int argc, char *argv[]) { ...@@ -608,10 +617,9 @@ int main(int argc, char *argv[]) {
} }
shellParseArgument(argc, argv, &args); shellParseArgument(argc, argv, &args);
taos_init();
if (args.dump_config) { if (args.dump_config) {
taosInitCfg(configDir, NULL, NULL, NULL, 1);
SConfig *pCfg = taosGetCfg(); SConfig *pCfg = taosGetCfg();
if (NULL == pCfg) { if (NULL == pCfg) {
printf("TDengine read global config failed!\n"); printf("TDengine read global config failed!\n");
...@@ -621,21 +629,36 @@ int main(int argc, char *argv[]) { ...@@ -621,21 +629,36 @@ int main(int argc, char *argv[]) {
exit(0); exit(0);
} }
if (args.netTestRole && args.netTestRole[0] != 0) { if (args.status || args.verbose) {
TAOS *con = NULL; char details[1024] = {0};
if (args.auth == NULL) {
con = taos_connect(args.host, args.user, args.password, args.database, args.port); TSDB_SERVER_STATUS code = taos_check_server_status(args.host, args.port, details, args.verbose ? 1024 : 0);
} else { switch (code) {
con = taos_connect_auth(args.host, args.user, args.auth, args.database, args.port); case TSDB_SRV_STATUS_UNAVAILABLE:
printf("0: unavailable\n");
break;
case TSDB_SRV_STATUS_NETWORK_OK:
printf("1: network ok\n");
break;
case TSDB_SRV_STATUS_SERVICE_OK:
printf("2: service ok\n");
break;
case TSDB_SRV_STATUS_SERVICE_DEGRADED:
printf("3: service degradedk\n");
break;
case TSDB_SRV_STATUS_EXTING:
printf("4: exiting\n");
break;
} }
// if (taos_init()) { if (strlen(details) != 0) {
// printf("Failed to init taos"); printf("detail info:\n%s\n", details);
// exit(EXIT_FAILURE); }
// } exit(0);
}
if (args.netTestRole && args.netTestRole[0] != 0) {
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType); taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
taos_close(con);
exit(0); exit(0);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册