Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Here is the list of data the module reports periodically:
utcstart: <when the process was started>,
events: <number of new reports being processed since last stats reporting>,,
cpu: <cpu usage>,
mem: <memory usage>,
mem: <ratio of used to total heap memory used>,
usedheap: <v8 heap memory used>,
totalheap: <v8 total heap size>,
cpuperreq: <cpu usage per request>,
oreqs: <current open requests count>,
sys_cpu: <system cpu load>,
Expand Down
10 changes: 9 additions & 1 deletion src/monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How expensive are these calls? Should we try to make them only once each?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes. that's probably a much better idea. I've updated the code to not do the extra call.

}

{ // Obtains the CPU usage
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ typedef struct {
volatile time_t healthStatusTimestamp_;

volatile double pmem_;

volatile int usedheap_;

volatile int totalheap_;
} Statistics;


Expand Down