added agent to server metrics (#1321)
This commit is contained in:
parent
19ac0480ee
commit
f603f40f43
|
@ -68,6 +68,7 @@ Server events allow us to aggregate data about file lifecycle without collecting
|
||||||
* `event_properties`
|
* `event_properties`
|
||||||
* `download_count` downloads completed
|
* `download_count` downloads completed
|
||||||
* `ttl` time remaining before expiry truncated to hour
|
* `ttl` time remaining before expiry truncated to hour
|
||||||
|
* `agent` the browser name or first 6 characters of the user agent that made the request
|
||||||
|
|
||||||
### Client Events
|
### Client Events
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@ function statUploadEvent(data) {
|
||||||
size: orderOfMagnitude(data.size),
|
size: orderOfMagnitude(data.size),
|
||||||
anonymous: data.anonymous
|
anonymous: data.anonymous
|
||||||
},
|
},
|
||||||
|
event_properties: {
|
||||||
|
agent: data.agent
|
||||||
|
},
|
||||||
event_id: 0
|
event_id: 0
|
||||||
};
|
};
|
||||||
return sendBatch([event]);
|
return sendBatch([event]);
|
||||||
|
@ -61,6 +64,7 @@ function statDownloadEvent(data) {
|
||||||
time: truncateToHour(Date.now()),
|
time: truncateToHour(Date.now()),
|
||||||
event_type: 'server_download',
|
event_type: 'server_download',
|
||||||
event_properties: {
|
event_properties: {
|
||||||
|
agent: data.agent,
|
||||||
download_count: data.download_count,
|
download_count: data.download_count,
|
||||||
ttl: data.ttl
|
ttl: data.ttl
|
||||||
},
|
},
|
||||||
|
@ -80,6 +84,7 @@ function statDeleteEvent(data) {
|
||||||
time: truncateToHour(Date.now()),
|
time: truncateToHour(Date.now()),
|
||||||
event_type: 'server_delete',
|
event_type: 'server_delete',
|
||||||
event_properties: {
|
event_properties: {
|
||||||
|
agent: data.agent,
|
||||||
download_count: data.download_count,
|
download_count: data.download_count,
|
||||||
ttl: data.ttl
|
ttl: data.ttl
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,6 +12,7 @@ const ID_REGEX = '([0-9a-fA-F]{10, 16})';
|
||||||
module.exports = function(app, devServer) {
|
module.exports = function(app, devServer) {
|
||||||
const wsapp = express();
|
const wsapp = express();
|
||||||
expressWs(wsapp, null, { perMessageDeflate: false });
|
expressWs(wsapp, null, { perMessageDeflate: false });
|
||||||
|
routes(wsapp);
|
||||||
wsapp.ws('/api/ws', require('../routes/ws'));
|
wsapp.ws('/api/ws', require('../routes/ws'));
|
||||||
wsapp.listen(8081, config.listen_address);
|
wsapp.listen(8081, config.listen_address);
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ if (config.sentry_dsn) {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
expressWs(app, null, { perMessageDeflate: false });
|
expressWs(app, null, { perMessageDeflate: false });
|
||||||
app.ws('/api/ws', require('../routes/ws'));
|
|
||||||
routes(app);
|
routes(app);
|
||||||
|
app.ws('/api/ws', require('../routes/ws'));
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
express.static(path.resolve(__dirname, '../../dist/'), {
|
express.static(path.resolve(__dirname, '../../dist/'), {
|
||||||
|
|
|
@ -7,8 +7,8 @@ const expressWs = require('express-ws');
|
||||||
module.exports = function(app, devServer) {
|
module.exports = function(app, devServer) {
|
||||||
assets.setMiddleware(devServer.middleware);
|
assets.setMiddleware(devServer.middleware);
|
||||||
expressWs(app, null, { perMessageDeflate: false });
|
expressWs(app, null, { perMessageDeflate: false });
|
||||||
app.ws('/api/ws', require('../routes/ws'));
|
|
||||||
routes(app);
|
routes(app);
|
||||||
|
app.ws('/api/ws', require('../routes/ws'));
|
||||||
tests(app);
|
tests(app);
|
||||||
// webpack-dev-server routes haven't been added yet
|
// webpack-dev-server routes haven't been added yet
|
||||||
// so wait for next tick to add 404 handler
|
// so wait for next tick to add 404 handler
|
||||||
|
|
|
@ -13,7 +13,8 @@ module.exports = async function(req, res) {
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
owner: meta.owner,
|
owner: meta.owner,
|
||||||
download_count: meta.dl,
|
download_count: meta.dl,
|
||||||
ttl
|
ttl,
|
||||||
|
agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
|
|
|
@ -28,7 +28,8 @@ module.exports = async function(req, res) {
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
owner: meta.owner,
|
owner: meta.owner,
|
||||||
download_count: dl,
|
download_count: dl,
|
||||||
ttl
|
ttl,
|
||||||
|
agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
if (dl >= dlimit) {
|
if (dl >= dlimit) {
|
||||||
|
|
|
@ -114,7 +114,8 @@ module.exports = function(ws, req) {
|
||||||
dlimit,
|
dlimit,
|
||||||
timeLimit,
|
timeLimit,
|
||||||
anonymous: !user,
|
anonymous: !user,
|
||||||
size: limiter.length
|
size: limiter.length,
|
||||||
|
agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue