Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

added dbOverview tab for service

Ankit Nayanade18bc11f7c
diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.go
index b7cf48c85e..0f299fab8a 100644
--- a/pkg/query-service/app/http_handler.go
+++ b/pkg/query-service/app/http_handler.go
@@ -63,6 +63,7 @@ func (aH *APIHandler) RegisterRoutes(router *mux.Router) {
router.HandleFunc("/api/v1/services", aH.getServices).Methods(http.MethodGet)
router.HandleFunc("/api/v1/services/list", aH.getServicesList).Methods(http.MethodGet)
router.HandleFunc("/api/v1/service/overview", aH.getServiceOverview).Methods(http.MethodGet)
+ router.HandleFunc("/api/v1/service/dbOverview", aH.getServiceDBOverview).Methods(http.MethodGet)
router.HandleFunc("/api/v1/service/externalAvgDuration", aH.GetServiceExternalAvgDuration).Methods(http.MethodGet)
router.HandleFunc("/api/v1/service/externalErrors", aH.getServiceExternalErrors).Methods(http.MethodGet)
router.HandleFunc("/api/v1/service/external", aH.getServiceExternal).Methods(http.MethodGet)
@@ -178,6 +179,22 @@ func (aH *APIHandler) getUsage(w http.ResponseWriter, r *http.Request) {
}
+func (aH *APIHandler) getServiceDBOverview(w http.ResponseWriter, r *http.Request) {
+
+ query, err := parseGetServiceExternalRequest(r)
+ if aH.handleError(w, err, http.StatusBadRequest) {
+ return
+ }
+
+ result, err := druidQuery.GetServiceDBOverview(aH.sqlClient, query)
+ if aH.handleError(w, err, http.StatusBadRequest) {
+ return
+ }
+
+ aH.writeJSON(w, r, result)
+
+}
+
func (aH *APIHandler) getServiceExternal(w http.ResponseWriter, r *http.Request) {
query, err := parseGetServiceExternalRequest(r)
diff --git a/pkg/query-service/druidQuery/mysql-query.go b/pkg/query-service/druidQuery/mysql-query.go
index 35e048a4e0..56d864daa0 100644
--- a/pkg/query-service/druidQuery/mysql-query.go
+++ b/pkg/query-service/druidQuery/mysql-query.go
@@ -51,6 +51,15 @@ type ServiceExternalItem struct {
CallRate float32 `json:"callRate,omitempty"`
}
+type ServiceDBOverviewItem struct {
+ Time string `json:"time,omitempty"`
+ Timestamp int64 `json:"timestamp,omitempty"`
+ DBSystem string `json:"dbSystem,omitempty"`
+ AvgDuration float32 `json:"avgDuration,omitempty"`
+ NumCalls int `json:"numCalls,omitempty"`
+ CallRate float32 `json:"callRate,omitempty"`
+}
+
type UsageItem struct {
Time string `json:"time,omitempty"`
Timestamp int64 `json:"timestamp"`
@@ -335,6 +344,43 @@ func GetServiceExternal(client *SqlClient, query *model.GetServiceOverviewParams
return &servicesExternalResponse, nil
}
+func GetServiceDBOverview(client *SqlClient, query *model.GetServiceOverviewParams) (*[]ServiceDBOverviewItem, error) {
+
+ sqlQuery := fmt.Sprintf(`SELECT TIME_FLOOR(__time, '%s') as "time", AVG(DurationNano) as "avgDuration", COUNT(SpanId) as "numCalls", DBSystem as "dbSystem" FROM %s WHERE ServiceName='%s' AND Kind='3' AND DBName IS NOT NULL
+ AND "__time" >= '%s' AND "__time" <= '%s'
+ GROUP BY TIME_FLOOR(__time, '%s'), DBSystem`, query.Period, constants.DruidDatasource, query.ServiceName, query.StartTime, query.EndTime, query.Period)
+
+ // zap.S().Debug(sqlQuery)
+
+ response, err := client.Query(sqlQuery, "object")
+
+ if err != nil {
+ zap.S().Error(query, err)
+ return nil, fmt.Errorf("Something went wrong in druid query")
+ }
+
+ // responseStr := string(response)
+ // zap.S().Info(responseStr)
+
+ res := new([]ServiceDBOverviewItem)
+ err = json.Unmarshal(response, res)
+ if err != nil {
+ zap.S().Error(err)
+ return nil, fmt.Errorf("Error in unmarshalling response from druid")
+ }
+
+ for i, _ := range *res {
+ timeObj, _ := time.Parse(time.RFC3339Nano, (*res)[i].Time)
+ (*res)[i].Timestamp = int64(timeObj.UnixNano())
+ (*res)[i].Time = ""
+ (*res)[i].CallRate = float32((*res)[i].NumCalls) / float32(query.StepSeconds)
+
+ }
+
+ servicesDBOverviewResponse := (*res)[1:]
+ return &servicesDBOverviewResponse, nil
+}
+
func GetServiceOverview(client *SqlClient, query *model.GetServiceOverviewParams) (*[]ServiceOverviewItem, error) {
sqlQuery := fmt.Sprintf(`SELECT TIME_FLOOR(__time, '%s') as "time", APPROX_QUANTILE_DS("QuantileDuration", 0.5) as p50, APPROX_QUANTILE_DS("QuantileDuration", 0.9) as p90,