mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 10:39:07 +08:00
chore: dashboard and alert names (#5705)
* chore: dashboard names * chore: fix panel count
This commit is contained in:
parent
0401c27dbc
commit
871e5ada9e
@ -3346,16 +3346,26 @@ func (r *ClickHouseReader) GetDashboardsInfo(ctx context.Context) (*model.Dashbo
|
|||||||
return &dashboardsInfo, err
|
return &dashboardsInfo, err
|
||||||
}
|
}
|
||||||
totalDashboardsWithPanelAndName := 0
|
totalDashboardsWithPanelAndName := 0
|
||||||
|
var dashboardNames []string
|
||||||
count := 0
|
count := 0
|
||||||
for _, dashboard := range dashboardsData {
|
for _, dashboard := range dashboardsData {
|
||||||
if isDashboardWithPanelAndName(dashboard.Data) {
|
if isDashboardWithPanelAndName(dashboard.Data) {
|
||||||
totalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName + 1
|
totalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName + 1
|
||||||
}
|
}
|
||||||
dashboardsInfo = countPanelsInDashboard(dashboard.Data)
|
dashboardName := extractDashboardName(dashboard.Data)
|
||||||
|
if dashboardName != "" {
|
||||||
|
dashboardNames = append(dashboardNames, dashboardName)
|
||||||
|
}
|
||||||
|
dashboardInfo := countPanelsInDashboard(dashboard.Data)
|
||||||
|
dashboardsInfo.LogsBasedPanels += dashboardInfo.LogsBasedPanels
|
||||||
|
dashboardsInfo.TracesBasedPanels += dashboardInfo.TracesBasedPanels
|
||||||
|
dashboardsInfo.MetricBasedPanels += dashboardsInfo.MetricBasedPanels
|
||||||
if isDashboardWithTSV2(dashboard.Data) {
|
if isDashboardWithTSV2(dashboard.Data) {
|
||||||
count = count + 1
|
count = count + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dashboardsInfo.DashboardNames = dashboardNames
|
||||||
dashboardsInfo.TotalDashboards = len(dashboardsData)
|
dashboardsInfo.TotalDashboards = len(dashboardsData)
|
||||||
dashboardsInfo.TotalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName
|
dashboardsInfo.TotalDashboardsWithPanelAndName = totalDashboardsWithPanelAndName
|
||||||
dashboardsInfo.QueriesWithTSV2 = count
|
dashboardsInfo.QueriesWithTSV2 = count
|
||||||
@ -3389,6 +3399,19 @@ func isDashboardWithPanelAndName(data map[string]interface{}) bool {
|
|||||||
|
|
||||||
return isDashboardWithPanelAndName
|
return isDashboardWithPanelAndName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractDashboardName(data map[string]interface{}) string {
|
||||||
|
|
||||||
|
if data != nil && data["title"] != nil {
|
||||||
|
title, ok := data["title"].(string)
|
||||||
|
if ok {
|
||||||
|
return title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func countPanelsInDashboard(data map[string]interface{}) model.DashboardsInfo {
|
func countPanelsInDashboard(data map[string]interface{}) model.DashboardsInfo {
|
||||||
var logsPanelCount, tracesPanelCount, metricsPanelCount int
|
var logsPanelCount, tracesPanelCount, metricsPanelCount int
|
||||||
// totalPanels := 0
|
// totalPanels := 0
|
||||||
|
@ -648,6 +648,7 @@ type AlertsInfo struct {
|
|||||||
MetricsClickHouseQueries int `json:"metricsClickHouseQueries"`
|
MetricsClickHouseQueries int `json:"metricsClickHouseQueries"`
|
||||||
MetricsPrometheusQueries int `json:"metricsPrometheusQueries"`
|
MetricsPrometheusQueries int `json:"metricsPrometheusQueries"`
|
||||||
SpanMetricsPrometheusQueries int `json:"spanMetricsPrometheusQueries"`
|
SpanMetricsPrometheusQueries int `json:"spanMetricsPrometheusQueries"`
|
||||||
|
AlertNames []string `json:"alertNames"`
|
||||||
AlertsWithTSV2 int `json:"alertsWithTSv2"`
|
AlertsWithTSV2 int `json:"alertsWithTSv2"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,8 +663,9 @@ type DashboardsInfo struct {
|
|||||||
TotalDashboardsWithPanelAndName int `json:"totalDashboardsWithPanelAndName"` // dashboards with panel and name without sample title
|
TotalDashboardsWithPanelAndName int `json:"totalDashboardsWithPanelAndName"` // dashboards with panel and name without sample title
|
||||||
LogsBasedPanels int `json:"logsBasedPanels"`
|
LogsBasedPanels int `json:"logsBasedPanels"`
|
||||||
MetricBasedPanels int `json:"metricBasedPanels"`
|
MetricBasedPanels int `json:"metricBasedPanels"`
|
||||||
QueriesWithTSV2 int `json:"queriesWithTSV2"`
|
|
||||||
TracesBasedPanels int `json:"tracesBasedPanels"`
|
TracesBasedPanels int `json:"tracesBasedPanels"`
|
||||||
|
DashboardNames []string `json:"dashboardNames"`
|
||||||
|
QueriesWithTSV2 int `json:"queriesWithTSV2"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagTelemetryData struct {
|
type TagTelemetryData struct {
|
||||||
|
@ -308,6 +308,7 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) {
|
|||||||
// fetch alerts from rules db
|
// fetch alerts from rules db
|
||||||
query := "SELECT data FROM rules"
|
query := "SELECT data FROM rules"
|
||||||
var alertsData []string
|
var alertsData []string
|
||||||
|
var alertNames []string
|
||||||
err := r.Select(&alertsData, query)
|
err := r.Select(&alertsData, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.L().Error("Error in processing sql query", zap.Error(err))
|
zap.L().Error("Error in processing sql query", zap.Error(err))
|
||||||
@ -323,6 +324,7 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) {
|
|||||||
zap.L().Error("invalid rule data", zap.Error(err))
|
zap.L().Error("invalid rule data", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
alertNames = append(alertNames, rule.AlertName)
|
||||||
if rule.AlertType == "LOGS_BASED_ALERT" {
|
if rule.AlertType == "LOGS_BASED_ALERT" {
|
||||||
alertsInfo.LogsBasedAlerts = alertsInfo.LogsBasedAlerts + 1
|
alertsInfo.LogsBasedAlerts = alertsInfo.LogsBasedAlerts + 1
|
||||||
} else if rule.AlertType == "METRIC_BASED_ALERT" {
|
} else if rule.AlertType == "METRIC_BASED_ALERT" {
|
||||||
@ -346,6 +348,6 @@ func (r *ruleDB) GetAlertsInfo(ctx context.Context) (*model.AlertsInfo, error) {
|
|||||||
}
|
}
|
||||||
alertsInfo.TotalAlerts = alertsInfo.TotalAlerts + 1
|
alertsInfo.TotalAlerts = alertsInfo.TotalAlerts + 1
|
||||||
}
|
}
|
||||||
|
alertsInfo.AlertNames = alertNames
|
||||||
return &alertsInfo, nil
|
return &alertsInfo, nil
|
||||||
}
|
}
|
||||||
|
@ -314,6 +314,8 @@ func createTelemetry() {
|
|||||||
dashboardsAlertsData := map[string]interface{}{
|
dashboardsAlertsData := map[string]interface{}{
|
||||||
"totalDashboards": dashboardsInfo.TotalDashboards,
|
"totalDashboards": dashboardsInfo.TotalDashboards,
|
||||||
"totalDashboardsWithPanelAndName": dashboardsInfo.TotalDashboardsWithPanelAndName,
|
"totalDashboardsWithPanelAndName": dashboardsInfo.TotalDashboardsWithPanelAndName,
|
||||||
|
"dashboardNames": dashboardsInfo.DashboardNames,
|
||||||
|
"alertNames": alertsInfo.AlertNames,
|
||||||
"logsBasedPanels": dashboardsInfo.LogsBasedPanels,
|
"logsBasedPanels": dashboardsInfo.LogsBasedPanels,
|
||||||
"metricBasedPanels": dashboardsInfo.MetricBasedPanels,
|
"metricBasedPanels": dashboardsInfo.MetricBasedPanels,
|
||||||
"tracesBasedPanels": dashboardsInfo.TracesBasedPanels,
|
"tracesBasedPanels": dashboardsInfo.TracesBasedPanels,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user