提交 52cb5b44 编写于 作者: G Ganlin Zhao

[TD-6452]<feature>: taoskeeper metrics collector phase 1 taosd implementation

上级 e9291a00
...@@ -62,6 +62,10 @@ void monSaveDnodeLog(int32_t level, const char *const format, ...); ...@@ -62,6 +62,10 @@ void monSaveDnodeLog(int32_t level, const char *const format, ...);
void monExecuteSQL(char *sql); void monExecuteSQL(char *sql);
typedef void (*MonExecuteSQLCbFP)(void *param, TAOS_RES *, int code); typedef void (*MonExecuteSQLCbFP)(void *param, TAOS_RES *, int code);
void monExecuteSQLWithResultCallback(char *sql, MonExecuteSQLCbFP callback, void* param); void monExecuteSQLWithResultCallback(char *sql, MonExecuteSQLCbFP callback, void* param);
void monIncQueryReqCnt();
void monIncSubmitReqCnt();
int32_t monFetchQueryReqCnt();
int32_t monFetchSubmitReqCnt();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -77,7 +77,9 @@ typedef struct { ...@@ -77,7 +77,9 @@ typedef struct {
} SMonConn; } SMonConn;
static SMonConn tsMonitor = {0}; static SMonConn tsMonitor = {0};
static bool monHasMnodeMaster = false; static int32_t monQueryReqNum = 0, monSubmitReqNum = 0;
static bool monHasMnodeMaster = false;
static void monSaveSystemInfo(); static void monSaveSystemInfo();
static void monSaveClusterInfo(); static void monSaveClusterInfo();
static void monSaveDnodesInfo(); static void monSaveDnodesInfo();
...@@ -396,7 +398,8 @@ static int32_t monBuildBandSql(char *sql) { ...@@ -396,7 +398,8 @@ static int32_t monBuildBandSql(char *sql) {
} }
static int32_t monBuildReqSql(char *sql) { static int32_t monBuildReqSql(char *sql) {
SStatisInfo info = dnodeGetStatisInfo(); //SStatisInfo info = dnodeGetStatisInfo();
SStatisInfo info = {0};
return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum); return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum);
} }
...@@ -429,6 +432,7 @@ static void monSaveSystemInfo() { ...@@ -429,6 +432,7 @@ static void monSaveSystemInfo() {
if (code != 0) { if (code != 0) {
monError("failed to save system info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); monError("failed to save system info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql);
} else { } else {
monIncSubmitReqCnt();
monDebug("successfully to save system info, sql:%s", tsMonitor.sql); monDebug("successfully to save system info, sql:%s", tsMonitor.sql);
} }
} }
...@@ -685,8 +689,8 @@ static int32_t monBuildReqRateSql(char *sql) { ...@@ -685,8 +689,8 @@ static int32_t monBuildReqRateSql(char *sql) {
float queryReqRate = info.queryReqNum / interval; float queryReqRate = info.queryReqNum / interval;
float submitReqRate = info.submitReqNum / interval; float submitReqRate = info.submitReqNum / interval;
return sprintf(sql, ", %d, %f, %d, %f, %d, %f", info.httpReqNum, httpReqRate, return sprintf(sql, ", %d, %f, %d, %f, %d, %f", info.httpReqNum, httpReqRate,
info.queryReqNum, queryReqRate, info.queryReqNum - monFetchQueryReqCnt(), queryReqRate,
info.submitReqNum, submitReqRate); info.submitReqNum - monFetchSubmitReqCnt(), submitReqRate);
} }
static int32_t monBuildDnodeErrorsSql(char *sql) { static int32_t monBuildDnodeErrorsSql(char *sql) {
...@@ -782,6 +786,7 @@ static void monSaveClusterInfo() { ...@@ -782,6 +786,7 @@ static void monSaveClusterInfo() {
if (code != 0) { if (code != 0) {
monError("failed to save cluster info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); monError("failed to save cluster info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql);
} else { } else {
monIncSubmitReqCnt();
monDebug("successfully to save cluster info, sql:%s", tsMonitor.sql); monDebug("successfully to save cluster info, sql:%s", tsMonitor.sql);
} }
} }
...@@ -811,6 +816,7 @@ static void monSaveDnodesInfo() { ...@@ -811,6 +816,7 @@ static void monSaveDnodesInfo() {
if (code != 0) { if (code != 0) {
monError("failed to save dnode_%d info, reason:%s, sql:%s", dnodeGetDnodeId(), tstrerror(code), tsMonitor.sql); monError("failed to save dnode_%d info, reason:%s, sql:%s", dnodeGetDnodeId(), tstrerror(code), tsMonitor.sql);
} else { } else {
monIncSubmitReqCnt();
monDebug("successfully to save dnode_%d info, sql:%s", dnodeGetDnodeId(), tsMonitor.sql); monDebug("successfully to save dnode_%d info, sql:%s", dnodeGetDnodeId(), tsMonitor.sql);
} }
} }
...@@ -893,6 +899,7 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) { ...@@ -893,6 +899,7 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) {
if (code != 0) { if (code != 0) {
monError("failed to save vgroup_%d info, reason:%s, sql:%s", vgId, tstrerror(code), tsMonitor.sql); monError("failed to save vgroup_%d info, reason:%s, sql:%s", vgId, tstrerror(code), tsMonitor.sql);
} else { } else {
monIncSubmitReqCnt();
monDebug("successfully to save vgroup_%d info, sql:%s", vgId, tsMonitor.sql); monDebug("successfully to save vgroup_%d info, sql:%s", vgId, tsMonitor.sql);
} }
} }
...@@ -968,10 +975,10 @@ static void monSaveSlowQueryInfo() { ...@@ -968,10 +975,10 @@ static void monSaveSlowQueryInfo() {
if (code != 0) { if (code != 0) {
monError("failed to save slowquery info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); monError("failed to save slowquery info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql);
} else { } else {
monIncSubmitReqCnt();
monDebug("successfully to save slowquery info, sql:%s", tsMonitor.sql); monDebug("successfully to save slowquery info, sql:%s", tsMonitor.sql);
} }
} }
static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) {
...@@ -979,6 +986,7 @@ static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { ...@@ -979,6 +986,7 @@ static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) {
if (c != TSDB_CODE_SUCCESS) { if (c != TSDB_CODE_SUCCESS) {
monError("save %s failed, reason:%s", (char *)param, tstrerror(c)); monError("save %s failed, reason:%s", (char *)param, tstrerror(c));
} else { } else {
monIncSubmitReqCnt();
int32_t rows = taos_affected_rows(result); int32_t rows = taos_affected_rows(result);
monDebug("save %s succ, rows:%d", (char *)param, rows); monDebug("save %s succ, rows:%d", (char *)param, rows);
} }
...@@ -1078,3 +1086,19 @@ void monExecuteSQLWithResultCallback(char *sql, MonExecuteSQLCbFP callback, void ...@@ -1078,3 +1086,19 @@ void monExecuteSQLWithResultCallback(char *sql, MonExecuteSQLCbFP callback, void
monDebug("execute sql:%s", sql); monDebug("execute sql:%s", sql);
taos_query_a(tsMonitor.conn, sql, callback, param); taos_query_a(tsMonitor.conn, sql, callback, param);
} }
void monIncQueryReqCnt() {
atomic_fetch_add_32(&monQueryReqNum, 1);
}
void monIncSubmitReqCnt() {
atomic_fetch_add_32(&monSubmitReqNum, 1);
}
int32_t monFetchQueryReqCnt() {
return atomic_exchange_32(&monQueryReqNum, 0);
}
int32_t monFetchSubmitReqCnt() {
return atomic_exchange_32(&monSubmitReqNum, 0);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册