-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NEW] Server Session Monitor (SAU) #11461
Description
Server Session Monitor for SAU(Simultaneously Active Users), DAU(Daily Active Users) and MAU(Monthly Active Users)
The main idea on this implementation is to provide a server session monitor(Meteor.server.sessions), which will be responsible for monitoring the life cycle of all connections on the server.
Through this monitor we will be able to store important informations about the sessions, such as sessionID, clientAddress , connection UserID, connection time, OS, platform, etc.
By default, the object returned when a new session is created contains the following fields:
{
id: 'SzczLqirqXc3jFT6W',
close: [Function: close],
onClose: [Function: onClose],
clientAddress: '127.0.0.1',
httpHeaders:
{
'x-forwarded-for': '127.0.0.1',
'x-forwarded-port': '3000',
'x-forwarded-proto': 'ws',
host: 'localhost:3000',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
'accept-language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6'
}
}
Once the user-agent is provided, we can split the string on this field and populated specific fields on the model, like below:
{
id: 'SzczLqirqXc3jFT6W',
...
browser: { name: 'Chrome', version: '67.0.3396.99', major: '67' },
os: { name: 'Mac OS', version: '10.13.6' },
engine: { name: 'WebKit', version: '537.36' }
...
}
Implementation
To track the creation of the sessions, we can rely on Meteor.onConnection(callback), and to handle the session closure, we can rely on connection.onClose callback.
Aiming to identify the User of the session, we can update the session model after login using the Accounts.onLogin(callback) method(e.g.):
Accounts.onLogin(login => {
const sessionID = login.connection.id;
const userId = login._id;
Session.update(sessionID, {
$set: {
userId,
loginAt: new Date()
}
});
});
Obviously the connection.onClose callback will not be called if the server dies, so we need to define the best strategy to keep monitoring the session life cycle.
The initial idea is to map the Meteor.server.sessions and update the records in the database related to the current sessionID's. We can think on creating a specific array to store/remove the SessionID's according to the session life cycle, but I'm not sure how difficult it could be to update the records in the database using that array of sessionID's.
If we start by this approach, a time interval needs to be set to trigger the method in which the array of sessionID's will be read. If the array is large, maybe would be possible to separate it into batches of sessionID's.
Any suggestion on this implementation is very welcome.
Results
At the end of this implementation, we will be able to analyze the information regarding the activities of the sessions on the server.
Steps:
-
Design session model
-
Implementation
-
Tests(In Progress)