Show Nodejs heap stats only at Standalone WeKan.

Not shown at Sandstorm WeKan, because there's a bunch of machine performance data
Sandstorm doesn't expose to apps to prevent side channel attacks.

Thanks to ocdtrekkie and xet7 !

Fixes #4154
reviewable/pr4157/r1
Lauri Ojansivu 4 years ago
parent 6d719b8a98
commit 02b6df320f
  1. 91
      client/components/settings/informationBody.jade
  2. 55
      server/statistics.js

@ -65,48 +65,49 @@ template(name='statistics')
tr
th {{_ 'OS_Cpus'}}
td {{statistics.os.cpus.length}}
tr
th {{_ 'Node_heap_total_heap_size'}}
td {{bytesToSize statistics.nodeHeapStats.totalHeapSize}}
tr
th {{_ 'Node_heap_total_heap_size_executable'}}
td {{bytesToSize statistics.nodeHeapStats.totalHeapSizeExecutable}}
tr
th {{_ 'Node_heap_total_physical_size'}}
td {{bytesToSize statistics.nodeHeapStats.totalPhysicalSize}}
tr
th {{_ 'Node_heap_total_available_size'}}
td {{bytesToSize statistics.nodeHeapStats.totalAvailableSize}}
tr
th {{_ 'Node_heap_used_heap_size'}}
td {{bytesToSize statistics.nodeHeapStats.usedHeapSize}}
tr
th {{_ 'Node_heap_heap_size_limit'}}
td {{bytesToSize statistics.nodeHeapStats.heapSizeLimit}}
tr
th {{_ 'Node_heap_malloced_memory'}}
td {{bytesToSize statistics.nodeHeapStats.mallocedMemory}}
tr
th {{_ 'Node_heap_peak_malloced_memory'}}
td {{bytesToSize statistics.nodeHeapStats.peakMallocedMemory}}
tr
th {{_ 'Node_heap_does_zap_garbage'}}
td {{statistics.nodeHeapStats.doesZapGarbage}}
tr
th {{_ 'Node_heap_number_of_native_contexts'}}
td {{statistics.nodeHeapStats.numberOfNativeContexts}}
tr
th {{_ 'Node_heap_number_of_detached_contexts'}}
td {{statistics.nodeHeapStats.numberOfDetachedContexts}}
tr
th {{_ 'Node_memory_usage_rss'}}
td {{bytesToSize statistics.nodeMemoryUsage.rss}}
tr
th {{_ 'Node_memory_usage_heap_total'}}
td {{bytesToSize statistics.nodeMemoryUsage.heapTotal}}
tr
th {{_ 'Node_memory_usage_heap_used'}}
td {{bytesToSize statistics.nodeMemoryUsage.heapUsed}}
tr
th {{_ 'Node_memory_usage_external'}}
td {{bytesToSize statistics.nodeMemoryUsage.external}}
unless isSandstorm
tr
th {{_ 'Node_heap_total_heap_size'}}
td {{bytesToSize statistics.nodeHeapStats.totalHeapSize}}
tr
th {{_ 'Node_heap_total_heap_size_executable'}}
td {{bytesToSize statistics.nodeHeapStats.totalHeapSizeExecutable}}
tr
th {{_ 'Node_heap_total_physical_size'}}
td {{bytesToSize statistics.nodeHeapStats.totalPhysicalSize}}
tr
th {{_ 'Node_heap_total_available_size'}}
td {{bytesToSize statistics.nodeHeapStats.totalAvailableSize}}
tr
th {{_ 'Node_heap_used_heap_size'}}
td {{bytesToSize statistics.nodeHeapStats.usedHeapSize}}
tr
th {{_ 'Node_heap_heap_size_limit'}}
td {{bytesToSize statistics.nodeHeapStats.heapSizeLimit}}
tr
th {{_ 'Node_heap_malloced_memory'}}
td {{bytesToSize statistics.nodeHeapStats.mallocedMemory}}
tr
th {{_ 'Node_heap_peak_malloced_memory'}}
td {{bytesToSize statistics.nodeHeapStats.peakMallocedMemory}}
tr
th {{_ 'Node_heap_does_zap_garbage'}}
td {{statistics.nodeHeapStats.doesZapGarbage}}
tr
th {{_ 'Node_heap_number_of_native_contexts'}}
td {{statistics.nodeHeapStats.numberOfNativeContexts}}
tr
th {{_ 'Node_heap_number_of_detached_contexts'}}
td {{statistics.nodeHeapStats.numberOfDetachedContexts}}
tr
th {{_ 'Node_memory_usage_rss'}}
td {{bytesToSize statistics.nodeMemoryUsage.rss}}
tr
th {{_ 'Node_memory_usage_heap_total'}}
td {{bytesToSize statistics.nodeMemoryUsage.heapTotal}}
tr
th {{_ 'Node_memory_usage_heap_used'}}
td {{bytesToSize statistics.nodeMemoryUsage.heapUsed}}
tr
th {{_ 'Node_memory_usage_external'}}
td {{bytesToSize statistics.nodeMemoryUsage.external}}

@ -1,5 +1,10 @@
import { MongoInternals } from 'meteor/mongo';
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
// in the package definition.
const isSandstorm =
Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm;
if (Meteor.isServer) {
Meteor.methods({
getStatistics() {
@ -28,27 +33,35 @@ if (Meteor.isServer) {
pid: process.pid,
uptime: process.uptime(),
};
const v8 = require('v8'); // Import the v8 module
statistics.nodeHeapStats = {
totalHeapSize: v8.getHeapStatistics().total_heap_size,
totalHeapSizeExecutable: v8.getHeapStatistics().total_heap_size_executable,
totalPhysicalSize: v8.getHeapStatistics().total_physical_size,
totalAvailableSize: v8.getHeapStatistics().total_available_size,
usedHeapSize: v8.getHeapStatistics().used_heap_size,
heapSizeLimit: v8.getHeapStatistics().heap_size_limit,
mallocedMemory: v8.getHeapStatistics().malloced_memory,
peakMallocedMemory: v8.getHeapStatistics().peak_malloced_memory,
doesZapGarbage: v8.getHeapStatistics().does_zap_garbage,
numberOfNativeContexts: v8.getHeapStatistics().number_of_native_contexts,
numberOfDetachedContexts: v8.getHeapStatistics().number_of_detached_contexts,
};
let memoryUsage = process.memoryUsage();
statistics.nodeMemoryUsage = {
rss: memoryUsage.rss,
heapTotal: memoryUsage.heapTotal,
heapUsed: memoryUsage.heapUsed,
external: memoryUsage.external,
};
// Start: Show Nodejs heap stats at Standalone WeKan.
//
// Not shown at Sandstorm WeKan, because there's a bunch of machine performance data
// Sandstorm doesn't expose to apps to prevent side channel attacks.
if (!isSandstorm) {
const v8 = require('v8'); // Import the v8 module
statistics.nodeHeapStats = {
totalHeapSize: v8.getHeapStatistics().total_heap_size,
totalHeapSizeExecutable: v8.getHeapStatistics().total_heap_size_executable,
totalPhysicalSize: v8.getHeapStatistics().total_physical_size,
totalAvailableSize: v8.getHeapStatistics().total_available_size,
usedHeapSize: v8.getHeapStatistics().used_heap_size,
heapSizeLimit: v8.getHeapStatistics().heap_size_limit,
mallocedMemory: v8.getHeapStatistics().malloced_memory,
peakMallocedMemory: v8.getHeapStatistics().peak_malloced_memory,
doesZapGarbage: v8.getHeapStatistics().does_zap_garbage,
numberOfNativeContexts: v8.getHeapStatistics().number_of_native_contexts,
numberOfDetachedContexts: v8.getHeapStatistics().number_of_detached_contexts,
};
let memoryUsage = process.memoryUsage();
statistics.nodeMemoryUsage = {
rss: memoryUsage.rss,
heapTotal: memoryUsage.heapTotal,
heapUsed: memoryUsage.heapUsed,
external: memoryUsage.external,
};
}
// End: Show Nodejs heap stats at Standalone WeKan.
//
// Remove beginning of Meteor release text METEOR@
let meteorVersion = Meteor.release;
meteorVersion = meteorVersion.replace('METEOR@', '');

Loading…
Cancel
Save