Ejemplo n.º 1
0
        public override void GetMetricFromLine(DateTime date, string line, LogParserParameters parameters, Dictionary <string, LogMetrics> logMetricsList)
        {
            var category = GetCategoryFromLog(line);

            var metric = new LogMetric(date, 1);

            if (logMetricsList.ContainsKey(category))
            {
                logMetricsList[category].Add(metric);
            }
            else
            {
                var newMetricSet = new LogMetrics();
                newMetricSet.Add(metric);
                logMetricsList.Add(category, newMetricSet);
            }
        }
Ejemplo n.º 2
0
        public async Task <LogResponse> GetHistogramAsync(LogParserParameters parameters)
        {
            Util.WriteLog(DateTime.Now + ": " + "GetHistogramAsync(LogParserParameters parameters)");
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var response = await FindAndSetLoggingFileAndCreateResponseObject();

            response.Parameters = parameters;

            if (!response.LogFileFound)
            {
                sw.Stop();
                response.ParseTime = sw.ElapsedMilliseconds;
                return(response);
            }

            FileInfo fileInfo = new FileInfo(response.LogFile);
            long     filesize = fileInfo.Length;

            Util.WriteLog("filesize: " + filesize);

            long offSet = 0;

            using (Stream stream = File.Open(response.LogFile, FileMode.Open))
            {
                Util.WriteLog("BinarySearch");
                offSet = BinarySearchLogFile(stream, parameters.EndTime, 0, filesize, parameters.EndTime.Subtract(parameters.StartTime), parameters);
            }

            Util.WriteLog("offSet: " + offSet);

            if (offSet == -1)
            {
                sw.Stop();
                response.ParseTime = sw.ElapsedMilliseconds;
                return(response);
            }

            var logMetricsList = new Dictionary <string, LogMetrics>();

            offSet = ReadFileInReverseOrder(response.LogFile, offSet, parameters, response);

            ReadFileInOrder(offSet, parameters, logMetricsList, response);

            foreach (var category in logMetricsList.Keys)
            {
                var logCatgeorMetrics = new LogMetrics();

                logCatgeorMetrics.AddRange(from dt in logMetricsList[category]
                                           group dt by dt.Timestamp.Ticks / parameters.TimeGrain.Ticks
                                           into g
                                           select
                                           new LogMetric(Util.GetDateTimeInUtcFormat(new DateTime(g.Key * parameters.TimeGrain.Ticks)), g.ToList().Count));

                logCatgeorMetrics.Sort((x, y) => x.Timestamp.CompareTo(y.Timestamp));

                response.LogMetrics.Add(category, logCatgeorMetrics);
            }

            sw.Stop();

            response.ExceptionCount = response.ExceptionCount.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

            response.ParseTime = sw.ElapsedMilliseconds;
            return(response);
        }