123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System.Timers;
- using OpenMetaverse.StructuredData;
- namespace OpenSim.Framework.Monitoring
- {
-
-
-
- public class UserStatsCollector : BaseStatsCollector
- {
- private Timer ageStatsTimer = new Timer(24 * 60 * 60 * 1000);
- private int successfulLoginsToday;
- public int SuccessfulLoginsToday { get { return successfulLoginsToday; } }
- private int successfulLoginsYesterday;
- public int SuccessfulLoginsYesterday { get { return successfulLoginsYesterday; } }
- private int successfulLogins;
- public int SuccessfulLogins { get { return successfulLogins; } }
- private int logouts;
- public int Logouts { get { return logouts; } }
- public UserStatsCollector()
- {
- ageStatsTimer.Elapsed += new ElapsedEventHandler(OnAgeing);
- ageStatsTimer.Enabled = true;
- }
- private void OnAgeing(object source, ElapsedEventArgs e)
- {
- successfulLoginsYesterday = successfulLoginsToday;
-
-
- successfulLoginsToday = 0;
- }
-
-
-
- public void AddSuccessfulLogin()
- {
- successfulLogins++;
- successfulLoginsToday++;
- }
- public void AddLogout()
- {
- logouts++;
- }
-
-
-
-
- override public string Report()
- {
- return string.Format(
- @"Successful logins total : {0}, today : {1}, yesterday : {2}
- Logouts total : {3}",
- SuccessfulLogins, SuccessfulLoginsToday, SuccessfulLoginsYesterday, Logouts);
- }
- public override string XReport(string uptime, string version)
- {
- return OSDParser.SerializeJsonString(OReport(uptime, version));
- }
- public override OSDMap OReport(string uptime, string version)
- {
- OSDMap ret = new OSDMap();
- ret.Add("SuccessfulLogins", OSD.FromInteger(SuccessfulLogins));
- ret.Add("SuccessfulLoginsToday", OSD.FromInteger(SuccessfulLoginsToday));
- ret.Add("SuccessfulLoginsYesterday", OSD.FromInteger(SuccessfulLoginsYesterday));
- ret.Add("Logouts", OSD.FromInteger(Logouts));
- return ret;
- }
- }
- }
|