public static DashboardItem AddWebTestsPercentage( ApiToken apiToken, string name = "Web tests 24h", Action <DashboardItem>?options = null, string whereQuery = "") { var query = $@" availabilityResults | where timestamp > ago(24h) | where client_Type == 'PC' {whereQuery} | summarize _successCount=todouble(countif(success == 1)), _totalCount=todouble(count()) by bin(timestamp, 1h) | project timestamp, 100.0 - (_successCount / _totalCount * 100.0)"; var item = new DashboardItem(name, apiToken, query) { Postfix = "%", MinChartValue = 10, Duration = ItemDuration.TwelveHours, FormatValue = d => (100.0 - d).ToString("0.#"), WarningThreshold = 1, ErrorThreshold = 5 }; options?.Invoke(item); return(item); }
public static DashboardItem AddExceptionsWhere( ApiToken apiToken, string name = "Exceptions", Action <DashboardItem>?options = null, string whereQuery = "") { var query = $@" exceptions | where timestamp > ago(1h) | where client_Type == 'PC' {whereQuery} | summarize _count=sum(itemCount) by bin(timestamp, 2m) | project timestamp, _count"; var item = new DashboardItem(name, apiToken, query) { MinChartValue = 10, Total = ItemTotal.Sum, WarningThreshold = 10, ErrorThreshold = 50 }; options?.Invoke(item); return(item); }
public static DashboardItem AddFailedRequestsPercentage( ApiToken apiToken, string name = "Failed requests", Action <DashboardItem>?options = null, string whereQuery = "") { var query = $@" requests | where timestamp > ago(1h) | where client_Type == 'PC' {whereQuery} | summarize totalCount=sum(itemCount), errorCount=sumif(itemCount, success == false) by bin(timestamp, 2m) | project timestamp, 100.0 / totalCount * errorCount"; var item = new DashboardItem(name, apiToken, query) { Postfix = "%", MinChartValue = 10, FormatValue = d => d.ToString("0.#"), WarningThreshold = 5, ErrorThreshold = 10 }; options?.Invoke(item); return(item); }
private string GetQueryString(ConfigLogic.Dashboard.DashboardItem item, DateTime durationFrom, DateTime durationTo, string bin) { var query = item.Query.Trim(); query = Regex.Replace(query, @"> ago\([0-9a-z]+\)", $">= datetime('{(durationFrom.ToString("o"))}') and timestamp <= datetime('{(durationTo.ToString("o"))}')"); query = Regex.Replace(query, @"bin\(([\w]+),[ ]*[0-9a-z]+\)", $"bin($1, {bin})"); query = Regex.Replace(query, @"\r\n[\W]*\|", "\r\n|"); return(query); }
private string GetQueryString(ConfigLogic.Dashboard.DashboardItem item, string ago, string bin) { var query = item.Query.Trim(); query = Regex.Replace(query, @"ago\([0-9a-z]+\)", $"ago({ago})"); query = Regex.Replace(query, @"bin\(([\w]+),[ ]*[0-9a-z]+\)", $"bin($1, {bin})"); query = Regex.Replace(query, @"\r\n[\W]*\|", "\r\n|"); return(query); }
public static DashboardItem AddRequestResponseTime( ApiToken apiToken, string name = "Response time", Action <DashboardItem>?options = null, string whereQuery = "", DurationType durationType = DurationType.Percentile_90) { var averageString = "avg(duration)"; switch (durationType) { case DurationType.Percentile_50: averageString = "percentile(duration, 50)"; break; case DurationType.Percentile_90: averageString = "percentile(duration, 90)"; break; case DurationType.Percentile_95: averageString = "percentile(duration, 95)"; break; case DurationType.Percentile_99: averageString = "percentile(duration, 99)"; break; } var query = $@" requests | where timestamp > ago(1h) | where client_Type == 'PC' {whereQuery} | summarize _duration = {averageString} by bin(timestamp, 2m) | project timestamp, _duration"; var item = new DashboardItem(name, apiToken, query) { Postfix = "ms", Total = ItemTotal.Average, MinChartValue = 1000, WarningThreshold = 5000, ErrorThreshold = 0 }; options?.Invoke(item); return(item); }
public static DashboardItem AddQuery( ApiToken apiToken, string name = "Requests", Action <DashboardItem>?options = null, string query = "") { var item = new DashboardItem(name, apiToken, query) { Postfix = "", Total = ItemTotal.Average, MinChartValue = 100 }; options?.Invoke(item); return(item); }
private async Task <double> GetValueQuery(ConfigLogic.Dashboard.DashboardItem item, string query) { var table = await AppInsightsClient.GetTableQuery(item.ApiToken.Id, item.ApiToken.Key, query); var value = 0.0; if (table.Rows.Count > 0 && table.Rows[0].Count > 1 && (table.Rows[0][1] is double || table.Rows[0][1] is long)) { value = table.Rows[0][1]; } if (item.Total == ItemTotal.Rpm) { return(value / item.Duration.GetString().GetTimeSpan().TotalMinutes); } return(value); }
private static ItemStatus DefaultGetStatus(DashboardItem item, double value, List <double> chart) { if (value <= item.DisabledThreshold) { return(ItemStatus.Disabled); } var tmpQuery = chart.SkipLast(2).AsEnumerable(); double finalTmpValue; if (item.StatusSplitFactor > 0 && chart.Count > item.StatusSplitFactor) { var count = tmpQuery.Count(); tmpQuery = tmpQuery.TakeLast(count / item.StatusSplitFactor); } if (item.Total == ItemTotal.Sum) { finalTmpValue = tmpQuery.Sum(); } else if (item.Total == ItemTotal.Average || item.Total == ItemTotal.Rpm) { finalTmpValue = tmpQuery.Average(); } else { return(ItemStatus.Normal); } if (finalTmpValue >= item.ErrorThreshold && item.ErrorThreshold > 0) { return(ItemStatus.Error); } else if (finalTmpValue >= item.WarningThreshold && item.WarningThreshold > 0) { return(ItemStatus.Warning); } return(ItemStatus.Normal); }
public static DashboardItem AddRequestPerMinute( ApiToken apiToken, string name = "Requests", Action <DashboardItem>?options = null, string whereQuery = "") { var query = $@" requests | where timestamp > ago(1h) | where client_Type == 'PC' {whereQuery} | summarize _count=sum(itemCount) by bin(timestamp, 2m) | project timestamp, _count"; var item = new DashboardItem(name, apiToken, query) { Postfix = "pm", Total = ItemTotal.Rpm, MinChartValue = 1000 }; options?.Invoke(item); return(item); }
private async Task <List <RowItem> > GetChartValues(ConfigLogic.Dashboard.DashboardItem item, string query) { var table = await AppInsightsClient.GetTableQuery(item.ApiToken.Id, item.ApiToken.Key, query); return(table.Rows.Select(row => new RowItem(row[0], row[1])).ToList()); }