Пример #1
0
        //[0]	"date"
        //[1]	"time"
        //[2]	"s-sitename"
        //[3]	"s-computername"
        //[4]	"s-ip"
        //[5]	"cs-method"
        //[6]	"cs-uri-stem"
        //[7]	"cs-uri-query"
        //[8]	"s-port"
        //[9]	"cs-username"
        //[10]	"c-ip"
        //[11]	"cs-version"
        //[12]	"cs(User-Agent)"
        //[13]	"cs(Cookie)"
        //[14]	"cs(Referer)"
        //[15]	"cs-host"
        //[16]	"sc-status"
        //[17]	"sc-substatus"
        //[18]	"sc-win32-status"
        //[19]	"sc-bytes"
        //[20]	"cs-bytes"
        //[21]	"time-taken"
        private static List<SessionEx> ReadIisFile(string path)
        {
            var text = File.ReadAllText(path);
            var lines = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            var sessions = new Dictionary<string, SessionEx>();

            foreach (var line in lines)
            {
                if (line.StartsWith("#"))
                    continue;

                var parts = line.Split(' ');
                var dateTime = DateTime.Parse(parts[0] + " " + parts[1]);

                var status = parts[16];
                if (status != "200")
                    continue;

                var contentPath = parts[6].ToLowerInvariant();
                if (!contentPath.StartsWith("/tradingapi/"))
                    continue;

                var url = parts[15] + contentPath;

                var timeTaken = (double)int.Parse(parts[21]) / 1000;

                var ip = parts[10];
                SessionEx session;
                if (!sessions.TryGetValue(ip, out session))
                {
                    session = new SessionEx { Records = new List<RecordEx>(), Ip = ip };
                    session.Records.Add(new RecordEx(session) { Time = dateTime, Name = "ClientIP", Value = ip, });
                    sessions.Add(ip, session);
                }

                var record = new RecordEx(session)
                {
                    Time = dateTime,
                    Name = "Latency " + url,
                    Value = timeTaken.ToString(),
                };
                session.Records.Add(record);
            }

            return sessions.Values.ToList();
        }
Пример #2
0
        public static List<SessionEx> Parse(string dataPath, TimePeriod period)
        {
            var watch = Stopwatch.StartNew();

            var res = new List<SessionEx>();

            {
                var sessions = DataReader.GetSessionsFromPath(dataPath, period);

                foreach (var session in sessions)
                {
                    var records = DataReader.GetRecordsFromSession(session, period);

                    var sessionEx = new SessionEx
                                        {
                                            Id = session.Id,
                                            CreationTime = session.CreationTime,
                                            LastUpdateTime = session.LastUpdateTime
                                        };
                    res.Add(sessionEx);

                    sessionEx.Records = records.ConvertAll(
                        val => new RecordEx(sessionEx)
                                {
                                    SessionId = val.SessionId,
                                    Name = val.Name,
                                    Time = val.Time,
                                    Value = val.Value
                                });
                }
            }

            GC.Collect();
            Trace.WriteLine(string.Format("Parsing data: {0} secs", watch.Elapsed.TotalSeconds));
            return res;
        }
Пример #3
0
 static void Validate(SessionEx session)
 {
     if (session.Records.Any(record => Util.IsJitter(record) && record.ValueAsNumber < 0))
         throw new ValidationException();
 }