Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"iofog-controller": "src/main.js"
},
"dependencies": {
"@sentry/node": "4.5.3",
"body-parser": "1.18.3",
"child_process": "1.0.2",
"command-line-args": "5.0.2",
"command-line-usage": "5.0.5",
"continuation-local-storage": "3.2.1",
Expand All @@ -64,27 +66,26 @@
"ftp": "0.3.10",
"helmet": "3.15.0",
"jsonschema": "1.2.4",
"moment": "^2.24.0",
"morgan": "1.9.1",
"nconf": "0.10.0",
"newman": "4.3.1",
"nodemailer": "5.1.1",
"nodemailer-smtp-transport": "2.7.4",
"os": "0.1.1",
"path": "0.12.7",
"portscanner": "2.2.0",
"qs": "6.6.0",
"retry-as-promised": "3.1.0",
"semver": "5.6.0",
"sequelize": "4.42.0",
"sequelize-cli": "5.4.0",
"sqlite3": "4.0.6",
"string-format": "2.0.0",
"umzug": "2.2.0",
"underscore": "1.9.1",
"winston": "3.1.0",
"xss-clean": "0.1.1",
"qs": "6.6.0",
"child_process": "1.0.2",
"os": "0.1.1",
"semver": "5.6.0",
"newman": "4.3.1",
"@sentry/node": "4.5.3"
"xss-clean": "0.1.1"
},
"devDependencies": {
"automatic-release": "1.1.1",
Expand Down
35 changes: 25 additions & 10 deletions src/jobs/time-tracking-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,45 @@
*
*/

const moment = require('moment');

const BaseJobHandler = require('./base/base-job-handler');
const FogAccessTokenService = require('../services/iofog-access-token-service');
const logger = require('../logger');
const Tracking = require('../tracking');
const TrackingEventType = require('../enums/tracking-event-type');
const TransactionDecorator = require('../decorators/transaction-decorator');


const INTERVAL_MIN = 5;

class TimeTrackingJob extends BaseJobHandler {

constructor() {
super();
this.scheduleTime = intervalMin * 60 * 1000;
this.scheduleTime = INTERVAL_MIN * 60 * 1000;
this.startTime = moment.now();
}

run() {
setInterval(trackTime, this.scheduleTime);
setTimeout(this.trackTime, this.scheduleTime);
}
}

let iteration = 0;
const intervalMin = 5;
async trackTime() {
let agentsCount = 0
try {
const agents = await TransactionDecorator.generateFakeTransaction(FogAccessTokenService.all)();
agentsCount = (agents || []).length;
} catch (e) {
logger.warn('Unable to count ioFog agents')
}

const runningTime = moment().diff(this.startTime, 'minutes');
const event = Tracking.buildEvent(TrackingEventType.RUNNING_TIME, { runningTime, agentsCount });
await Tracking.processEvent(event);

async function trackTime() {
iteration++;
const runningTime = iteration * intervalMin;
const event = Tracking.buildEvent(TrackingEventType.RUNNING_TIME, runningTime,);
await Tracking.processEvent(event);
setTimeout(this.trackTime, this.scheduleTime);
}
}

module.exports = new TimeTrackingJob();
9 changes: 7 additions & 2 deletions src/services/iofog-access-token-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ async function updateAccessToken(fogUuid, newAccessToken, transaction) {
}, transaction);
}

async function all(transaction) {
return FogAccessTokenManager.findAll(null, transaction);
}

module.exports = {
generateAccessToken: generateAccessToken,
updateAccessToken: updateAccessToken
generateAccessToken,
updateAccessToken,
all,
};
17 changes: 14 additions & 3 deletions src/tracking/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ function buildEvent(eventType, res, args, functionName) {
eventInfo.data = {event: 'user created'};
break;
case EventTypes.RUNNING_TIME:
eventInfo.data = {event: `${res} min`};
eventInfo.data = {
event: `${res.runningTime} min`,
agentsCount: res.agentsCount,
};
break;
case EventTypes.IOFOG_CREATED:
eventInfo.data = {event: 'iofog agent created'};
Expand Down Expand Up @@ -101,13 +104,21 @@ function sendEvents(events) {

function getUniqueTrackingUuid() {
let uuid;

try {
let allMacs = '';
const interfaces = os.networkInterfaces();
for (const i in interfaces) {
if (!i.internal) {
allMacs += i.mac + '-'
let networkInterface = interfaces[i];
if (Array.isArray(networkInterface)) {
networkInterface = networkInterface.length > 0 ? networkInterface[0] : null;
}

if (!networkInterface || networkInterface.internal) {
continue;
}

allMacs += networkInterface.mac + '-';
}
uuid = crypto.createHash('md5').update(allMacs).digest("hex");
} catch (e) {
Expand Down