public IActionResult GetLastHours([FromQuery] int hours) { if (hours == 1) { return(GetLastMinutes(60)); } if (hours > 24) { throw new ArgumentException(); } var logs = Logger.GetLogs(); var now = DateTime.UtcNow.AddSeconds(-DateTime.UtcNow.Second); now = now.AddMinutes(-now.Minute); var model = new ChartViewModel(); model.FromTime = now.AddHours(-hours); model.ToTime = now.AddHours(1); model.ChartDataModels = new List <Metrics>(); model.ChartType = ChartType.Hour; for (int i = hours; i >= 0; i--) { var metrics = MetricsService.CountMetrics(logs, now.AddHours(-i), now.AddHours(-i).AddMinutes(-now.Minute).AddMinutes(59).AddSeconds(-now.Second).AddSeconds(59)); model.ChartDataModels.Add(metrics); } return(View("Index", model)); }
private IActionResult GetLastMinutes(int minutes) { if (minutes > 60) { throw new ArgumentException(); } var logs = Logger.GetLogs(); var now = DateTime.UtcNow.AddSeconds(-DateTime.UtcNow.Second); var model = new ChartViewModel(); model.FromTime = now.AddMinutes(-minutes); model.ToTime = now; model.ChartDataModels = new List <Metrics>(); model.ChartType = ChartType.Time; int sub = minutes >= 30 ? 5 : 1; for (int i = minutes; i >= 0; i -= sub) { var metrics = MetricsService.CountMetrics(logs, now.AddMinutes(-i), now.AddMinutes(-i).AddSeconds(-now.Second).AddSeconds(59)); model.ChartDataModels.Add(metrics); } return(View("Index", model)); }
public IActionResult GetLastDays([FromQuery] int days) { var logs = Logger.GetLogs(); var now = DateTime.UtcNow.AddSeconds(-DateTime.UtcNow.Second); var metrics = MetricsService.CountMetrics(logs, now.AddDays(-days), now); return(View("Index", metrics)); }
public IActionResult Index() { var logs = Logger.GetLogs(); var now = DateTime.UtcNow.AddSeconds(-DateTime.UtcNow.Second); var metrics = MetricsService.CountMetrics(logs, now.AddHours(-1), now); return(View(metrics)); }
public IActionResult GetLastDays([FromQuery] int days) { if (days == 1) { return(GetLastHours(24)); } var logs = Logger.GetLogs(); var now = DateTime.UtcNow.AddSeconds(-DateTime.UtcNow.Second); var model = new ChartViewModel(); model.FromTime = now.AddDays(-days); model.ToTime = now; model.ChartDataModels = new List <Metrics>(); model.ChartType = ChartType.Date; for (int i = days; i >= 0; i--) { var metrics = MetricsService.CountMetrics(logs, now.AddDays(-i), now.AddDays(-i).AddHours(-now.Hour).AddHours(23).AddMinutes(-now.Minute).AddMinutes(59).AddSeconds(-now.Second).AddSeconds(59)); model.ChartDataModels.Add(metrics); } return(View("Index", model)); }