Esempio n. 1
0
        public void ExportCollectorMetricsToCSV()
        {
            string outputPath     = CollectorMetricsExportPath;
            string outputFileName = Name.StringToSaveFileName() + DateTime.Now.Date.ToString("yyyyMMdd") + ".csv";

            if (outputPath.Length == 0)
            {
                if (MonitorPackPath != null && MonitorPackPath.Length > 0)
                {
                    outputPath = System.IO.Path.GetDirectoryName(MonitorPackPath);
                }
                else
                {
                    outputPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                }
                outputPath = System.IO.Path.Combine(outputPath, outputFileName);
            }
            else if (System.IO.Directory.Exists(outputPath))
            {
                outputPath = System.IO.Path.Combine(outputPath, outputFileName);
            }

            ////Get output directory
            //if (outputPath.Length == 0 || (!System.IO.Directory.Exists(outputPath) && !System.IO.File.Exists(outputPath)))
            //{
            //    if (MonitorPackPath != null && MonitorPackPath.Length > 0)
            //    {
            //        outputPath = System.IO.Path.GetDirectoryName(MonitorPackPath);
            //    }
            //    else
            //    {
            //        outputPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            //    }
            //}
            //outputPath = System.IO.Path.Combine(outputPath, outputFileName);
            try
            {
                lock (collectorMetricsSyncLock)
                {
                    if (!System.IO.File.Exists(outputPath))
                    {
                        System.IO.File.WriteAllText(outputPath, CollectorHost.ExportHistoryToCSVHeaders());
                    }

                    System.IO.File.AppendAllText(outputPath, ExportCurrentCollectorMetricsToCSV());
                }
            }
            catch (Exception ex)
            {
                WriteLogging(string.Format("Error performing ExportCollectorMetricsToCSV: {0}", ex.Message));
                RaiseMonitorPackError(string.Format("Error performing ExportCollectorMetricsToCSV: {0}", ex.Message));
            }
        }
Esempio n. 2
0
        public string ExportCollectorHistoryToCSV(bool addheader = true)
        {
            StringBuilder sb = new StringBuilder();

            if (addheader)
            {
                sb.Append(CollectorHost.ExportHistoryToCSVHeaders());
            }
            foreach (CollectorHost ch in CollectorHosts)
            {
                sb.Append(ch.ExportHistoryToCSV());
            }
            return(sb.ToString());
        }