report sample queue size (#1027)

* report sample queue size

* report sample channel size
This commit is contained in:
ulricqin 2022-07-07 10:00:08 +08:00 committed by GitHub
parent 32e6993eea
commit fe82886f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -49,6 +49,14 @@ var (
Name: "alert_queue_size",
Help: "The size of alert queue.",
}, []string{"cluster"})
// 数据转发队列,各个队列的长度
GaugeSampleQueueSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "sample_queue_size",
Help: "The size of sample queue.",
}, []string{"cluster", "channel_number"})
)
func Init() {

View File

@ -16,6 +16,8 @@ import (
"github.com/prometheus/client_golang/api"
"github.com/prometheus/prometheus/prompb"
"github.com/toolkits/pkg/logger"
promstat "github.com/didi/nightingale/v5/src/server/stat"
)
type WriterType struct {
@ -192,6 +194,8 @@ func Init(opts []config.WriterOptions, globalOpt config.WriterGlobalOpt) error {
go Writers.StartConsumer(i, Writers.chans[i])
}
go reportChanSize()
for i := 0; i < len(opts); i++ {
cli, err := api.NewClient(api.Config{
Address: opts[i].Url,
@ -226,3 +230,13 @@ func Init(opts []config.WriterOptions, globalOpt config.WriterGlobalOpt) error {
return nil
}
func reportChanSize() {
for {
time.Sleep(time.Second * 3)
for i, c := range Writers.chans {
size := len(c)
promstat.GaugeSampleQueueSize.WithLabelValues(config.C.ClusterName, fmt.Sprint(i)).Set(float64(size))
}
}
}