static void Main(string[] args) { List<string> asyncT = new List<string>(); List<string> errors = new List<string>(); Console.WriteLine(System.Environment.NewLine); Console.WriteLine("Running automatic full reports on all nmon-based files and blg files in this recursive directory..."); Console.WriteLine("Review .\\Output.txt when completed for a detailed report."); string[] zips = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.zip", SearchOption.AllDirectories).ToArray(); if (zips.Count() > 0) { try {//can you .NET4.5? Parallel.ForEach(zips, z => { using (ZipArchive archive = ZipFile.OpenRead(z)) { foreach (ZipArchiveEntry entry in archive.Entries) { string exName = ""; if (entry.FullName.Contains("nmon")) { try {//can you unzip that file? entry.ExtractToFile(Path.Combine(z.Substring(0, z.LastIndexOf('\\')), entry.Name), true); Console.WriteLine("Unzipped " + entry.Name); } catch { errors.Add("Had trouble unzipping this file: " + z); } } else if (entry.Name.Contains(".blg")) { try {//can you unzip that file? //OVERWRITE SAME FOLDER MUHGAWD pls fix string fzName = entry.FullName; int ixf = fzName.IndexOf("/"); exName = fzName.Substring(0, ixf); string nfhx = Path.Combine(z.Substring(0, z.LastIndexOf('\\')), exName); //int inc = 1; while (Directory.Exists(nfhx)) { nfhx += "x"; } //entry.ExtractToDirectory(nfhx); archive.ExtractToDirectory(nfhx); Console.WriteLine("Unzipped " + exName); break; } catch { errors.Add("Had trouble unzipping " + exName +" please check for completion."); } } } } //using (ZipArchive archive = ZipFile.Open(z, ZipArchiveMode.Read)) { // foreach (ZipArchiveEntry entry in archive.Entries) { // if (entry.FullName.Contains("blg")) { // try {//can you unzip that file? // string fzName = entry.FullName; // int ixf = fzName.IndexOf("/"); // string exName = fzName.Substring(0, ixf); // string nfhx = Path.Combine(z.Substring(0, z.LastIndexOf('\\')), exName); // //entry.ExtractToDirectory(nfhx); // archive.ExtractToDirectory(nfhx); // Console.WriteLine("Unzipped " + exName); // } catch { // errors.Add("Had trouble unzipping this file: " + z); // } // } // } //} }); } catch { Console.WriteLine("Your System is not updated to support .NET Framework 4.5, please update!!!"); errors.Add("Your System is not updated to support .NET Framework 4.5, please update!!!"); errors.Add("Could not unzip and process, exiting with errors."); } } string here = Directory.GetCurrentDirectory(); string[] nmonfiles = Directory.GetFiles(here, "*.*", SearchOption.AllDirectories).Where(name => name.Substring(name.LastIndexOf('\\'), name.Length - name.LastIndexOf('\\')).Contains("nmon")).Where(name => !name.Contains(".zip")).ToArray(); string[] blgfiles = Directory.GetFiles(here, "*.blg", SearchOption.AllDirectories); #region perfmons List<string> csvfiles = new List<string>(); if (blgfiles.Count() > 0) { string filterText = @here + @"\CB745.txt"; using (StreamWriter sw = File.CreateText(filterText)) { sw.WriteLine(@"\PhysicalDisk(_Total)\% Disk Time"); sw.WriteLine(@"\Memory\Available MBytes"); sw.WriteLine(@"\Processor(_Total)\% Processor Time "); sw.WriteLine(@"\Network Interface(*)\Bytes Total/sec "); } Console.WriteLine("Relogging Windows PerfMons."); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "CMD.exe"; //Parallel.ForEach(blgfiles, blgfile => { foreach (string blgfile in blgfiles) { File.Delete(blgfile.Substring(0, blgfile.Length - 4) + ".csv"); startInfo.Arguments = "/C relog " + blgfile + " -cf " + filterText + " -f csv -o " + blgfile.Substring(0, blgfile.Length - 4) + ".csv"; csvfiles.Add(blgfile.Substring(0, blgfile.Length - 4) + ".csv"); process.StartInfo = startInfo; process.Start(); process.WaitForExit(); //}); } File.Delete(filterText); Console.WriteLine("Windows PerfMons can take a few minutes."); //string temptest = @"T:\Progs\nmon\sherpanalyzer\sherpanalyzer\bin\x64\Debug\JCRE2_DAC1\000001\PerfMonitor.csv"; List<csvfile> AllCSVs = new List<csvfile>(); foreach (string csvf in csvfiles) { csvfile csvTemp = new csvfile(csvf); AllCSVs.Add(csvTemp); } string[] TotalHosts = (from x in AllCSVs select x.hostname).Distinct().ToArray(); var sortedHosts = from x in AllCSVs orderby x.date group x by x.hostname into newgroup orderby newgroup.Key select newgroup; List<string> MergedCSVs = new List<string>(); //List<string> completedFiles = new List<string>(); foreach (var shost in sortedHosts) { List<string> hoststoCombine = new List<string>(); Console.WriteLine("Sherpalyzing- "+shost.Key); foreach (var dda in shost) { hoststoCombine.Add(dda.filelocation); } MergedCSVs.Add(combineCSVs(hoststoCombine, here, shost.Key)); } Parallel.ForEach(MergedCSVs, mcsv=>{ OutputUnits resultBLG = makePerfMonGraphs(mcsv); asyncT.Add(resultBLG.display()); if (resultBLG.isLeaking) { Console.WriteLine("Possible Memory leak found in "+Path.GetFileNameWithoutExtension(mcsv)); } if (resultBLG.highCPU) { Console.WriteLine("Possible high CPU usage found in " + Path.GetFileNameWithoutExtension(mcsv)); } }); foreach (csvfile mcsv in AllCSVs) { File.Delete(mcsv.filelocation); } foreach (string mcsv in MergedCSVs) { try { File.Delete(mcsv); } catch { Console.WriteLine("FILE IN USE! Excel frozen?"); } } //asyncT.Add("Completed Windows PerfMon analysis. "+System.Environment.NewLine); } else { asyncT.Add("No blg (windows) files were found in this directory."); } #endregion #region nmon if (nmonfiles.Count() < 1) { asyncT.Add("No nmon (redhat) files were found in this directory."); } else { //asyncT.Add("Starting nmon analysis"); Parallel.ForEach(nmonfiles, nmons => { try {//only try; do not. unhandled crashes; doing will cause. asyncT.Add(readSherpa(nmons, true)); } catch {//when someone makes readSherpa crash, tell them there was a bad file in there errors.Add("Had trouble sherpalyzing this file: " + nmons); } }); if (errors.Count == 0) { asyncT.Add("No errors sherpalyzing!"); } else { foreach (string e in errors) { asyncT.Add(e); } } // outputFile(asyncT); Console.WriteLine("Finished"); String graphs = ""; if (args.Length != 0) { Console.WriteLine("Create graphs? (y/n)"); graphs = Console.ReadLine(); } else { Console.WriteLine("Starting automated graph creation."); graphs = "y"; } if (graphs.Length > 0) { if (graphs.Substring(0, 1) == "y" || graphs.Substring(0, 1) == "Y") { Console.WriteLine("Working with Excel in the background."); Console.WriteLine("This may take several minutes..."); string[] CSVs = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csv", SearchOption.TopDirectoryOnly).ToArray(); int cL = CSVs.Length; int i = 1; Parallel.ForEach(CSVs, csvF => { makeGraphs(csvF); File.Delete(csvF); Console.WriteLine("Completed " + i + " of " + cL); i++; }); } } } outputFile(asyncT); #endregion }
static void Main(string[] args) { List <string> asyncT = new List <string>(); List <string> errors = new List <string>(); Console.WriteLine(System.Environment.NewLine); Console.WriteLine("Running automatic full reports on all nmon-based files and blg files in this recursive directory..."); Console.WriteLine("Review .\\Output.txt when completed for a detailed report."); string[] zips = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.zip", SearchOption.AllDirectories).ToArray(); if (zips.Count() > 0) { try {//can you .NET4.5? Parallel.ForEach(zips, z => { using (ZipArchive archive = ZipFile.OpenRead(z)) { foreach (ZipArchiveEntry entry in archive.Entries) { string exName = ""; if (entry.FullName.Contains("nmon")) { try {//can you unzip that file? entry.ExtractToFile(Path.Combine(z.Substring(0, z.LastIndexOf('\\')), entry.Name), true); Console.WriteLine("Unzipped " + entry.Name); } catch { errors.Add("Had trouble unzipping this file: " + z); } } else if (entry.Name.Contains(".blg")) { try {//can you unzip that file? //OVERWRITE SAME FOLDER MUHGAWD pls fix string fzName = entry.FullName; int ixf = fzName.IndexOf("/"); exName = fzName.Substring(0, ixf); string nfhx = Path.Combine(z.Substring(0, z.LastIndexOf('\\')), exName); //int inc = 1; while (Directory.Exists(nfhx)) { nfhx += "x"; } //entry.ExtractToDirectory(nfhx); archive.ExtractToDirectory(nfhx); Console.WriteLine("Unzipped " + exName); break; } catch { errors.Add("Had trouble unzipping " + exName + " please check for completion."); } } } } //using (ZipArchive archive = ZipFile.Open(z, ZipArchiveMode.Read)) { // foreach (ZipArchiveEntry entry in archive.Entries) { // if (entry.FullName.Contains("blg")) { // try {//can you unzip that file? // string fzName = entry.FullName; // int ixf = fzName.IndexOf("/"); // string exName = fzName.Substring(0, ixf); // string nfhx = Path.Combine(z.Substring(0, z.LastIndexOf('\\')), exName); // //entry.ExtractToDirectory(nfhx); // archive.ExtractToDirectory(nfhx); // Console.WriteLine("Unzipped " + exName); // } catch { // errors.Add("Had trouble unzipping this file: " + z); // } // } // } //} }); } catch { Console.WriteLine("Your System is not updated to support .NET Framework 4.5, please update!!!"); errors.Add("Your System is not updated to support .NET Framework 4.5, please update!!!"); errors.Add("Could not unzip and process, exiting with errors."); } } string here = Directory.GetCurrentDirectory(); string[] nmonfiles = Directory.GetFiles(here, "*.*", SearchOption.AllDirectories).Where(name => name.Substring(name.LastIndexOf('\\'), name.Length - name.LastIndexOf('\\')).Contains("nmon")).Where(name => !name.Contains(".zip")).ToArray(); string[] blgfiles = Directory.GetFiles(here, "*.blg", SearchOption.AllDirectories); #region perfmons List <string> csvfiles = new List <string>(); if (blgfiles.Count() > 0) { string filterText = @here + @"\CB745.txt"; using (StreamWriter sw = File.CreateText(filterText)) { sw.WriteLine(@"\PhysicalDisk(_Total)\% Disk Time"); sw.WriteLine(@"\Memory\Available MBytes"); sw.WriteLine(@"\Processor(_Total)\% Processor Time "); sw.WriteLine(@"\Network Interface(*)\Bytes Total/sec "); } Console.WriteLine("Relogging Windows PerfMons."); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "CMD.exe"; //Parallel.ForEach(blgfiles, blgfile => { foreach (string blgfile in blgfiles) { File.Delete(blgfile.Substring(0, blgfile.Length - 4) + ".csv"); startInfo.Arguments = "/C relog " + blgfile + " -cf " + filterText + " -f csv -o " + blgfile.Substring(0, blgfile.Length - 4) + ".csv"; csvfiles.Add(blgfile.Substring(0, blgfile.Length - 4) + ".csv"); process.StartInfo = startInfo; process.Start(); process.WaitForExit(); //}); } File.Delete(filterText); Console.WriteLine("Windows PerfMons can take a few minutes."); //string temptest = @"T:\Progs\nmon\sherpanalyzer\sherpanalyzer\bin\x64\Debug\JCRE2_DAC1\000001\PerfMonitor.csv"; List <csvfile> AllCSVs = new List <csvfile>(); foreach (string csvf in csvfiles) { csvfile csvTemp = new csvfile(csvf); AllCSVs.Add(csvTemp); } string[] TotalHosts = (from x in AllCSVs select x.hostname).Distinct().ToArray(); var sortedHosts = from x in AllCSVs orderby x.date group x by x.hostname into newgroup orderby newgroup.Key select newgroup; List <string> MergedCSVs = new List <string>(); //List<string> completedFiles = new List<string>(); foreach (var shost in sortedHosts) { List <string> hoststoCombine = new List <string>(); Console.WriteLine("Sherpalyzing- " + shost.Key); foreach (var dda in shost) { hoststoCombine.Add(dda.filelocation); } MergedCSVs.Add(combineCSVs(hoststoCombine, here, shost.Key)); } Parallel.ForEach(MergedCSVs, mcsv => { OutputUnits resultBLG = makePerfMonGraphs(mcsv); asyncT.Add(resultBLG.display()); if (resultBLG.isLeaking) { Console.WriteLine("Possible Memory leak found in " + Path.GetFileNameWithoutExtension(mcsv)); } if (resultBLG.highCPU) { Console.WriteLine("Possible high CPU usage found in " + Path.GetFileNameWithoutExtension(mcsv)); } }); foreach (csvfile mcsv in AllCSVs) { File.Delete(mcsv.filelocation); } foreach (string mcsv in MergedCSVs) { try { File.Delete(mcsv); } catch { Console.WriteLine("FILE IN USE! Excel frozen?"); } } //asyncT.Add("Completed Windows PerfMon analysis. "+System.Environment.NewLine); } else { asyncT.Add("No blg (windows) files were found in this directory."); } #endregion #region nmon if (nmonfiles.Count() < 1) { asyncT.Add("No nmon (redhat) files were found in this directory."); } else { //asyncT.Add("Starting nmon analysis"); Parallel.ForEach(nmonfiles, nmons => { try { //only try; do not. unhandled crashes; doing will cause. asyncT.Add(readSherpa(nmons, true)); } catch { //when someone makes readSherpa crash, tell them there was a bad file in there errors.Add("Had trouble sherpalyzing this file: " + nmons); } }); if (errors.Count == 0) { asyncT.Add("No errors sherpalyzing!"); } else { foreach (string e in errors) { asyncT.Add(e); } } // outputFile(asyncT); Console.WriteLine("Finished"); String graphs = ""; if (args.Length != 0) { Console.WriteLine("Create graphs? (y/n)"); graphs = Console.ReadLine(); } else { Console.WriteLine("Starting automated graph creation."); graphs = "y"; } if (graphs.Length > 0) { if (graphs.Substring(0, 1) == "y" || graphs.Substring(0, 1) == "Y") { Console.WriteLine("Working with Excel in the background."); Console.WriteLine("This may take several minutes..."); string[] CSVs = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csv", SearchOption.TopDirectoryOnly).ToArray(); int cL = CSVs.Length; int i = 1; Parallel.ForEach(CSVs, csvF => { makeGraphs(csvF); File.Delete(csvF); Console.WriteLine("Completed " + i + " of " + cL); i++; }); } } } outputFile(asyncT); #endregion }