Commit 784b4868 authored by NGPixel's avatar NGPixel

feat: telemetry module

parent b11a90cc
......@@ -17,7 +17,6 @@ import store from './store'
// ====================================
import localization from './modules/localization'
import telemetry from './modules/telemetry'
// ====================================
// Load Helpers
......
......@@ -121,7 +121,7 @@ export default {
}
this.$helpers._.delay(() => {
axios.post('/syscheck').then(resp => {
axios.post('/syscheck', self.conf).then(resp => {
if (resp.data.ok === true) {
self.syscheck.ok = true
self.syscheck.results = resp.data.results
......
import GRAPHQL from './graphql'
import TELEMETRY from './telemetry'
export default {
GRAPHQL,
TELEMETRY
GRAPHQL
}
export default {
GA_ID: 'UA-9094100-7',
GA_REMOTE: 'http://www.google-analytics.com/collect'
}
import uuid from 'uuid/v4'
/* global CONSTANTS, wiki */
export default {
cid: '',
init() {
this.cid = uuid()
},
sendEvent() {
wiki.$http.post(CONSTANTS.TELEMETRY.GA_REMOTE, {
v: 1, // API version
tid: CONSTANTS.TELEMETRY.GA_ID, // Tracking ID
aip: 1, // Anonymize IP
ds: 'server', // Data source
t: 'event', // Hit Type
ec: 'setup', // Event Category
ea: 'start', // Event Action
el: 'success', // Event Label
ev: 1 // Event Value
}).then(resp => {
}, err => {
console.error(err)
})
}
}
......@@ -43,6 +43,7 @@
"bcryptjs-then": "1.0.1",
"bluebird": "3.5.1",
"body-parser": "1.18.2",
"bugsnag": "2.0.0",
"bull": "3.3.0",
"bunyan": "1.8.12",
"cheerio": "1.0.0-rc.2",
......
......@@ -39,6 +39,11 @@ configNamespaces:
queues:
- gitSync
- uplClearTemp
telemetry:
BUGSNAG_ID: 'bb4b324d0675bcbba10025617fd2cec8'
BUGSNAG_REMOTE: 'https://notify.bugsnag.com'
GA_ID: 'UA-9094100-7'
GA_REMOTE: 'https://www.google-analytics.com/collect'
authProviders:
- local
- microsoft
......
......@@ -22,6 +22,7 @@ module.exports = () => {
const yaml = require('js-yaml')
const _ = require('lodash')
const cfgHelper = require('./helpers/config')
const filesize = require('filesize.js')
// ----------------------------------------
// Define Express App
......@@ -59,7 +60,10 @@ module.exports = () => {
app.get('*', (req, res) => {
fs.readJsonAsync(path.join(wiki.ROOTPATH, 'package.json')).then(packageObj => {
res.render('configure/index', { packageObj })
res.render('configure/index', {
packageObj,
telemetryClientID: wiki.telemetry.cid
})
})
})
......@@ -67,6 +71,9 @@ module.exports = () => {
* Perform basic system checks
*/
app.post('/syscheck', (req, res) => {
wiki.telemetry.enabled = (req.body.telemetry === true)
wiki.telemetry.sendEvent('setup', 'start')
Promise.mapSeries([
() => {
const semver = require('semver')
......@@ -103,7 +110,7 @@ module.exports = () => {
if (os.totalmem() < 1000 * 1000 * 512) {
throw new Error('Not enough memory. Minimum is 512 MB.')
}
return _.round(os.totalmem() / (1024 * 1024)) + ' MB of system memory available. Minimum is 512 MB.'
return filesize(os.totalmem()) + ' of system memory available. Minimum is 512 MB.'
},
() => {
let fs = require('fs')
......@@ -124,6 +131,8 @@ module.exports = () => {
* Check the Git connection
*/
app.post('/gitcheck', (req, res) => {
wiki.telemetry.sendEvent('setup', 'gitcheck')
const exec = require('execa')
const url = require('url')
......@@ -212,6 +221,8 @@ module.exports = () => {
* Finalize
*/
app.post('/finalize', (req, res) => {
wiki.telemetry.sendEvent('setup', 'finalize')
const bcrypt = require('bcryptjs-then')
const crypto = Promise.promisifyAll(require('crypto'))
let mongo = require('mongodb').MongoClient
......@@ -359,6 +370,7 @@ module.exports = () => {
error: wiki.IS_DEBUG ? err : {}
})
wiki.logger.error(err.message)
wiki.telemetry.sendError(err)
})
// ----------------------------------------
......
......@@ -2,9 +2,6 @@
/* global wiki */
module.exports = false
return
const express = require('express')
const router = express.Router()
......
......@@ -31,6 +31,12 @@ wiki.configSvc.init()
wiki.logger = require('./modules/logger').init()
// ----------------------------------------
// Init Telemetry
// ----------------------------------------
wiki.telemetry = require('./modules/telemetry').init()
// ----------------------------------------
// Init DB
// ----------------------------------------
......
......@@ -37,19 +37,15 @@ module.exports = {
appconfig = _.defaultsDeep(appconfig, appdata.defaults.config)
// Check port
if (appconfig.port < 1) {
appconfig.port = process.env.PORT || 80
}
// Convert booleans
appconfig.public = (appconfig.public === true || _.toLower(appconfig.public) === 'true')
// List authentication strategies
wiki.config = appconfig
wiki.data = appdata
wiki.version = require(path.join(wiki.ROOTPATH, 'package.json')).version
},
/**
......
const axios = require('axios')
const bugsnag = require('bugsnag')
const path = require('path')
const uuid = require('uuid/v4')
const _ = require('lodash')
/* global wiki */
module.exports = {
cid: '',
enabled: false,
init() {
this.cid = uuid()
bugsnag.register(wiki.data.telemetry.BUGSNAG_ID, {
appVersion: wiki.version,
autoNotify: false,
hostname: this.cid,
notifyReleaseStages: ['production'],
packageJSON: path.join(wiki.ROOTPATH, 'package.json'),
projectRoot: wiki.ROOTPATH,
useSSL: true
})
bugsnag.onBeforeNotify((notification, originalError) => {
if (!this.enabled) { return false }
})
if (_.get(wiki.config, 'logging.telemetry', false) === true) {
this.enabled = true
}
return this
},
sendError(err) {
bugsnag.notify(err)
},
sendEvent(eventCategory, eventAction, eventLabel) {
if (!this.enabled) { return false }
axios({
method: 'post',
url: wiki.data.telemetry.GA_REMOTE,
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
params: {
v: 1, // API version
tid: wiki.data.telemetry.GA_ID, // Tracking ID
aip: 1, // Anonymize IP
ds: 'server', // Data source
cid: this.cid, // Client ID
t: 'event', // Hit Type
ec: eventCategory, // Event Category
ea: eventAction, // Event Action
el: eventLabel // Event Label
}
}).then(resp => {
if (resp.status !== 200) {
wiki.logger.warn('Unable to send analytics telemetry request.')
}
}, err => {
wiki.logger.warn('Unable to send analytics telemetry request.')
})
}
}
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment