commit
af0815919e
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_UTIL_HTTP_H_
|
||||
#define _TD_UTIL_HTTP_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t taosSendHttpReport(const char* server, uint16_t port, const char* pCont, int32_t contLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_UTIL_H_*/
|
|
@ -19,8 +19,9 @@
|
|||
#include "mndSync.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tjson.h"
|
||||
#include "thttp.h"
|
||||
|
||||
#define TELEMETRY_SERVER "localhost"
|
||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||
#define TELEMETRY_PORT 80
|
||||
|
||||
static void mndBuildRuntimeInfo(SMnode* pMnode, SJson* pJson) {
|
||||
|
@ -81,62 +82,6 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) {
|
|||
return pCont;
|
||||
}
|
||||
|
||||
static void mndSendTelemetryReport(const char* pCont) {
|
||||
int32_t code = -1;
|
||||
char buf[128] = {0};
|
||||
SOCKET fd = 0;
|
||||
int32_t contLen = strlen(pCont);
|
||||
|
||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
||||
if (ip == 0xffffffff) {
|
||||
mError("failed to get telemetry server ip");
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
fd = taosOpenTcpClientSocket(ip, TELEMETRY_PORT, 0);
|
||||
if (fd < 0) {
|
||||
mError("failed to create telemetry socket");
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
const char* header =
|
||||
"POST /report HTTP/1.1\n"
|
||||
"Host: " TELEMETRY_SERVER
|
||||
"\n"
|
||||
"Content-Type: application/json\n"
|
||||
"Content-Length: ";
|
||||
if (taosWriteSocket(fd, (void*)header, (int32_t)strlen(header)) < 0) {
|
||||
mError("failed to send telemetry header");
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d\n\n", contLen);
|
||||
if (taosWriteSocket(fd, buf, (int32_t)strlen(buf)) < 0) {
|
||||
mError("failed to send telemetry contlen");
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
if (taosWriteSocket(fd, (void*)pCont, contLen) < 0) {
|
||||
mError("failed to send telemetry content");
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
// read something to avoid nginx error 499
|
||||
if (taosReadSocket(fd, buf, 10) < 0) {
|
||||
mError("failed to receive telemetry response");
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
mInfo("send telemetry to %s:%d, len:%d content: %s", TELEMETRY_SERVER, TELEMETRY_PORT, contLen, pCont);
|
||||
code = 0;
|
||||
|
||||
SEND_OVER:
|
||||
if (code != 0) {
|
||||
mError("failed to send telemetry to %s:%d since %s", TELEMETRY_SERVER, TELEMETRY_PORT, terrstr());
|
||||
}
|
||||
taosCloseSocket(fd);
|
||||
}
|
||||
|
||||
static int32_t mndProcessTelemTimer(SMnodeMsg* pReq) {
|
||||
SMnode* pMnode = pReq->pMnode;
|
||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||
|
@ -145,7 +90,7 @@ static int32_t mndProcessTelemTimer(SMnodeMsg* pReq) {
|
|||
taosWLockLatch(&pMgmt->lock);
|
||||
char* pCont = mndBuildTelemetryReport(pMnode);
|
||||
if (pCont != NULL) {
|
||||
mndSendTelemetryReport(pCont);
|
||||
taosSendHttpReport(TELEMETRY_SERVER, TELEMETRY_PORT, pCont, strlen(pCont));
|
||||
free(pCont);
|
||||
}
|
||||
taosWUnLockLatch(&pMgmt->lock);
|
||||
|
|
|
@ -132,7 +132,7 @@ static int32_t mndInitTimer(SMnode *pMnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (taosTmrReset(mndPullupTelem, 300, pMnode, pMnode->timer, &pMnode->telemTimer)) {
|
||||
if (taosTmrReset(mndPullupTelem, 60000, pMnode, pMnode->timer, &pMnode->telemTimer)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "thttp.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
|
||||
int32_t taosSendHttpReport(const char* server, uint16_t port, const char* pCont, int32_t contLen) {
|
||||
int32_t code = -1;
|
||||
SOCKET fd = 0;
|
||||
|
||||
uint32_t ip = taosGetIpv4FromFqdn(server);
|
||||
if (ip == 0xffffffff) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to get http server:%s ip since %s", server, terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
fd = taosOpenTcpClientSocket(ip, port, 0);
|
||||
if (fd < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to create http socket since %s", terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
char header[4096] = {0};
|
||||
int32_t headLen = snprintf(header, sizeof(header),
|
||||
"POST /report HTTP/1.1\n"
|
||||
"Host: %s\n"
|
||||
"Content-Type: application/json\n"
|
||||
"Content-Length: %d\n\n",
|
||||
server, contLen);
|
||||
|
||||
if (taosWriteSocket(fd, (void*)header, headLen) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to send http header since %s", terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
if (taosWriteSocket(fd, (void*)pCont, contLen) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to send http content since %s", terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
// read something to avoid nginx error 499
|
||||
if (taosReadSocket(fd, header, 10) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to receive response since %s", terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
uInfo("send http to %s:%d, len:%d content: %s", server, port, contLen, pCont);
|
||||
code = 0;
|
||||
|
||||
SEND_OVER:
|
||||
if (fd != 0) {
|
||||
taosCloseSocket(fd);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
Loading…
Reference in New Issue