Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
29422c65
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
29422c65
编写于
3月 02, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
telemetry
上级
c5a74d6f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
110 addition
and
59 deletion
+110
-59
include/util/thttp.h
include/util/thttp.h
+31
-0
source/dnode/mnode/impl/src/mndTelem.c
source/dnode/mnode/impl/src/mndTelem.c
+3
-58
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+1
-1
source/util/src/thttp.c
source/util/src/thttp.c
+75
-0
未找到文件。
include/util/thttp.h
0 → 100644
浏览文件 @
29422c65
/*
* 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_*/
source/dnode/mnode/impl/src/mndTelem.c
浏览文件 @
29422c65
...
...
@@ -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
);
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
29422c65
...
...
@@ -132,7 +132,7 @@ static int32_t mndInitTimer(SMnode *pMnode) {
return
-
1
;
}
if
(
taosTmrReset
(
mndPullupTelem
,
3
00
,
pMnode
,
pMnode
->
timer
,
&
pMnode
->
telemTimer
))
{
if
(
taosTmrReset
(
mndPullupTelem
,
600
00
,
pMnode
,
pMnode
->
timer
,
&
pMnode
->
telemTimer
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
source/util/src/thttp.c
0 → 100644
浏览文件 @
29422c65
/*
* 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
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录