提交 09be95e4 编写于 作者: S Shengliang Guan

sysinfo for monitor

上级 09f27bdc
...@@ -92,11 +92,11 @@ typedef struct { ...@@ -92,11 +92,11 @@ typedef struct {
int64_t mem_engine; // KB int64_t mem_engine; // KB
int64_t mem_system; // KB int64_t mem_system; // KB
int64_t mem_total; // KB int64_t mem_total; // KB
float disk_engine; // GB int64_t disk_engine; // Byte
float disk_used; // GB int64_t disk_used; // Byte
float disk_total; // GB int64_t disk_total; // Byte
int64_t net_in; int64_t net_in; // Byte
int64_t net_out; int64_t net_out; // Byte
float io_read; float io_read;
float io_write; float io_write;
float io_read_disk; float io_read_disk;
......
...@@ -43,8 +43,8 @@ int32_t taosGetTotalMemory(int64_t *totalKB); ...@@ -43,8 +43,8 @@ int32_t taosGetTotalMemory(int64_t *totalKB);
int32_t taosGetProcMemory(int64_t *usedKB); int32_t taosGetProcMemory(int64_t *usedKB);
int32_t taosGetSysMemory(int64_t *usedKB); int32_t taosGetSysMemory(int64_t *usedKB);
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars); int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
int32_t taosGetProcIO(float *readKB, float *writeKB); int32_t taosGetProcIOSpeed(float *readKB, float *writeKB, float *readDiskKB, float *writeDiskKB);
int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes); int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes);
int32_t taosGetBandSpeed(float *bandSpeedKb); int32_t taosGetBandSpeed(float *bandSpeedKb);
......
...@@ -108,6 +108,7 @@ typedef struct { ...@@ -108,6 +108,7 @@ typedef struct {
SHashObj *hash; SHashObj *hash;
int32_t openVnodes; int32_t openVnodes;
int32_t totalVnodes; int32_t totalVnodes;
int32_t masterNum;
SRWLatch latch; SRWLatch latch;
SQWorkerPool queryPool; SQWorkerPool queryPool;
SFWorkerPool fetchPool; SFWorkerPool fetchPool;
......
...@@ -487,12 +487,10 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { ...@@ -487,12 +487,10 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
taosGetSysMemory(&pInfo->mem_system); taosGetSysMemory(&pInfo->mem_system);
pInfo->mem_total = tsTotalMemoryKB; pInfo->mem_total = tsTotalMemoryKB;
pInfo->disk_engine = 0; pInfo->disk_engine = 0;
pInfo->disk_used = tsDataSpace.size.used / (1024 * 1024 * 1024.0); pInfo->disk_used = tsDataSpace.size.used;
pInfo->disk_total = tsDataSpace.size.avail / (1024 * 1024 * 1024.0); pInfo->disk_total = tsDataSpace.size.avail;
taosGetCardInfo(NULL, &pInfo->net_in, &pInfo->net_out); taosGetCardInfo(NULL, &pInfo->net_in, &pInfo->net_out);
taosGetProcIO(&pInfo->io_read, &pInfo->io_write); taosGetProcIOSpeed(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
pInfo->io_read_disk = 0;
pInfo->io_write_disk = 0;
pInfo->req_select = 0; pInfo->req_select = 0;
pInfo->req_select_rate = 0; pInfo->req_select_rate = 0;
pInfo->req_insert = 0; pInfo->req_insert = 0;
...@@ -501,9 +499,9 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { ...@@ -501,9 +499,9 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
pInfo->req_insert_batch = 0; pInfo->req_insert_batch = 0;
pInfo->req_insert_batch_success = 0; pInfo->req_insert_batch_success = 0;
pInfo->req_insert_batch_rate = 0; pInfo->req_insert_batch_rate = 0;
pInfo->errors = 0; pInfo->errors = tsNumOfErrorLogs;
pInfo->vnodes_num = 0; pInfo->vnodes_num = pDnode->vmgmt.totalVnodes;
pInfo->masters = 0; pInfo->masters = pDnode->vmgmt.masterNum;
pInfo->has_mnode = dndIsMnode(pDnode); pInfo->has_mnode = dndIsMnode(pDnode);
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "dndVnodes.h" #include "dndVnodes.h"
#include "dndMgmt.h" #include "dndMgmt.h"
#include "dndTransport.h" #include "dndTransport.h"
#include "sync.h"
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
...@@ -979,6 +980,8 @@ void dndCleanupVnodes(SDnode *pDnode) { ...@@ -979,6 +980,8 @@ void dndCleanupVnodes(SDnode *pDnode) {
void dndGetVnodeLoads(SDnode *pDnode, SArray *pLoads) { void dndGetVnodeLoads(SDnode *pDnode, SArray *pLoads) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
int32_t totalVnodes = 0;
int32_t masterNum = 0;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
...@@ -993,8 +996,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SArray *pLoads) { ...@@ -993,8 +996,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SArray *pLoads) {
vnodeGetLoad(pVnode->pImpl, &vload); vnodeGetLoad(pVnode->pImpl, &vload);
taosArrayPush(pLoads, &vload); taosArrayPush(pLoads, &vload);
totalVnodes++;
if (vload.role == TAOS_SYNC_STATE_LEADER) masterNum++;
pIter = taosHashIterate(pMgmt->hash, pIter); pIter = taosHashIterate(pMgmt->hash, pIter);
} }
taosRUnLockLatch(&pMgmt->latch); taosRUnLockLatch(&pMgmt->latch);
pMgmt->totalVnodes = totalVnodes;
pMgmt->masterNum = masterNum;
} }
...@@ -124,52 +124,26 @@ int32_t taosGetBandSpeed(float *bandSpeedKb) { ...@@ -124,52 +124,26 @@ int32_t taosGetBandSpeed(float *bandSpeedKb) {
return 0; return 0;
} }
int32_t taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
IO_COUNTERS io_counter; IO_COUNTERS io_counter;
if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) {
if (readbyte) *readbyte = io_counter.ReadTransferCount; if (rchars) *rchars = io_counter.ReadTransferCount;
if (writebyte) *writebyte = io_counter.WriteTransferCount; if (wchars) *wchars = io_counter.WriteTransferCount;
if (read_bytes) *read_bytes = 0;
if (write_bytes) *write_bytes = 0;
return 0; return 0;
} }
return -1; return -1;
} }
int32_t taosGetProcIO(float *readKB, float *writeKB) {
static int64_t lastReadbyte = -1;
static int64_t lastWritebyte = -1;
int64_t curReadbyte = 0;
int64_t curWritebyte = 0;
if (taosReadProcIO(&curReadbyte, &curWritebyte) != 0) {
return -1;
}
if (lastReadbyte == -1 || lastWritebyte == -1) {
lastReadbyte = curReadbyte;
lastWritebyte = curWritebyte;
return -1;
}
*readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024);
*writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024);
if (*readKB < 0) *readKB = 0;
if (*writeKB < 0) *writeKB = 0;
lastReadbyte = curReadbyte;
lastWritebyte = curWritebyte;
return 0;
}
void taosGetSystemInfo() { void taosGetSystemInfo() {
taosGetCpuCores(&tsNumOfCores); taosGetCpuCores(&tsNumOfCores);
taosGetTotalMemory(&tsTotalMemoryKB); taosGetTotalMemory(&tsTotalMemoryKB);
float tmp1, tmp2; float tmp1, tmp2, tmp3, tmp4;
taosGetBandSpeed(&tmp1); taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2); taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2); taosGetProcIOSpeed(&tmp1, &tmp2, &tmp3, &tmp4);
} }
void taosKillSystem() { void taosKillSystem() {
...@@ -259,15 +233,11 @@ void taosGetSystemInfo() { ...@@ -259,15 +233,11 @@ void taosGetSystemInfo() {
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN); tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
} }
int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) { int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
if (rchars) *rchars = 0; if (rchars) *rchars = 0;
if (wchars) *wchars = 0; if (wchars) *wchars = 0;
return 0; if (read_bytes) *read_bytes = 0;
} if (write_bytes) *write_bytes = 0;
int32_t taosGetProcIO(float *readKB, float *writeKB) {
*readKB = 0;
*writeKB = 0;
return 0; return 0;
} }
...@@ -631,8 +601,7 @@ int32_t taosGetBandSpeed(float *bandSpeedKb) { ...@@ -631,8 +601,7 @@ int32_t taosGetBandSpeed(float *bandSpeedKb) {
return 0; return 0;
} }
int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) { int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
// FILE *fp = fopen(tsProcIOFile, "r");
TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) { if (pFile == NULL) {
// printf("open file:%s failed", tsProcIOFile); // printf("open file:%s failed", tsProcIOFile);
...@@ -655,16 +624,22 @@ int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) { ...@@ -655,16 +624,22 @@ int32_t 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 { } if (strstr(line, "read_bytes:") != NULL) {
sscanf(line, "%s %" PRId64, tmp, read_bytes);
readIndex++;
} else if (strstr(line, "write_bytes::") != NULL) {
sscanf(line, "%s %" PRId64, tmp, write_bytes);
readIndex++;
}else {
} }
if (readIndex >= 2) break; if (readIndex >= 4) break;
} }
if (line != NULL) tfree(line); if (line != NULL) tfree(line);
taosCloseFile(&pFile); taosCloseFile(&pFile);
if (readIndex < 2) { if (readIndex < 4) {
// printf("read file:%s failed", tsProcIOFile); // printf("read file:%s failed", tsProcIOFile);
return -1; return -1;
} }
...@@ -672,30 +647,43 @@ int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) { ...@@ -672,30 +647,43 @@ int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) {
return 0; return 0;
} }
int32_t taosGetProcIO(float *readKB, float *writeKB) { int32_t taosGetProcIOSpeed(float *readKB, float *writeKB, float *readDiskKB, float *writeDiskKB) {
static int64_t lastReadbyte = -1; static int64_t lastRchar = -1;
static int64_t lastWritebyte = -1; static int64_t lastWchar = -1;
static int64_t lastRbyte = -1;
static int64_t lastWbyte = -1;
int64_t curReadbyte = 0; int64_t curRchar = 0;
int64_t curWritebyte = 0; int64_t curWchar = 0;
int64_t curRbyte = 0;
int64_t curWbyte = 0;
if (taosReadProcIO(&curReadbyte, &curWritebyte) != 0) { if (taosReadProcIO(&curRchar, &curWchar, &curRbyte, &curWbyte) != 0) {
return -1; return -1;
} }
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 -1; return -1;
} }
*readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024); *readKB = (curRchar - lastRchar) / 1024.0f;
*writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024); *writeKB = (curWchar - lastWchar) / 1024.0f;
*readDiskKB = (curRbyte - lastRbyte) / 1024.0f;
*writeDiskKB = (curWbyte - lastWbyte) / 1024.0f;
if (*readKB < 0) *readKB = 0; if (*readKB < 0) *readKB = 0;
if (*writeKB < 0) *writeKB = 0; if (*writeKB < 0) *writeKB = 0;
if (*readDiskKB < 0) *readDiskKB = 0;
if (*writeDiskKB < 0) *writeDiskKB = 0;
lastReadbyte = curReadbyte; lastRchar = curRchar;
lastWritebyte = curWritebyte; lastWchar = curWchar;
lastRbyte = curRbyte;
lastWbyte = curWbyte;
return 0; return 0;
} }
...@@ -705,10 +693,10 @@ void taosGetSystemInfo() { ...@@ -705,10 +693,10 @@ void taosGetSystemInfo() {
taosGetCpuCores(&tsNumOfCores); taosGetCpuCores(&tsNumOfCores);
taosGetTotalMemory(&tsTotalMemoryKB); taosGetTotalMemory(&tsTotalMemoryKB);
float tmp1, tmp2; float tmp1, tmp2, tmp3, tmp4;
taosGetBandSpeed(&tmp1); taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2); taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2); taosGetProcIOSpeed(&tmp1, &tmp2, &tmp3, &tmp4);
} }
void taosKillSystem() { void taosKillSystem() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册