提交 fdb2a099 编写于 作者: G Ganlin Zhao

[TD-6452]<feature>: taoskeeper modified grants_info

上级 72fb4c61
...@@ -30,8 +30,8 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize); ...@@ -30,8 +30,8 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize);
int32_t taosGetCpuCores(); int32_t taosGetCpuCores();
void taosGetSystemInfo(); void taosGetSystemInfo();
bool taosReadProcIO(int64_t* rchars, int64_t* wchars); bool taosReadProcIO(int64_t* rchars, int64_t* wchars, int64_t* rbytes, int64_t* wbytes);
bool taosGetProcIO(float *readKB, float *writeKB); bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float* wbyteKB);
bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes); bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes);
bool taosGetBandSpeed(float *bandSpeedKb); bool taosGetBandSpeed(float *bandSpeedKb);
bool taosGetNetworkIO(float *netInKb, float *netOutKb); bool taosGetNetworkIO(float *netInKb, float *netOutKb);
......
...@@ -191,9 +191,11 @@ void taosGetSystemInfo() { ...@@ -191,9 +191,11 @@ void taosGetSystemInfo() {
taosGetSystemLocale(); taosGetSystemLocale();
} }
bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t *wbytes) {
if (rchars) *rchars = 0; if (rchars) *rchars = 0;
if (wchars) *wchars = 0; if (wchars) *wchars = 0;
if (rbytes) *rbytes = 0;
if (wbytes) *wbytes = 0;
return true; return true;
} }
......
...@@ -465,7 +465,7 @@ bool taosGetNetworkIO(float *netInKb, float *netOutKb) { ...@@ -465,7 +465,7 @@ bool taosGetNetworkIO(float *netInKb, float *netOutKb) {
return true; return true;
} }
bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t *wbytes) {
FILE *fp = fopen(tsProcIOFile, "r"); FILE *fp = fopen(tsProcIOFile, "r");
if (fp == NULL) { if (fp == NULL) {
uError("open file:%s failed", tsProcIOFile); uError("open file:%s failed", tsProcIOFile);
...@@ -475,7 +475,7 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { ...@@ -475,7 +475,7 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
ssize_t _bytes = 0; ssize_t _bytes = 0;
size_t len; size_t len;
char * line = NULL; char * line = NULL;
char tmp[10]; char tmp[15];
int readIndex = 0; int readIndex = 0;
while (!feof(fp)) { while (!feof(fp)) {
...@@ -491,16 +491,21 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { ...@@ -491,16 +491,21 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
} else if (strstr(line, "wchar:") != NULL) { } else if (strstr(line, "wchar:") != NULL) {
sscanf(line, "%s %" PRId64, tmp, wchars); sscanf(line, "%s %" PRId64, tmp, wchars);
readIndex++; readIndex++;
} else { } else if (strstr(line, "read_bytes:") != NULL){
sscanf(line, "%s %" PRId64, tmp, rbytes);
readIndex++;
} else if (strstr(line, "write_bytes:") != NULL){
sscanf(line, "%s %" PRId64, tmp, wbytes);
readIndex++;
} }
if (readIndex >= 2) break; if (readIndex >= 4) break;
} }
tfree(line); tfree(line);
fclose(fp); fclose(fp);
if (readIndex < 2) { if (readIndex < 4) {
uError("read file:%s failed", tsProcIOFile); uError("read file:%s failed", tsProcIOFile);
return false; return false;
} }
...@@ -508,30 +513,39 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { ...@@ -508,30 +513,39 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
return true; return true;
} }
bool taosGetProcIO(float *readKB, float *writeKB) { bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteKB) {
static int64_t lastReadbyte = -1; static int64_t lastRchar = -1, lastRbyte = -1;
static int64_t lastWritebyte = -1; static int64_t lastWchar = -1, lastWbyte = -1;
int64_t curReadbyte = 0; int64_t curRchar = 0, curRbyte = 0;
int64_t curWritebyte = 0; int64_t curWchar = 0, curWbyte = 0;
if (!taosReadProcIO(&curReadbyte, &curWritebyte)) { if (!taosReadProcIO(&curRchar, &curWchar, &curRbyte, &curWbyte)) {
return false; return false;
} }
if (lastReadbyte == -1 || lastWritebyte == -1) { if (lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) {
lastReadbyte = curReadbyte; lastRchar = curRchar;
lastWritebyte = curWritebyte; lastWchar = curWchar;
lastRbyte = curRbyte;
lastWbyte = curWbyte;
return false; return false;
} }
*readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024); *rcharKB = (float)((double)(curRchar - lastRchar) / 1024);
*writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024); *wcharKB = (float)((double)(curWchar - lastWchar) / 1024);
if (*readKB < 0) *readKB = 0; if (*rcharKB < 0) *rcharKB = 0;
if (*writeKB < 0) *writeKB = 0; if (*wcharKB < 0) *wcharKB = 0;
*rbyteKB = (float)((double)(curRbyte - lastRbyte) / 1024);
*wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024);
if (*rbyteKB < 0) *rbyteKB = 0;
if (*wbyteKB < 0) *wbyteKB = 0;
lastReadbyte = curReadbyte; lastRchar = curRchar;
lastWritebyte = curWritebyte; lastWchar = curWchar;
lastRbyte = curRbyte;
lastWbyte = curWbyte;
return true; return true;
} }
...@@ -542,13 +556,13 @@ void taosGetSystemInfo() { ...@@ -542,13 +556,13 @@ void taosGetSystemInfo() {
tsNumOfCores = taosGetCpuCores(); tsNumOfCores = taosGetCpuCores();
tsTotalMemoryMB = taosGetTotalMemory(); tsTotalMemoryMB = taosGetTotalMemory();
float tmp1, tmp2; float tmp1, tmp2, tmp3, tmp4;
taosGetSysMemory(&tmp1); taosGetSysMemory(&tmp1);
taosGetProcMemory(&tmp2); taosGetProcMemory(&tmp2);
// taosGetDisk(); // taosGetDisk();
taosGetBandSpeed(&tmp1); taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2); taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2); taosGetProcIO(&tmp1, &tmp2, &tmp3, &tmp4);
taosGetSystemTimezone(); taosGetSystemTimezone();
taosGetSystemLocale(); taosGetSystemLocale();
......
...@@ -123,9 +123,9 @@ bool metricsProcessRequest(HttpContext* pContext) { ...@@ -123,9 +123,9 @@ bool metricsProcessRequest(HttpContext* pContext) {
} }
{ {
int64_t rchars = 0; int64_t rchars = 0, rbytes = 0;
int64_t wchars = 0; int64_t wchars = 0, wbytes = 0;
bool succeeded = taosReadProcIO(&rchars, &wchars); bool succeeded = taosReadProcIO(&rchars, &wchars, &rbytes, &wbytes);
if (!succeeded) { if (!succeeded) {
httpError("failed to get io info"); httpError("failed to get io info");
} else { } else {
......
...@@ -148,9 +148,17 @@ typedef struct { ...@@ -148,9 +148,17 @@ typedef struct {
char sql[SQL_LENGTH + 1]; char sql[SQL_LENGTH + 1];
} SMonConn; } SMonConn;
typedef struct {
float io_read;
float io_write;
float io_read_disk;
float io_write_disk;
} SMonStat;
static void *monHttpStatusHashTable; static void *monHttpStatusHashTable;
static SMonConn tsMonitor = {0}; static SMonConn tsMonitor = {0};
static SMonStat tsMonStat = {0};
static int32_t monQueryReqNum = 0, monSubmitReqNum = 0; static int32_t monQueryReqNum = 0, monSubmitReqNum = 0;
static bool monHasMnodeMaster = false; static bool monHasMnodeMaster = false;
...@@ -163,6 +171,7 @@ static void monSaveDisksInfo(); ...@@ -163,6 +171,7 @@ static void monSaveDisksInfo();
static void monSaveGrantsInfo(); static void monSaveGrantsInfo();
static void monSaveHttpReqInfo(); static void monSaveHttpReqInfo();
static void monClearStatisInfo(); static void monClearStatisInfo();
static void monGetSysStats();
static void *monThreadFunc(void *param); static void *monThreadFunc(void *param);
static void monBuildMonitorSql(char *sql, int32_t cmd); static void monBuildMonitorSql(char *sql, int32_t cmd);
static void monInitHttpStatusHashTable(); static void monInitHttpStatusHashTable();
...@@ -300,6 +309,7 @@ static void *monThreadFunc(void *param) { ...@@ -300,6 +309,7 @@ static void *monThreadFunc(void *param) {
if (tsMonitor.state == MON_STATE_INITED) { if (tsMonitor.state == MON_STATE_INITED) {
if (accessTimes % tsMonitorInterval == 0 || accessTimes == 1) { if (accessTimes % tsMonitorInterval == 0 || accessTimes == 1) {
monGetSysStats();
//monSaveDnodesInfo has to be the first, as it calculates //monSaveDnodesInfo has to be the first, as it calculates
//stats using monSubmitReqNum before any insertion from monitor //stats using monSubmitReqNum before any insertion from monitor
monSaveDnodesInfo(); monSaveDnodesInfo();
...@@ -398,6 +408,7 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) { ...@@ -398,6 +408,7 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) {
", disk_engine float, disk_used float, disk_total float" ", disk_engine float, disk_used float, disk_total float"
", net_in float, net_out float" ", net_in float, net_out float"
", io_read float, io_write float" ", io_read float, io_write float"
", io_read_disk float, io_write_disk float"
", req_http int, req_http_rate float" ", req_http int, req_http_rate float"
", req_select int, req_select_rate float" ", req_select int, req_select_rate float"
", req_insert int, req_insert_success int, req_insert_rate float" ", req_insert int, req_insert_success int, req_insert_rate float"
...@@ -486,6 +497,15 @@ void monCleanupSystem() { ...@@ -486,6 +497,15 @@ void monCleanupSystem() {
monInfo("monitor module is cleaned up"); monInfo("monitor module is cleaned up");
} }
static void monGetSysStats() {
memset(&tsMonStat, 0, sizeof(SMonStat));
bool suc = taosGetProcIO(&tsMonStat.io_read, &tsMonStat.io_write,
&tsMonStat.io_read_disk, &tsMonStat.io_write_disk);
if (!suc) {
monDebug("failed to get io info");
}
}
// unit is MB // unit is MB
static int32_t monBuildMemorySql(char *sql) { static int32_t monBuildMemorySql(char *sql) {
float sysMemoryUsedMB = 0; float sysMemoryUsedMB = 0;
...@@ -541,10 +561,8 @@ static int32_t monBuildReqSql(char *sql) { ...@@ -541,10 +561,8 @@ static int32_t monBuildReqSql(char *sql) {
static int32_t monBuildIoSql(char *sql) { static int32_t monBuildIoSql(char *sql) {
float readKB = 0, writeKB = 0; float readKB = 0, writeKB = 0;
bool suc = taosGetProcIO(&readKB, &writeKB); readKB = tsMonStat.io_read;
if (!suc) { writeKB = tsMonStat.io_write;
monDebug("failed to get io info");
}
return sprintf(sql, ", %f, %f", readKB, writeKB); return sprintf(sql, ", %f, %f", readKB, writeKB);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册