public FileResult GetJobPerformanceData() { string jsonData = "{}"; try { List <TriggerStatistic> triggerStats = null; var triggerStatStore = GetConfiguredTriggerStatStore(); if (triggerStatStore != null) { triggerStats = triggerStatStore.GetAllTriggerStatistics(); if (triggerStats != null) { jsonData = HelperUtility.GetJsonSerializedData(triggerStats); jsonData = HelperUtility.AddJsonHeader(jsonData); } else { Diagnostics.Log.Warn("No chart data retrieved from configured Sitecore.QuartzScheduler.TriggerStatisticsStoreProvider when GetAllTriggerStatistics is called!", this); } } Diagnostics.Log.Info(String.Format("Sitecore.QuartzScheuler: Job performance data being returned from the controller action ReportDataController.GetJobPerformanceData: {0}", jsonData), this); } catch (Exception ex) { Diagnostics.Log.Error("Sitecore.QuartzScheuler: " + ex.Message + Environment.NewLine + ex.StackTrace, this); throw ex; } return((FileResult)this.File(new UTF8Encoding().GetBytes(jsonData), "text/json", "data.json"));; }
public void ArchiveTriggerStatistics(int DaysToKeep, string ArchiveLocation) { try { string directory = AssemblyDirectory(); DirectoryInfo dirInfo = new DirectoryInfo(directory); var parentPath = dirInfo.Parent; string archivePath = Path.Combine(parentPath.FullName, ArchiveLocation); if (!Directory.Exists(archivePath)) { Directory.CreateDirectory(archivePath); } var cacheData = cache[Common.Constants.PerformanceDataCacheKey]; if (cacheData != null) { var triggerStatsToArchive = from stats in (List <TriggerStatistic>)cacheData where stats.StartTime < DateTime.Now.Add(TimeSpan.FromDays(-1 * DaysToKeep)) select stats; var triggerStatsToKeep = from stats in (List <TriggerStatistic>)cacheData where stats.StartTime >= DateTime.Now.Add(TimeSpan.FromDays(-1 * DaysToKeep)) select stats; string jsonDataToArchive = HelperUtility.GetJsonSerializedData(triggerStatsToArchive.ToList <TriggerStatistic>()); jsonDataToArchive = HelperUtility.AddJsonHeader(jsonDataToArchive); string fileName = "JobPerformanceData-" + DateTime.Now.Ticks.ToString() + ".json"; string filePath = Path.Combine(archivePath, fileName); if (triggerStatsToArchive != null && triggerStatsToArchive.Count() > 0) { using (FileStream fs = File.Create(filePath)) { byte[] data = new UTF8Encoding().GetBytes(jsonDataToArchive); fs.Write(data, 0, data.Length); cache[Common.Constants.PerformanceDataCacheKey] = triggerStatsToKeep.ToList <TriggerStatistic>(); Diagnostics.Log.Info(String.Format("Performance Data Archived at {0} location in file {1}", archivePath, fileName), this); } } else { Diagnostics.Log.Info(String.Format("No Job performance data to Archive at {0}", DateTime.Now), this); } } } catch (Exception ex) { Diagnostics.Log.Error("Sitecore.QuartzScheuler: " + ex.Message + Environment.NewLine + ex.StackTrace, this); throw ex; } }
public FileResult GetJobWisePerformanceData() { string jsonData = ""; string finalJsonReportData = ""; try { List <TriggerStatistic> triggerStats = null; var triggerStatStore = GetConfiguredTriggerStatStore(); if (triggerStatStore != null) { JobManager jm = new JobManager(); var jobList = jm.GetAllJobs(); if (jobList != null && jobList.Count > 0) { for (int i = 0; i < jobList.Count; i++) { JobDetail jd = jobList[i]; triggerStats = triggerStatStore.GetTriggerStatisticsForJob(jd.JobKey); if (triggerStats != null && triggerStats.Count > 0) { if (finalJsonReportData != "") { finalJsonReportData = finalJsonReportData.Insert(finalJsonReportData.Length, ", "); } jsonData = HelperUtility.GetJsonSerializedData(triggerStats); finalJsonReportData = finalJsonReportData.Insert(finalJsonReportData.Length, jsonData); } else { Diagnostics.Log.Warn("No chart data retrieved from configured Sitecore.QuartzScheduler.TriggerStatisticsStoreProvider when GetTriggerStatisticsForJob is called!", this); } } finalJsonReportData = HelperUtility.AddJsonHeader(finalJsonReportData); } } } catch (Exception ex) { Diagnostics.Log.Error("Sitecore.QuartzScheuler: Error in GetJobWisePerformanceData : " + ex.Message + Environment.NewLine + ex.StackTrace, this); throw ex; } return((FileResult)this.File(new UTF8Encoding().GetBytes(finalJsonReportData), "text/json", "data.json"));; }