Ejemplo n.º 1
0
        public Dictionary <string, List <KeyValuePair <string, int> > > GetLastDayStats()
        {
            StatCounter totalStatCounter = new StatCounter();

            totalStatCounter.Lock();

            List <KeyValuePair <string, int> > totalQueriesPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNoErrorPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalServerFailurePerInterval = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNameErrorPerInterval     = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalRefusedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalBlockedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalClientsPerInterval       = new List <KeyValuePair <string, int> >();

            DateTime lastDayDateTime = DateTime.UtcNow.AddHours(-24);

            lastDayDateTime = new DateTime(lastDayDateTime.Year, lastDayDateTime.Month, lastDayDateTime.Day, lastDayDateTime.Hour, 0, 0, DateTimeKind.Utc);

            for (int hour = 0; hour < 24; hour++)
            {
                DateTime lastDateTime = lastDayDateTime.AddHours(hour);
                string   label        = lastDateTime.ToLocalTime().ToString("MM/dd HH") + ":00";

                HourlyStats hourlyStats       = LoadHourlyStats(lastDateTime);
                StatCounter hourlyStatCounter = hourlyStats.HourStat;

                totalStatCounter.Merge(hourlyStatCounter);

                totalQueriesPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalQueries));
                totalNoErrorPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalNoError));
                totalServerFailurePerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalServerFailure));
                totalNameErrorPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalNameError));
                totalRefusedPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalRefused));
                totalBlockedPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalBlocked));
                totalClientsPerInterval.Add(new KeyValuePair <string, int>(label, hourlyStatCounter.TotalClients));
            }

            Dictionary <string, List <KeyValuePair <string, int> > > data = new Dictionary <string, List <KeyValuePair <string, int> > >();

            {
                List <KeyValuePair <string, int> > stats = new List <KeyValuePair <string, int> >(6);

                stats.Add(new KeyValuePair <string, int>("totalQueries", totalStatCounter.TotalQueries));
                stats.Add(new KeyValuePair <string, int>("totalNoError", totalStatCounter.TotalNoError));
                stats.Add(new KeyValuePair <string, int>("totalServerFailure", totalStatCounter.TotalServerFailure));
                stats.Add(new KeyValuePair <string, int>("totalNameError", totalStatCounter.TotalNameError));
                stats.Add(new KeyValuePair <string, int>("totalRefused", totalStatCounter.TotalRefused));
                stats.Add(new KeyValuePair <string, int>("totalBlocked", totalStatCounter.TotalBlocked));
                stats.Add(new KeyValuePair <string, int>("totalClients", totalStatCounter.TotalClients));

                data.Add("stats", stats);
            }

            data.Add("totalQueriesPerInterval", totalQueriesPerInterval);
            data.Add("totalNoErrorPerInterval", totalNoErrorPerInterval);
            data.Add("totalServerFailurePerInterval", totalServerFailurePerInterval);
            data.Add("totalNameErrorPerInterval", totalNameErrorPerInterval);
            data.Add("totalRefusedPerInterval", totalRefusedPerInterval);
            data.Add("totalBlockedPerInterval", totalBlockedPerInterval);
            data.Add("totalClientsPerInterval", totalClientsPerInterval);

            data.Add("topDomains", totalStatCounter.GetTopDomains());
            data.Add("topBlockedDomains", totalStatCounter.GetTopBlockedDomains());
            data.Add("topClients", totalStatCounter.GetTopClients());
            data.Add("queryTypes", totalStatCounter.GetTopQueryTypes());

            return(data);
        }
Ejemplo n.º 2
0
        public Dictionary <string, List <KeyValuePair <string, int> > > GetLastYearStats()
        {
            StatCounter totalStatCounter = new StatCounter();

            totalStatCounter.Lock();

            List <KeyValuePair <string, int> > totalQueriesPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNoErrorPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalServerFailurePerInterval = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalNameErrorPerInterval     = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalRefusedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalBlockedPerInterval       = new List <KeyValuePair <string, int> >();
            List <KeyValuePair <string, int> > totalClientsPerInterval       = new List <KeyValuePair <string, int> >();

            DateTime lastYearDateTime = DateTime.UtcNow.AddMonths(-12);

            lastYearDateTime = new DateTime(lastYearDateTime.Year, lastYearDateTime.Month, 1, 0, 0, 0, DateTimeKind.Utc);

            for (int month = 0; month < 12; month++) //months
            {
                StatCounter monthlyStatCounter = new StatCounter();
                monthlyStatCounter.Lock();

                DateTime lastMonthDateTime = lastYearDateTime.AddMonths(month);
                string   label             = lastMonthDateTime.ToLocalTime().ToString("MM/yyyy");

                int days = DateTime.DaysInMonth(lastMonthDateTime.Year, lastMonthDateTime.Month);

                for (int day = 0; day < days; day++) //days
                {
                    DateTime lastDayDateTime = lastMonthDateTime.AddDays(day);

                    for (int hour = 0; hour < 24; hour++) //hours
                    {
                        DateTime    lastDateTime = lastDayDateTime.AddHours(hour);
                        HourlyStats hourlyStats  = LoadHourlyStats(lastDateTime);

                        monthlyStatCounter.Merge(hourlyStats.HourStat);
                    }
                }

                totalStatCounter.Merge(monthlyStatCounter);

                totalQueriesPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalQueries));
                totalNoErrorPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalNoError));
                totalServerFailurePerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalServerFailure));
                totalNameErrorPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalNameError));
                totalRefusedPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalRefused));
                totalBlockedPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalBlocked));
                totalClientsPerInterval.Add(new KeyValuePair <string, int>(label, monthlyStatCounter.TotalClients));
            }

            Dictionary <string, List <KeyValuePair <string, int> > > data = new Dictionary <string, List <KeyValuePair <string, int> > >();

            {
                List <KeyValuePair <string, int> > stats = new List <KeyValuePair <string, int> >(6);

                stats.Add(new KeyValuePair <string, int>("totalQueries", totalStatCounter.TotalQueries));
                stats.Add(new KeyValuePair <string, int>("totalNoError", totalStatCounter.TotalNoError));
                stats.Add(new KeyValuePair <string, int>("totalServerFailure", totalStatCounter.TotalServerFailure));
                stats.Add(new KeyValuePair <string, int>("totalNameError", totalStatCounter.TotalNameError));
                stats.Add(new KeyValuePair <string, int>("totalRefused", totalStatCounter.TotalRefused));
                stats.Add(new KeyValuePair <string, int>("totalBlocked", totalStatCounter.TotalBlocked));
                stats.Add(new KeyValuePair <string, int>("totalClients", totalStatCounter.TotalClients));

                data.Add("stats", stats);
            }

            data.Add("totalQueriesPerInterval", totalQueriesPerInterval);
            data.Add("totalNoErrorPerInterval", totalNoErrorPerInterval);
            data.Add("totalServerFailurePerInterval", totalServerFailurePerInterval);
            data.Add("totalNameErrorPerInterval", totalNameErrorPerInterval);
            data.Add("totalRefusedPerInterval", totalRefusedPerInterval);
            data.Add("totalBlockedPerInterval", totalBlockedPerInterval);
            data.Add("totalClientsPerInterval", totalClientsPerInterval);

            data.Add("topDomains", totalStatCounter.GetTopDomains());
            data.Add("topBlockedDomains", totalStatCounter.GetTopBlockedDomains());
            data.Add("topClients", totalStatCounter.GetTopClients());
            data.Add("queryTypes", totalStatCounter.GetTopQueryTypes());

            return(data);
        }
Ejemplo n.º 3
0
        public Dictionary <string, List <KeyValuePair <string, int> > > GetLastHourStats()
        {
            StatCounter totalStatCounter = new StatCounter();

            totalStatCounter.Lock();

            List <KeyValuePair <string, int> > totalQueriesPerInterval       = new List <KeyValuePair <string, int> >(60);
            List <KeyValuePair <string, int> > totalNoErrorPerInterval       = new List <KeyValuePair <string, int> >(60);
            List <KeyValuePair <string, int> > totalServerFailurePerInterval = new List <KeyValuePair <string, int> >(60);
            List <KeyValuePair <string, int> > totalNameErrorPerInterval     = new List <KeyValuePair <string, int> >(60);
            List <KeyValuePair <string, int> > totalRefusedPerInterval       = new List <KeyValuePair <string, int> >(60);
            List <KeyValuePair <string, int> > totalBlockedPerInterval       = new List <KeyValuePair <string, int> >(60);
            List <KeyValuePair <string, int> > totalClientsPerInterval       = new List <KeyValuePair <string, int> >(60);

            DateTime lastHourDateTime = DateTime.UtcNow.AddMinutes(-60);

            lastHourDateTime = new DateTime(lastHourDateTime.Year, lastHourDateTime.Month, lastHourDateTime.Day, lastHourDateTime.Hour, lastHourDateTime.Minute, 0, DateTimeKind.Utc);

            for (int minute = 0; minute < 60; minute++)
            {
                DateTime lastDateTime = lastHourDateTime.AddMinutes(minute);
                string   label        = lastDateTime.ToLocalTime().ToString("HH:mm");

                StatCounter statCounter = _lastHourStatCounters[lastDateTime.Minute];
                if ((statCounter != null) && statCounter.IsLocked)
                {
                    totalStatCounter.Merge(statCounter);

                    totalQueriesPerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalQueries));
                    totalNoErrorPerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalNoError));
                    totalServerFailurePerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalServerFailure));
                    totalNameErrorPerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalNameError));
                    totalRefusedPerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalRefused));
                    totalBlockedPerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalBlocked));
                    totalClientsPerInterval.Add(new KeyValuePair <string, int>(label, statCounter.TotalClients));
                }
                else
                {
                    totalQueriesPerInterval.Add(new KeyValuePair <string, int>(label, 0));
                    totalNoErrorPerInterval.Add(new KeyValuePair <string, int>(label, 0));
                    totalServerFailurePerInterval.Add(new KeyValuePair <string, int>(label, 0));
                    totalNameErrorPerInterval.Add(new KeyValuePair <string, int>(label, 0));
                    totalRefusedPerInterval.Add(new KeyValuePair <string, int>(label, 0));
                    totalBlockedPerInterval.Add(new KeyValuePair <string, int>(label, 0));
                    totalClientsPerInterval.Add(new KeyValuePair <string, int>(label, 0));
                }
            }

            Dictionary <string, List <KeyValuePair <string, int> > > data = new Dictionary <string, List <KeyValuePair <string, int> > >();

            {
                List <KeyValuePair <string, int> > stats = new List <KeyValuePair <string, int> >(6);

                stats.Add(new KeyValuePair <string, int>("totalQueries", totalStatCounter.TotalQueries));
                stats.Add(new KeyValuePair <string, int>("totalNoError", totalStatCounter.TotalNoError));
                stats.Add(new KeyValuePair <string, int>("totalServerFailure", totalStatCounter.TotalServerFailure));
                stats.Add(new KeyValuePair <string, int>("totalNameError", totalStatCounter.TotalNameError));
                stats.Add(new KeyValuePair <string, int>("totalRefused", totalStatCounter.TotalRefused));
                stats.Add(new KeyValuePair <string, int>("totalBlocked", totalStatCounter.TotalBlocked));
                stats.Add(new KeyValuePair <string, int>("totalClients", totalStatCounter.TotalClients));

                data.Add("stats", stats);
            }

            data.Add("totalQueriesPerInterval", totalQueriesPerInterval);
            data.Add("totalNoErrorPerInterval", totalNoErrorPerInterval);
            data.Add("totalServerFailurePerInterval", totalServerFailurePerInterval);
            data.Add("totalNameErrorPerInterval", totalNameErrorPerInterval);
            data.Add("totalRefusedPerInterval", totalRefusedPerInterval);
            data.Add("totalBlockedPerInterval", totalBlockedPerInterval);
            data.Add("totalClientsPerInterval", totalClientsPerInterval);

            data.Add("topDomains", totalStatCounter.GetTopDomains());
            data.Add("topBlockedDomains", totalStatCounter.GetTopBlockedDomains());
            data.Add("topClients", totalStatCounter.GetTopClients());
            data.Add("queryTypes", totalStatCounter.GetTopQueryTypes());

            return(data);
        }