Skip to content

Commit

Permalink
feat: add metrics to analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjeffos committed Nov 2, 2020
1 parent 27fd89f commit 79b27bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const osName = require('os-name');
const crypto = require('crypto');
const uuid = require('uuid');
const stripAnsi = require('strip-ansi');
const { MetricsCollector } = require('./metrics');

const metadata = {};
// analytics module is required at the beginning of the CLI run cycle
Expand Down Expand Up @@ -86,6 +87,15 @@ function postAnalytics(data) {
data.ci = isCI();
data.durationMs = Date.now() - startTime;

try {
const networkTime = MetricsCollector.NETWORK_TIME.getTotal();
const cpuTime = data.durationMs - networkTime;
MetricsCollector.CPU_TIME.createInstance().setValue(cpuTime);
data.metrics = MetricsCollector.getAllMetrics();
} catch (err) {
debug('Error with metrics', err);
}

const queryStringParams = {};
if (data.org) {
queryStringParams.org = data.org;
Expand Down
3 changes: 3 additions & 0 deletions test/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test('analytics', (t) => {
'id',
'ci',
'metadata',
'metrics',
'args',
'nodeVersion',
'standalone',
Expand Down Expand Up @@ -120,6 +121,7 @@ test('analytics with args', (t) => {
'id',
'ci',
'metadata',
'metrics',
'args',
'nodeVersion',
'standalone',
Expand Down Expand Up @@ -160,6 +162,7 @@ test('analytics with args and org', (t) => {
'id',
'ci',
'metadata',
'metrics',
'args',
'nodeVersion',
'standalone',
Expand Down

0 comments on commit 79b27bb

Please sign in to comment.