send the basic information of the monitor
This commit is contained in:
parent
4f4100f9c6
commit
8b1a991186
|
@ -52,6 +52,8 @@ void deltaToUtcInitOnce();
|
||||||
|
|
||||||
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision);
|
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision);
|
||||||
|
|
||||||
|
void taosFormatUtcTime(char *buf, int32_t bufLen, int64_t time, int32_t precision);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -627,3 +627,50 @@ const char* fmtts(int64_t ts) {
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) {
|
||||||
|
char ts[40] = {0};
|
||||||
|
struct tm* ptm;
|
||||||
|
|
||||||
|
int32_t fractionLen;
|
||||||
|
char* format = NULL;
|
||||||
|
time_t quot = 0;
|
||||||
|
long mod = 0;
|
||||||
|
|
||||||
|
switch (precision) {
|
||||||
|
case TSDB_TIME_PRECISION_MILLI: {
|
||||||
|
quot = t / 1000;
|
||||||
|
fractionLen = 5;
|
||||||
|
format = ".%03" PRId64;
|
||||||
|
mod = t % 1000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_TIME_PRECISION_MICRO: {
|
||||||
|
quot = t / 1000000;
|
||||||
|
fractionLen = 8;
|
||||||
|
format = ".%06" PRId64;
|
||||||
|
mod = t % 1000000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_TIME_PRECISION_NANO: {
|
||||||
|
quot = t / 1000000000;
|
||||||
|
fractionLen = 11;
|
||||||
|
format = ".%09" PRId64;
|
||||||
|
mod = t % 1000000000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
fractionLen = 0;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptm = localtime(");
|
||||||
|
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm);
|
||||||
|
length += snprintf(ts + length, fractionLen, format, mod);
|
||||||
|
length += (int32_t)strftime(ts + length, 40 - length, "%z", ptm);
|
||||||
|
|
||||||
|
tstrncpy(buf, ts, bufLen);
|
||||||
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "thttp.h"
|
#include "thttp.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
#include "ttime.h"
|
||||||
|
|
||||||
static SMonitor tsMonitor = {0};
|
static SMonitor tsMonitor = {0};
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ SMonInfo *monCreateMonitorInfo() {
|
||||||
if (pMonitor == NULL) return NULL;
|
if (pMonitor == NULL) return NULL;
|
||||||
|
|
||||||
taosWLockLatch(&tsMonitor.lock);
|
taosWLockLatch(&tsMonitor.lock);
|
||||||
pMonitor->logs = taosArrayDup(pMonitor->logs);
|
pMonitor->logs = taosArrayDup(tsMonitor.logs);
|
||||||
taosArrayClear(tsMonitor.logs);
|
taosArrayClear(tsMonitor.logs);
|
||||||
taosWUnLockLatch(&tsMonitor.lock);
|
taosWUnLockLatch(&tsMonitor.lock);
|
||||||
|
|
||||||
|
@ -88,6 +89,11 @@ void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo) {
|
||||||
SJson *pJson = pMonitor->pJson;
|
SJson *pJson = pMonitor->pJson;
|
||||||
tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id);
|
tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id);
|
||||||
tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep);
|
tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep);
|
||||||
|
|
||||||
|
int64_t ms = taosGetTimestampMs();
|
||||||
|
char buf[40] = {0};
|
||||||
|
taosFormatUtcTime(buf, sizeof(buf), ms, TSDB_TIME_PRECISION_MILLI);
|
||||||
|
tjsonAddStringToObject(pJson, "ts", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo);
|
void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo);
|
||||||
|
|
|
@ -32,7 +32,7 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, const char* pCont,
|
||||||
fd = taosOpenTcpClientSocket(ip, port, 0);
|
fd = taosOpenTcpClientSocket(ip, port, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
uError("failed to create http socket since %s", terrstr());
|
uError("failed to create socket to %s:%u since %s", server, port, terrstr());
|
||||||
goto SEND_OVER;
|
goto SEND_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,24 +46,24 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, const char* pCont,
|
||||||
|
|
||||||
if (taosWriteSocket(fd, (void*)header, headLen) < 0) {
|
if (taosWriteSocket(fd, (void*)header, headLen) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
uError("failed to send http header since %s", terrstr());
|
uError("failed to send http header to %s:%u since %s", server, port, terrstr());
|
||||||
goto SEND_OVER;
|
goto SEND_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteSocket(fd, (void*)pCont, contLen) < 0) {
|
if (taosWriteSocket(fd, (void*)pCont, contLen) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
uError("failed to send http content since %s", terrstr());
|
uError("failed to send http content to %s:%u since %s", server, port, terrstr());
|
||||||
goto SEND_OVER;
|
goto SEND_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read something to avoid nginx error 499
|
// read something to avoid nginx error 499
|
||||||
if (taosReadSocket(fd, header, 10) < 0) {
|
if (taosReadSocket(fd, header, 10) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
uError("failed to receive response since %s", terrstr());
|
uError("failed to receive response from %s:%u since %s", server, port, terrstr());
|
||||||
goto SEND_OVER;
|
goto SEND_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
uInfo("send http to %s:%d, len:%d content: %s", server, port, contLen, pCont);
|
uInfo("send http to %s:%u, len:%d content: %s", server, port, contLen, pCont);
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
SEND_OVER:
|
SEND_OVER:
|
||||||
|
|
Loading…
Reference in New Issue