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

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

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