From 6bc47c314728d6d625e27c9707357d308b48f350 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Thu, 28 Apr 2016 16:09:10 -0400 Subject: [PATCH 01/15] Added more heap statistics --- README.md | 4 +++- src/monitor.cc | 8 ++++++++ src/monitor.h | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index be79cf3..3074c05 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ Here is the list of data the module reports periodically: utcstart: , events: ,, cpu: , - mem: , + mem: , + usedheap: , + totalheap: , cpuperreq: , oreqs: , sys_cpu: , diff --git a/src/monitor.cc b/src/monitor.cc index 5d1f1bf..af88155 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -404,6 +404,8 @@ void NodeMonitor::setStatistics() { Nan::GetHeapStatistics(&v8stats); stats_.pmem_ = (v8stats.used_heap_size() / (double) v8stats.total_heap_size()); + stats_.usedheap_ = v8stats.used_heap_size(); + stats_.totalheap_ = v8stats.total_heap_size(); } { // Obtains the CPU usage @@ -786,6 +788,12 @@ bool NodeMonitor::sendReport() { data.append(buffer); } + snprintf(buffer, sizeof(buffer), "\"usedheap\":%d,", stats.usedheap_); + data.append(buffer); + + snprintf(buffer, sizeof(buffer), "\"totalheap\":%d,", stats.totalheap_); + data.append(buffer); + // requests served since beginning snprintf(buffer, sizeof(buffer), "\"reqstotal\":%d,", stats.lastRequests_); data.append(buffer); diff --git a/src/monitor.h b/src/monitor.h index 71db212..fa2972c 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -224,6 +224,10 @@ typedef struct { volatile time_t healthStatusTimestamp_; volatile double pmem_; + + volatile int usedheap_; + + volatile int totalheap_; } Statistics; From 79974a273f2e70c7cbfbcbc5779e184ab8fa8ba7 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Thu, 28 Apr 2016 17:17:46 -0400 Subject: [PATCH 02/15] Increase stats reporting interval to 5 seconds --- src/monitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monitor.cc b/src/monitor.cc index af88155..45080d7 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -53,7 +53,7 @@ static bool _show_backtrace = false; //< default to false for performance // However, if there is no receiver on the other end (i.e. sendmsg() // returns -1), then the reporting thread will wait MAX_INACTIVITY_RETRIES // before trying again. -static const int REPORT_INTERVAL_MS = 1000; +static const int REPORT_INTERVAL_MS = 5000; static const int MAX_INACTIVITY_RETRIES = 5; /* globals used for signal catching, etc */ From cbfece6e978bb1c0e86a634c960a86617a565c45 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Thu, 28 Apr 2016 18:14:19 -0400 Subject: [PATCH 03/15] remove extra v8 lookup calls --- src/monitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monitor.cc b/src/monitor.cc index 45080d7..183da17 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -403,9 +403,9 @@ void NodeMonitor::setStatistics() { v8::HeapStatistics v8stats; Nan::GetHeapStatistics(&v8stats); - stats_.pmem_ = (v8stats.used_heap_size() / (double) v8stats.total_heap_size()); stats_.usedheap_ = v8stats.used_heap_size(); stats_.totalheap_ = v8stats.total_heap_size(); + stats_.pmem_ = (stats_.usedheap_ / (double) stats_.totalheap_); } { // Obtains the CPU usage From 151e124232ad64e2e227e644f0d6beb8bb970c2b Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Thu, 28 Apr 2016 18:17:07 -0400 Subject: [PATCH 04/15] Revert change of interval back to 1000 ms --- src/monitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monitor.cc b/src/monitor.cc index 183da17..c977a2b 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -53,7 +53,7 @@ static bool _show_backtrace = false; //< default to false for performance // However, if there is no receiver on the other end (i.e. sendmsg() // returns -1), then the reporting thread will wait MAX_INACTIVITY_RETRIES // before trying again. -static const int REPORT_INTERVAL_MS = 5000; +static const int REPORT_INTERVAL_MS = 1000; static const int MAX_INACTIVITY_RETRIES = 5; /* globals used for signal catching, etc */ From 80be9b211f27aba8d2f17dfe2b01c72523b681f7 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 01:29:47 -0400 Subject: [PATCH 05/15] Attempt at adding custom names --- lib/monitor.js | 14 +++++++++++++- src/monitor.cc | 21 +++++++++++++++++++++ src/monitor.h | 7 +++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/monitor.js b/lib/monitor.js index 7150584..0e0c4b1 100644 --- a/lib/monitor.js +++ b/lib/monitor.js @@ -119,12 +119,16 @@ function HealthStatus() { this._isDown = false; this._statusCode = 0; this._timestamp = 0; + this._name = ''; + this._id = ''; } -HealthStatus.prototype.setHealthStatus = function(isDown, statusCode) { +HealthStatus.prototype.setHealthStatus = function(isDown, statusCode, name, id) { this._isDown = Boolean(isDown); this._statusCode = parseInt(statusCode, 10); this._timestamp = Math.floor(Date.now()/1000); //convert to seconds + this._name = name || ''; + this._id = id || ''; }; function setupHealthStatus() { @@ -150,6 +154,14 @@ function setupHealthStatus() { process.monitor.getStatusDate = function() { return new Date(healthStatus._timestamp * 1000); }; + + process.monitor.getName = function() { + return healthStatus._name; + }; + + process.monitor.getId = function() { + return healthStatus._id; + }; } diff --git a/src/monitor.cc b/src/monitor.cc index c977a2b..3883bff 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -463,6 +463,8 @@ void NodeMonitor::setStatistics() { stats_.healthIsDown_ = getBooleanFunction("isDown"); stats_.healthStatusCode_ = getIntFunction("getStatusCode"); stats_.healthStatusTimestamp_ = (time_t) getIntFunction("getStatusTimestamp"); + stats_.healthName_ = getStringFunction("getName"); + stats_.healthId_ = getStringFunction("getId"); } @@ -686,6 +688,19 @@ bool NodeMonitor::getBooleanFunction(const char* funcName) { return false; } +// calls a Javascript function which returns a string +char* NodeMonitor::getStringFunction(const char* funcName) { + Nan::HandleScope scope; + Local res = callFunction(funcName); + String::Utf8Value cmd(res); + string s = string(*cmd); + return s; + // if (res->IsName()) { +// return res->BooleanValue(); +// } +// return ""; +} + NodeMonitor& NodeMonitor::getInstance() { assert( 0 != instance_ ); return *instance_; @@ -836,6 +851,12 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"health_status_code\":%d,", stats.healthStatusCode_); data.append(buffer); + + snprintf(buffer, sizeof(buffer), "\"health_status_name\":%s,", stats.healthName_); + data.append(buffer); + + snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); + data.append(buffer); } // append gc stats diff --git a/src/monitor.h b/src/monitor.h index fa2972c..158634e 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -221,6 +221,12 @@ typedef struct { // health status: statusCode volatile int healthStatusCode_; + // health status: name + volatile char* healthName_; + + // health status: id + volatile char* healthId_; + volatile time_t healthStatusTimestamp_; volatile double pmem_; @@ -302,6 +308,7 @@ class NodeMonitor { static int getIntFunction(const char* funcName); static bool getBooleanFunction(const char* funcName); + static char* getStringFunction(const char* funcName); static NodeMonitor* instance_; //< the singleton instance From 477aeb51136563a007659b6389e5f43d6fea9ef0 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 01:57:19 -0400 Subject: [PATCH 06/15] added healthName --- src/monitor.cc | 20 +++++++++++++------- src/monitor.h | 7 ++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/monitor.cc b/src/monitor.cc index 3883bff..1c4fbf2 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -464,7 +464,7 @@ void NodeMonitor::setStatistics() { stats_.healthStatusCode_ = getIntFunction("getStatusCode"); stats_.healthStatusTimestamp_ = (time_t) getIntFunction("getStatusTimestamp"); stats_.healthName_ = getStringFunction("getName"); - stats_.healthId_ = getStringFunction("getId"); +// stats_.healthId_ = getStringFunction("getId"); } @@ -689,12 +689,18 @@ bool NodeMonitor::getBooleanFunction(const char* funcName) { } // calls a Javascript function which returns a string -char* NodeMonitor::getStringFunction(const char* funcName) { +const char* NodeMonitor::getStringFunction(const char* funcName) { Nan::HandleScope scope; Local res = callFunction(funcName); - String::Utf8Value cmd(res); - string s = string(*cmd); - return s; + if(res->IsString()){ + String::Utf8Value cmd(res->ToString()); + std::string s = string(*cmd); +// return res->ToString(); + return s.c_str(); + } +// String::Utf8Value cmd(res); +// string s = string(*cmd); + return ""; // if (res->IsName()) { // return res->BooleanValue(); // } @@ -855,8 +861,8 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"health_status_name\":%s,", stats.healthName_); data.append(buffer); - snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); - data.append(buffer); +// snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); + // data.append(buffer); } // append gc stats diff --git a/src/monitor.h b/src/monitor.h index 158634e..306e05c 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -222,11 +222,8 @@ typedef struct { volatile int healthStatusCode_; // health status: name - volatile char* healthName_; + const char* healthName_; - // health status: id - volatile char* healthId_; - volatile time_t healthStatusTimestamp_; volatile double pmem_; @@ -308,7 +305,7 @@ class NodeMonitor { static int getIntFunction(const char* funcName); static bool getBooleanFunction(const char* funcName); - static char* getStringFunction(const char* funcName); + static const char* getStringFunction(const char* funcName); static NodeMonitor* instance_; //< the singleton instance From 9aca2f2c11aa342b1aafa0f61473d8cc0c7e0681 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:04:05 -0400 Subject: [PATCH 07/15] add quotes to json --- src/monitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monitor.cc b/src/monitor.cc index 1c4fbf2..8f30d1d 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -858,7 +858,7 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"health_status_code\":%d,", stats.healthStatusCode_); data.append(buffer); - snprintf(buffer, sizeof(buffer), "\"health_status_name\":%s,", stats.healthName_); + snprintf(buffer, sizeof(buffer), "\"health_status_name\":\"%s\",", stats.healthName_); data.append(buffer); // snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); From fe28946010effc9cf2c8e355750464727d84c355 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:20:02 -0400 Subject: [PATCH 08/15] Revert "add quotes to json" This reverts commit 9aca2f2c11aa342b1aafa0f61473d8cc0c7e0681. --- src/monitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monitor.cc b/src/monitor.cc index 8f30d1d..1c4fbf2 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -858,7 +858,7 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"health_status_code\":%d,", stats.healthStatusCode_); data.append(buffer); - snprintf(buffer, sizeof(buffer), "\"health_status_name\":\"%s\",", stats.healthName_); + snprintf(buffer, sizeof(buffer), "\"health_status_name\":%s,", stats.healthName_); data.append(buffer); // snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); From 124ef2362ee9123a4fa9561ef13cb853c5656078 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:20:09 -0400 Subject: [PATCH 09/15] Revert "added healthName" This reverts commit 477aeb51136563a007659b6389e5f43d6fea9ef0. --- src/monitor.cc | 20 +++++++------------- src/monitor.h | 7 +++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/monitor.cc b/src/monitor.cc index 1c4fbf2..3883bff 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -464,7 +464,7 @@ void NodeMonitor::setStatistics() { stats_.healthStatusCode_ = getIntFunction("getStatusCode"); stats_.healthStatusTimestamp_ = (time_t) getIntFunction("getStatusTimestamp"); stats_.healthName_ = getStringFunction("getName"); -// stats_.healthId_ = getStringFunction("getId"); + stats_.healthId_ = getStringFunction("getId"); } @@ -689,18 +689,12 @@ bool NodeMonitor::getBooleanFunction(const char* funcName) { } // calls a Javascript function which returns a string -const char* NodeMonitor::getStringFunction(const char* funcName) { +char* NodeMonitor::getStringFunction(const char* funcName) { Nan::HandleScope scope; Local res = callFunction(funcName); - if(res->IsString()){ - String::Utf8Value cmd(res->ToString()); - std::string s = string(*cmd); -// return res->ToString(); - return s.c_str(); - } -// String::Utf8Value cmd(res); -// string s = string(*cmd); - return ""; + String::Utf8Value cmd(res); + string s = string(*cmd); + return s; // if (res->IsName()) { // return res->BooleanValue(); // } @@ -861,8 +855,8 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"health_status_name\":%s,", stats.healthName_); data.append(buffer); -// snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); - // data.append(buffer); + snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); + data.append(buffer); } // append gc stats diff --git a/src/monitor.h b/src/monitor.h index 306e05c..158634e 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -222,8 +222,11 @@ typedef struct { volatile int healthStatusCode_; // health status: name - const char* healthName_; + volatile char* healthName_; + // health status: id + volatile char* healthId_; + volatile time_t healthStatusTimestamp_; volatile double pmem_; @@ -305,7 +308,7 @@ class NodeMonitor { static int getIntFunction(const char* funcName); static bool getBooleanFunction(const char* funcName); - static const char* getStringFunction(const char* funcName); + static char* getStringFunction(const char* funcName); static NodeMonitor* instance_; //< the singleton instance From 1993c5b9882bfec0e5925defd1cf20c27a4961cd Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:20:10 -0400 Subject: [PATCH 10/15] Revert "Attempt at adding custom names" This reverts commit 80be9b211f27aba8d2f17dfe2b01c72523b681f7. --- lib/monitor.js | 14 +------------- src/monitor.cc | 21 --------------------- src/monitor.h | 7 ------- 3 files changed, 1 insertion(+), 41 deletions(-) diff --git a/lib/monitor.js b/lib/monitor.js index 0e0c4b1..7150584 100644 --- a/lib/monitor.js +++ b/lib/monitor.js @@ -119,16 +119,12 @@ function HealthStatus() { this._isDown = false; this._statusCode = 0; this._timestamp = 0; - this._name = ''; - this._id = ''; } -HealthStatus.prototype.setHealthStatus = function(isDown, statusCode, name, id) { +HealthStatus.prototype.setHealthStatus = function(isDown, statusCode) { this._isDown = Boolean(isDown); this._statusCode = parseInt(statusCode, 10); this._timestamp = Math.floor(Date.now()/1000); //convert to seconds - this._name = name || ''; - this._id = id || ''; }; function setupHealthStatus() { @@ -154,14 +150,6 @@ function setupHealthStatus() { process.monitor.getStatusDate = function() { return new Date(healthStatus._timestamp * 1000); }; - - process.monitor.getName = function() { - return healthStatus._name; - }; - - process.monitor.getId = function() { - return healthStatus._id; - }; } diff --git a/src/monitor.cc b/src/monitor.cc index 3883bff..c977a2b 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -463,8 +463,6 @@ void NodeMonitor::setStatistics() { stats_.healthIsDown_ = getBooleanFunction("isDown"); stats_.healthStatusCode_ = getIntFunction("getStatusCode"); stats_.healthStatusTimestamp_ = (time_t) getIntFunction("getStatusTimestamp"); - stats_.healthName_ = getStringFunction("getName"); - stats_.healthId_ = getStringFunction("getId"); } @@ -688,19 +686,6 @@ bool NodeMonitor::getBooleanFunction(const char* funcName) { return false; } -// calls a Javascript function which returns a string -char* NodeMonitor::getStringFunction(const char* funcName) { - Nan::HandleScope scope; - Local res = callFunction(funcName); - String::Utf8Value cmd(res); - string s = string(*cmd); - return s; - // if (res->IsName()) { -// return res->BooleanValue(); -// } -// return ""; -} - NodeMonitor& NodeMonitor::getInstance() { assert( 0 != instance_ ); return *instance_; @@ -851,12 +836,6 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"health_status_code\":%d,", stats.healthStatusCode_); data.append(buffer); - - snprintf(buffer, sizeof(buffer), "\"health_status_name\":%s,", stats.healthName_); - data.append(buffer); - - snprintf(buffer, sizeof(buffer), "\"health_status_id\":%s,", stats.healthId_); - data.append(buffer); } // append gc stats diff --git a/src/monitor.h b/src/monitor.h index 158634e..fa2972c 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -221,12 +221,6 @@ typedef struct { // health status: statusCode volatile int healthStatusCode_; - // health status: name - volatile char* healthName_; - - // health status: id - volatile char* healthId_; - volatile time_t healthStatusTimestamp_; volatile double pmem_; @@ -308,7 +302,6 @@ class NodeMonitor { static int getIntFunction(const char* funcName); static bool getBooleanFunction(const char* funcName); - static char* getStringFunction(const char* funcName); static NodeMonitor* instance_; //< the singleton instance From 00c6c1544973629066a567f335f0c8d5825a5fdf Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:43:05 -0400 Subject: [PATCH 11/15] Added customName method --- src/monitor.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/monitor.cc b/src/monitor.cc index c977a2b..3a5b53e 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -47,6 +47,8 @@ using namespace v8; // This is the default IPC path where the stats are written to // Could use the setter method to change this static string _ipcMonitorPath = "/tmp/nodejs.mon"; +static string _customName = ""; + static bool _show_backtrace = false; //< default to false for performance // Normally reports will be sent every REPORT_INTERVAL_MS @@ -788,6 +790,9 @@ bool NodeMonitor::sendReport() { data.append(buffer); } + snprintf(buffer, sizeof(buffer), "\"custom_name\":\"%s\",", _customName.c_str()); + data.append(buffer); + snprintf(buffer, sizeof(buffer), "\"usedheap\":%d,", stats.usedheap_); data.append(buffer); @@ -1035,6 +1040,10 @@ static NAN_GETTER(GetterIPCMonitorPath) { info.GetReturnValue().Set(Nan::New(_ipcMonitorPath.c_str()).ToLocalChecked()); } +static NAN_GETTER(GetterCustomName) { + info.GetReturnValue().Set(Nan::New(_customName.c_str()).ToLocalChecked()); +} + static NAN_GETTER(GetterShowBackTrace) { info.GetReturnValue().Set(_show_backtrace); } @@ -1058,6 +1067,16 @@ static NAN_METHOD(SetterIPCMonitorPath) { info.GetReturnValue().SetUndefined(); } +static NAN_METHOD(SetterCustomName) { + if (info.Length() < 1 || + (!info[0]->IsString() && !info[0]->IsUndefined() && !info[0]->IsNull())) { + THROW_BAD_ARGS(); + } + String::Utf8Value customName(info[0]); + _customName = *customName; + info.GetReturnValue().SetUndefined(); +} + static NAN_METHOD(StartMonitor) { NodeMonitor::getInstance().Start(); info.GetReturnValue().SetUndefined(); @@ -1084,9 +1103,13 @@ NAN_MODULE_INIT(init) { Nan::SetAccessor( exports, Nan::New("ipcMonitorPath").ToLocalChecked(), GetterIPCMonitorPath, 0, v8::Local(), v8::PROHIBITS_OVERWRITING, v8::DontDelete ); + Nan::SetAccessor( exports, Nan::New("customName").ToLocalChecked(), + GetterCustomName, 0, v8::Local(), + v8::PROHIBITS_OVERWRITING, v8::DontDelete ); Nan::SetAccessor( exports, Nan::New("showBacktrace").ToLocalChecked(), GetterShowBackTrace, SetterShowBackTrace ); Nan::Export( exports, "setIpcMonitorPath", SetterIPCMonitorPath); + Nan::Export( exports, "setCustomName", SetterCustomName); Nan::Export( exports, "start", StartMonitor); Nan::Export( exports, "stop", StopMonitor); From cb7d565b1c15957838f939843b5980596973c15b Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:50:48 -0400 Subject: [PATCH 12/15] Added CustomID field --- src/monitor.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/monitor.cc b/src/monitor.cc index 3a5b53e..05ffd7d 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -48,6 +48,7 @@ using namespace v8; // Could use the setter method to change this static string _ipcMonitorPath = "/tmp/nodejs.mon"; static string _customName = ""; +static string _customId = ""; static bool _show_backtrace = false; //< default to false for performance @@ -793,6 +794,9 @@ bool NodeMonitor::sendReport() { snprintf(buffer, sizeof(buffer), "\"custom_name\":\"%s\",", _customName.c_str()); data.append(buffer); + snprintf(buffer, sizeof(buffer), "\"custom_id\":\"%s\",", _customId.c_str()); + data.append(buffer); + snprintf(buffer, sizeof(buffer), "\"usedheap\":%d,", stats.usedheap_); data.append(buffer); @@ -1044,6 +1048,10 @@ static NAN_GETTER(GetterCustomName) { info.GetReturnValue().Set(Nan::New(_customName.c_str()).ToLocalChecked()); } +static NAN_GETTER(GetterCustomId) { + info.GetReturnValue().Set(Nan::New(_customId.c_str()).ToLocalChecked()); +} + static NAN_GETTER(GetterShowBackTrace) { info.GetReturnValue().Set(_show_backtrace); } @@ -1077,6 +1085,16 @@ static NAN_METHOD(SetterCustomName) { info.GetReturnValue().SetUndefined(); } +static NAN_METHOD(SetterCustomId) { + if (info.Length() < 1 || + (!info[0]->IsString() && !info[0]->IsUndefined() && !info[0]->IsNull())) { + THROW_BAD_ARGS(); + } + String::Utf8Value customId(info[0]); + _customId = *customId; + info.GetReturnValue().SetUndefined(); +} + static NAN_METHOD(StartMonitor) { NodeMonitor::getInstance().Start(); info.GetReturnValue().SetUndefined(); @@ -1106,10 +1124,14 @@ NAN_MODULE_INIT(init) { Nan::SetAccessor( exports, Nan::New("customName").ToLocalChecked(), GetterCustomName, 0, v8::Local(), v8::PROHIBITS_OVERWRITING, v8::DontDelete ); + Nan::SetAccessor( exports, Nan::New("customId").ToLocalChecked(), + GetterCustomId, 0, v8::Local(), + v8::PROHIBITS_OVERWRITING, v8::DontDelete ); Nan::SetAccessor( exports, Nan::New("showBacktrace").ToLocalChecked(), GetterShowBackTrace, SetterShowBackTrace ); Nan::Export( exports, "setIpcMonitorPath", SetterIPCMonitorPath); Nan::Export( exports, "setCustomName", SetterCustomName); + Nan::Export( exports, "setCustomId", SetterCustomId); Nan::Export( exports, "start", StartMonitor); Nan::Export( exports, "stop", StopMonitor); From 106d4a81bc56d73aa8dd0a9be703d29c93994efd Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 02:56:58 -0400 Subject: [PATCH 13/15] Added getter for reportInterval --- src/monitor.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/monitor.cc b/src/monitor.cc index 05ffd7d..d024aaf 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -1048,6 +1048,10 @@ static NAN_GETTER(GetterCustomName) { info.GetReturnValue().Set(Nan::New(_customName.c_str()).ToLocalChecked()); } +static NAN_GETTER(GetterReportInterval) { + info.GetReturnValue().Set(Nan::New(REPORT_INTERVAL_MS)); +} + static NAN_GETTER(GetterCustomId) { info.GetReturnValue().Set(Nan::New(_customId.c_str()).ToLocalChecked()); } @@ -1127,6 +1131,9 @@ NAN_MODULE_INIT(init) { Nan::SetAccessor( exports, Nan::New("customId").ToLocalChecked(), GetterCustomId, 0, v8::Local(), v8::PROHIBITS_OVERWRITING, v8::DontDelete ); + Nan::SetAccessor( exports, Nan::New("reportInterval").ToLocalChecked(), + GetterReportInterval, 0, v8::Local(), + v8::PROHIBITS_OVERWRITING, v8::DontDelete ); Nan::SetAccessor( exports, Nan::New("showBacktrace").ToLocalChecked(), GetterShowBackTrace, SetterShowBackTrace ); Nan::Export( exports, "setIpcMonitorPath", SetterIPCMonitorPath); From 0b0de00e92a81ca68ec58460335353fc71dd06e3 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 03:09:52 -0400 Subject: [PATCH 14/15] Added interval setter --- src/monitor.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/monitor.cc b/src/monitor.cc index d024aaf..7ab3b2d 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -56,7 +56,7 @@ static bool _show_backtrace = false; //< default to false for performance // However, if there is no receiver on the other end (i.e. sendmsg() // returns -1), then the reporting thread will wait MAX_INACTIVITY_RETRIES // before trying again. -static const int REPORT_INTERVAL_MS = 1000; +static int REPORT_INTERVAL_MS = 1000; static const int MAX_INACTIVITY_RETRIES = 5; /* globals used for signal catching, etc */ @@ -1079,6 +1079,15 @@ static NAN_METHOD(SetterIPCMonitorPath) { info.GetReturnValue().SetUndefined(); } +static NAN_METHOD(SetterReportInterval) { + if (info.Length() < 1 || + (!info[0]->IsNumber() && !info[0]->IsUndefined() && !info[0]->IsNull())) { + THROW_BAD_ARGS(); + } + REPORT_INTERVAL_MS = info[0]->Uint32Value(); + info.GetReturnValue().SetUndefined(); +} + static NAN_METHOD(SetterCustomName) { if (info.Length() < 1 || (!info[0]->IsString() && !info[0]->IsUndefined() && !info[0]->IsNull())) { @@ -1137,6 +1146,7 @@ NAN_MODULE_INIT(init) { Nan::SetAccessor( exports, Nan::New("showBacktrace").ToLocalChecked(), GetterShowBackTrace, SetterShowBackTrace ); Nan::Export( exports, "setIpcMonitorPath", SetterIPCMonitorPath); + Nan::Export( exports, "setReportInterval", SetterReportInterval); Nan::Export( exports, "setCustomName", SetterCustomName); Nan::Export( exports, "setCustomId", SetterCustomId); Nan::Export( exports, "start", StartMonitor); From 4b1e2e2cf570f82c301de792e41704933e79f718 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 29 Apr 2016 03:17:33 -0400 Subject: [PATCH 15/15] Updated README with new methods --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 3074c05..06f1739 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,24 @@ monitor.setIpcMonitorPath('/tmp/my-process-stats.mon'); ``` Sets the datagram socket name to write the stats. Defaults to /tmp/nodejs.mon +## setReportInterval(ms) +```js +monitor.setReportInterval(1000); +``` +Sets the report interval. Defaults to 1000ms. Integer. + +## setCustomName(name) +```js +monitor.setCustomName("processname"); +``` +Sets the custom process name. This will be sent as custom_name inside the JSON payload. String. + +## setCustomId(id) +```js +monitor.setCustomName("process-id"); +``` +Sets the custom process id. This will be sent as custom_id inside the JSON payload. String. + # Health Status Monitr supports custom health functionality whereby the app can report its own health. The following methods are added to process.monitor to set and get the health information.