feat: add goroutine count metric to the MetricService and update related files

This commit is contained in:
Marvin Zhang
2025-07-08 14:08:31 +08:00
parent 7e4187f388
commit 8bd3ef0b72
10 changed files with 39 additions and 11 deletions

View File

@@ -2,14 +2,15 @@ package server
import (
"context"
"sync"
"time"
"github.com/crawlab-team/crawlab/core/interfaces"
"github.com/crawlab-team/crawlab/core/models/models"
"github.com/crawlab-team/crawlab/core/models/service"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/crawlab-team/crawlab/grpc"
"go.mongodb.org/mongo-driver/bson"
"sync"
"time"
)
type MetricServiceServer struct {
@@ -40,6 +41,7 @@ func (svr MetricServiceServer) Send(_ context.Context, req *grpc.MetricServiceSe
DiskWriteBytesRate: req.DiskWriteBytesRate,
NetworkBytesSentRate: req.NetworkBytesSentRate,
NetworkBytesRecvRate: req.NetworkBytesRecvRate,
GoroutineCount: req.GoroutineCount,
}
metric.CreatedAt = time.Unix(req.Timestamp, 0)
_, err = service.NewModelService[models.Metric]().InsertOne(metric)

View File

@@ -22,4 +22,5 @@ type Metric struct {
DiskWriteBytesRate float32 `json:"disk_write_bytes_rate" bson:"disk_write_bytes_rate" description:"Disk write bytes rate"`
NetworkBytesSentRate float32 `json:"network_bytes_sent_rate" bson:"network_bytes_sent_rate" description:"Network bytes sent rate"`
NetworkBytesRecvRate float32 `json:"network_bytes_recv_rate" bson:"network_bytes_recv_rate" description:"Network bytes recv rate"`
GoroutineCount int32 `json:"goroutine_count" bson:"goroutine_count" description:"Current goroutine count"`
}

View File

@@ -2,13 +2,14 @@ package notification
import (
"fmt"
"github.com/crawlab-team/crawlab/core/interfaces"
"github.com/crawlab-team/crawlab/core/utils"
"regexp"
"strings"
"sync"
"time"
"github.com/crawlab-team/crawlab/core/interfaces"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/crawlab-team/crawlab/core/constants"
"github.com/crawlab-team/crawlab/core/entity"
"github.com/crawlab-team/crawlab/core/models/models"
@@ -471,6 +472,8 @@ func (svc *Service) getFormattedMetricValue(metricName string, m *models.Metric)
return fmt.Sprintf("%.2fMB/s", m.NetworkBytesSentRate/(1024*1024))
case "network_bytes_recv_rate":
return fmt.Sprintf("%.2fMB/s", m.NetworkBytesRecvRate/(1024*1024))
case "goroutine_count":
return fmt.Sprintf("%d", m.GoroutineCount)
default:
return "N/A"
}