public void Start(string[] args) { m_Parameters = ParameterParse.ParseArguments(args, false /* firstOpFlag */, true /* multipleFiles */); foreach (KeyValuePair <string, string> kvp in m_Parameters) { switch (kvp.Key) { case "-o": case "--output": m_outFile = kvp.Value; break; case "--verbose": m_ParamVerbose++; break; case ParameterParse.LAST_PARAM: m_inFiles = kvp.Value; break; case ParameterParse.ERROR_PARAM: // if we get here, the parser found an error Logger.Log("Parameter error: " + kvp.Value); Logger.Log(Invocation()); return; default: Logger.Log("ERROR: UNKNOWN PARAMETER: " + kvp.Key); Logger.Log(Invocation()); return; } } GlobalRecordCollection globalCollection = new GlobalRecordCollection(); // Read in all log records into approriate structure type for each log line if (!String.IsNullOrEmpty(m_inFiles)) { string[] files = m_inFiles.Split(','); foreach (string fileName in files) { if (fileName.Substring(0, connName.Length) == connName) { List <Records> syncConn = StatSyncConnector.Read(fileName); globalCollection.Add(syncConn); } else if (fileName.Substring(0, sceneName.Length) == sceneName) { List <Records> syncConn = StatScene.Read(fileName); globalCollection.Add(syncConn); } else if (fileName.Substring(0, serverName.Length) == serverName) { List <Records> syncConn = StatServer.Read(fileName); globalCollection.Add(syncConn); } else { Logger.Log("No handler for file {0}", fileName); } } } // Compute the number of buckets based on the log records. Compute min and max. double[] bucketTimes = ComputeBuckets(globalCollection, 10 /* bucket size in seconds */); long numBuckets = bucketTimes.Length; if (numBuckets > 0) { List <Records>[] buckets = DistributeToBucketArray(globalCollection, numBuckets); GenerateOutput(globalCollection, buckets, bucketTimes); } }
public void Start(string[] args) { m_Parameters = ParameterParse.ParseArguments(args, false /* firstOpFlag */, true /* multipleFiles */); foreach (KeyValuePair <string, string> kvp in m_Parameters) { switch (kvp.Key) { case "-p": case "--period": m_bucketSeconds = int.Parse(kvp.Value); break; case "-o": case "--output": m_outFile = kvp.Value; break; case "-h": case "--cmHosts": m_cmHosts = kvp.Value; break; case "--verbose": m_ParamVerbose++; break; case ParameterParse.LAST_PARAM: m_inFiles = kvp.Value; break; case ParameterParse.ERROR_PARAM: // if we get here, the parser found an error Logger.Log("Parameter error: " + kvp.Value); Logger.Log(Invocation()); return; default: Logger.Log("ERROR: UNKNOWN PARAMETER: " + kvp.Key); Logger.Log(Invocation()); return; } } List <HTTPRecord> records = new List <HTTPRecord>(); // Read in the records if (!String.IsNullOrEmpty(m_inFiles)) { string[] files = m_inFiles.Split(','); foreach (string fileName in files) { records.AddRange(HTTPRecord.Read(fileName)); } } // Find high and low dates and compute the number of buckets double minDate = double.MaxValue; double maxDate = double.MinValue; foreach (HTTPRecord rec in records) { minDate = Math.Min(minDate, rec.time); maxDate = Math.Max(maxDate, rec.time); } double bucketBaseTime = minDate; int numBuckets = ((int)((maxDate - minDate) * LongDate.secondsPerDay)) / m_bucketSeconds; numBuckets += 1; // add a last bucket for rounding error at the end. Logger.Log("Number of buckets = {0}", numBuckets); // Loop through all the records and assign each to a bucket foreach (HTTPRecord rec in records) { rec.bucket = ((int)((rec.time - bucketBaseTime) * LongDate.secondsPerDay)) / m_bucketSeconds; } // Specify individual hosts to count accesses with CSV list "host,host,host" List <string> cmHosts = m_cmHosts.Split(',').ToList <string>(); int numHosts = cmHosts.Count; if (numHosts == 0) { Logger.Log("NUMBER OF Client Manager HOSTS MUST NOT BE ZERO!!"); return; } // Initialize each bucket line with the variable sized structures BucketLine[] bucketLines = new BucketLine[numBuckets]; for (int ii = 0; ii < numBuckets; ii++) { bucketLines[ii].bucket = ii; bucketLines[ii].time = bucketBaseTime + ((double)(ii * m_bucketSeconds) / LongDate.secondsPerDay); bucketLines[ii].hostCount = new int[numHosts]; bucketLines[ii].logins = 0; } // Loop through all the records and fill the bucket info foreach (HTTPRecord rec in records) { int nHost = cmHosts.IndexOf(rec.source); if (nHost >= 0) { bucketLines[rec.bucket].hostCount[nHost]++; } if (rec.remain.Contains("/Grid/login/ ")) { bucketLines[rec.bucket].logins++; } } // Print out all the buckets bool firstLine = true; TextWriter outWriter = new StreamWriter(File.Open(m_outFile, FileMode.Create)); if (outWriter != null) { using (outWriter) { if (firstLine) { StringBuilder buff = new StringBuilder(); buff.Append("bucket"); buff.Append(","); buff.Append("time"); buff.Append(","); buff.Append("logins"); buff.Append(","); for (int ii = 0; ii < cmHosts.Count; ii++) { buff.Append(cmHosts[ii]); buff.Append(","); } outWriter.WriteLine(buff.ToString()); firstLine = false; } foreach (BucketLine buck in bucketLines) { StringBuilder buff = new StringBuilder(); buff.Append(buck.bucket.ToString()); buff.Append(","); buff.Append(buck.time.ToString()); buff.Append(","); buff.Append(buck.logins.ToString()); buff.Append(","); for (int ii = 0; ii < buck.hostCount.Length; ii++) { buff.Append(buck.hostCount[ii].ToString()); buff.Append(","); } outWriter.WriteLine(buff.ToString()); } } } }