'use strict';

const gcStats = require('gc-stats')();
const eventLoopStats = require('event-loop-stats');

const common = require('./common');


export class Metrics {
  constructor (period) {
    this.period = period;

    this.metrics = {};
    this.metrics.rss = 0;
    this.metrics.heapTotal = 0;
    this.metrics.heapUsed = 0;
  }

  runMeasures () {
    gcStats.on('stats', (stats) => {
      common.log(`GC happened ${JSON.stringify(stats)}`);
    });

    setInterval( () => {
      const mu = process.memoryUsage();
      this.metrics.rss = mu.rss;
      this.metrics.heapTotal = mu.heapTotal;
      this.metrics.heapUsed = mu.heapUsed;

      common.log(JSON.stringify(this.metrics));
      common.log(`event loop stats', ${JSON.stringify(eventLoopStats.sense())}`);

    }, this.period);
  }
}
@@ -8,16 +8,46 @@
 rict';%0A%0A
+const lynx = require('lynx');%0A
 const gc
@@ -242,17 +242,16 @@
 period;%0A
-%0A
     this
@@ -265,99 +265,35 @@
 s = 
-%7B%7D;%0A    this.metrics.rss = 0;%0A    this.metrics.heapTotal = 0;%0A    this.metrics.heapUsed = 0
+new lynx('localhost', 8125)
 ;%0A  
@@ -409,16 +409,495 @@
 ts)%7D%60);%0A
+      this.metrics.gauge('gc.pause_ms', stats.pauseMS);%0A%0A      this.metrics.gauge('gc.diff.total_heap_size', stats.diff.totalHeapSize);%0A      this.metrics.gauge('gc.diff.total_heap_executable_size', stats.diff.totalHeapExecutableSize);%0A      this.metrics.gauge('gc.diff.used_heap_size', stats.diff.usedHeapSize);%0A      this.metrics.gauge('gc.diff.heap_size_limit', stats.diff.heapSizeLimit);%0A      this.metrics.gauge('gc.diff.total_physical_size', stats.diff.totalPhysicalSize);%0A
     %7D);%0A
@@ -985,20 +985,43 @@
 ics.
-rss =
+gauge('process.memory.rss',
  mu.rss
+)
 ;%0A  
@@ -1041,19 +1041,42 @@
 ics.
+gauge('process.memory.
 heap
-T
+_t
 otal
- =
+',
  mu.
@@ -1084,16 +1084,17 @@
 eapTotal
+)
 ;%0A      
@@ -1110,18 +1110,41 @@
 ics.
+gauge('process.memory.
 heap
-Used =
+_used',
  mu.
@@ -1151,16 +1151,17 @@
 heapUsed
+)
 ;%0A%0A     
@@ -1167,127 +1167,251 @@
   co
-mmon.log(JSON.stringify(this.metrics));%0A      common.log(%60
+nst els = eventLoopStats.sense();%0A      this.metrics.gauge('event_loop.min', els.min);%0A      this.metrics.gauge('
 event
- 
+_
 loop
- stats', $%7BJSON.stringify(
+.max', els.max);%0A      this.metrics.gauge('event_loop.num', els.num);%0A      this.metrics.gauge('
 event
-LoopStats.sense())%7D%60
+_loop.sum', els.sum
 );%0A%0A

Use lynx and statsd