commit
d2af3bd970
|
@ -34,11 +34,11 @@ typedef struct SMonInfo {
|
||||||
} SMonInfo;
|
} SMonInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_rwlock_t rwlock;
|
pthread_mutex_t lock;
|
||||||
SArray *logs; // array of SMonLogItem
|
SArray *logs; // array of SMonLogItem
|
||||||
int32_t maxLogs;
|
int32_t maxLogs;
|
||||||
const char *server;
|
const char *server;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
} SMonitor;
|
} SMonitor;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
static SMonitor tsMonitor = {0};
|
static SMonitor tsMonitor = {0};
|
||||||
|
|
||||||
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
||||||
pthread_rwlock_rdlock(&tsMonitor.rwlock);
|
pthread_mutex_lock(&tsMonitor.lock);
|
||||||
int32_t size = taosArrayGetSize(tsMonitor.logs);
|
int32_t size = taosArrayGetSize(tsMonitor.logs);
|
||||||
if (size >= tsMonitor.maxLogs) {
|
if (size >= tsMonitor.maxLogs) {
|
||||||
uInfo("too many logs for monitor");
|
uInfo("too many logs for monitor");
|
||||||
|
@ -34,7 +34,7 @@ void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
||||||
tstrncpy(pItem->content, content, sizeof(item.content));
|
tstrncpy(pItem->content, content, sizeof(item.content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_rwlock_unlock(&tsMonitor.rwlock);
|
pthread_mutex_unlock(&tsMonitor.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t monInit(const SMonCfg *pCfg) {
|
int32_t monInit(const SMonCfg *pCfg) {
|
||||||
|
@ -48,14 +48,14 @@ int32_t monInit(const SMonCfg *pCfg) {
|
||||||
tsMonitor.server = pCfg->server;
|
tsMonitor.server = pCfg->server;
|
||||||
tsMonitor.port = pCfg->port;
|
tsMonitor.port = pCfg->port;
|
||||||
tsLogFp = monRecordLog;
|
tsLogFp = monRecordLog;
|
||||||
pthread_rwlock_init(&tsMonitor.rwlock, NULL);
|
pthread_mutex_init(&tsMonitor.lock, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void monCleanup() {
|
void monCleanup() {
|
||||||
taosArrayDestroy(tsMonitor.logs);
|
taosArrayDestroy(tsMonitor.logs);
|
||||||
tsMonitor.logs = NULL;
|
tsMonitor.logs = NULL;
|
||||||
pthread_rwlock_wrlock(&tsMonitor.rwlock);
|
pthread_mutex_destroy(&tsMonitor.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMonInfo *monCreateMonitorInfo() {
|
SMonInfo *monCreateMonitorInfo() {
|
||||||
|
@ -65,10 +65,10 @@ SMonInfo *monCreateMonitorInfo() {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_rwlock_wrlock(&tsMonitor.rwlock);
|
pthread_mutex_lock(&tsMonitor.lock);
|
||||||
pMonitor->logs = taosArrayDup(tsMonitor.logs);
|
pMonitor->logs = taosArrayDup(tsMonitor.logs);
|
||||||
taosArrayClear(tsMonitor.logs);
|
taosArrayClear(tsMonitor.logs);
|
||||||
pthread_rwlock_unlock(&tsMonitor.rwlock);
|
pthread_mutex_unlock(&tsMonitor.lock);
|
||||||
|
|
||||||
pMonitor->pJson = tjsonCreateObject();
|
pMonitor->pJson = tjsonCreateObject();
|
||||||
if (pMonitor->pJson == NULL || pMonitor->logs == NULL) {
|
if (pMonitor->pJson == NULL || pMonitor->logs == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue