mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 03:21:18 +01:00
Plugin metrics (#7626)
* feat: add enable/disable checkbox for plugin usage * feat: submit plugin data to packages.nodebb.org only submit in production mode submit once every 24 hours dont submit for plugins that have "private": true in plugin.json enabled on new installs disabled on existing installs * fix: hash not working after first send fix statusCode * fix: remove url * feat: show compatibilty * feat: add install question for submit plugin usage
This commit is contained in:
committed by
GitHub
parent
3f4f8aface
commit
5fa5e999f8
@@ -15,6 +15,7 @@ var Plugins = module.exports;
|
||||
require('./install')(Plugins);
|
||||
require('./load')(Plugins);
|
||||
require('./hooks')(Plugins);
|
||||
require('./usage')(Plugins);
|
||||
Plugins.data = require('./data');
|
||||
|
||||
Plugins.getPluginPaths = Plugins.data.getPluginPaths;
|
||||
@@ -33,6 +34,7 @@ Plugins.libraryPaths = [];
|
||||
Plugins.versionWarning = [];
|
||||
Plugins.soundpacks = [];
|
||||
Plugins.languageData = {};
|
||||
Plugins.loadedPlugins = [];
|
||||
|
||||
Plugins.initialized = false;
|
||||
|
||||
@@ -105,6 +107,7 @@ Plugins.reload = function (callback) {
|
||||
Plugins.clientScripts.length = 0;
|
||||
Plugins.acpScripts.length = 0;
|
||||
Plugins.libraryPaths.length = 0;
|
||||
Plugins.loadedPlugins.length = 0;
|
||||
|
||||
async.waterfall([
|
||||
Plugins.getPluginPaths,
|
||||
|
||||
@@ -150,8 +150,16 @@ module.exports = function (Plugins) {
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error(err.stack);
|
||||
winston.verbose('[plugins] Could not load plugin : ' + pluginData.id);
|
||||
return callback(err);
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (!pluginData.private) {
|
||||
Plugins.loadedPlugins.push({
|
||||
id: pluginData.id,
|
||||
version: pluginData.version,
|
||||
});
|
||||
}
|
||||
|
||||
winston.verbose('[plugins] Loaded plugin: ' + pluginData.id);
|
||||
@@ -196,9 +204,8 @@ module.exports = function (Plugins) {
|
||||
callback();
|
||||
}
|
||||
} catch (err) {
|
||||
winston.error(err.stack);
|
||||
winston.warn('[plugins] Unable to parse library for: ' + pluginData.id);
|
||||
callback();
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
43
src/plugins/usage.js
Normal file
43
src/plugins/usage.js
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const nconf = require('nconf');
|
||||
const request = require('request');
|
||||
const winston = require('winston');
|
||||
const crypto = require('crypto');
|
||||
const cronJob = require('cron').CronJob;
|
||||
|
||||
const pkg = require('../../package.json');
|
||||
|
||||
const meta = require('../meta');
|
||||
|
||||
module.exports = function (Plugins) {
|
||||
Plugins.startJobs = function () {
|
||||
new cronJob('0 0 0 * * *', function () {
|
||||
Plugins.submitUsageData();
|
||||
}, null, true);
|
||||
};
|
||||
|
||||
Plugins.submitUsageData = function () {
|
||||
if (!meta.config.submitPluginUsage || !Plugins.loadedPlugins.length || global.env !== 'production') {
|
||||
return;
|
||||
}
|
||||
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(nconf.get('url'));
|
||||
request.post((nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugin/usage', {
|
||||
form: {
|
||||
id: hash.digest('hex'),
|
||||
version: pkg.version,
|
||||
plugins: Plugins.loadedPlugins,
|
||||
},
|
||||
timeout: 5000,
|
||||
}, function (err, res, body) {
|
||||
if (err) {
|
||||
return winston.error(err);
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
winston.error('[plugins.submitUsageData] received ' + res.statusCode + ' ' + body);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user