mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 01:32:25 -05:00
[feature] add metrics for worker counts, and worker queue sizes (#4387)
should help to debug https://codeberg.org/superseriousbusiness/gotosocial/issues/4309 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4387 Reviewed-by: Daenney <daenney@noreply.codeberg.org> Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
3fad524089
commit
1144ac037f
6 changed files with 169 additions and 10 deletions
|
|
@ -24,7 +24,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"code.superseriousbusiness.org/gotosocial/internal/config"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/db"
|
||||
"code.superseriousbusiness.org/gotosocial/internal/state"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/technologize/otel-go-contrib/otelginmetrics"
|
||||
|
|
@ -36,7 +36,7 @@ import (
|
|||
"go.opentelemetry.io/otel/sdk/metric/exemplar"
|
||||
)
|
||||
|
||||
func InitializeMetrics(ctx context.Context, db db.DB) error {
|
||||
func InitializeMetrics(ctx context.Context, state *state.State) error {
|
||||
if !config.GetMetricsEnabled() {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -73,8 +73,8 @@ func InitializeMetrics(ctx context.Context, db db.DB) error {
|
|||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.instance.total_users",
|
||||
metric.WithDescription("Total number of users on this instance"),
|
||||
metric.WithInt64Callback(func(c context.Context, o metric.Int64Observer) error {
|
||||
userCount, err := db.CountInstanceUsers(c, thisInstance)
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
userCount, err := state.DB.CountInstanceUsers(ctx, thisInstance)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -89,8 +89,8 @@ func InitializeMetrics(ctx context.Context, db db.DB) error {
|
|||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.instance.total_statuses",
|
||||
metric.WithDescription("Total number of statuses on this instance"),
|
||||
metric.WithInt64Callback(func(c context.Context, o metric.Int64Observer) error {
|
||||
statusCount, err := db.CountInstanceStatuses(c, thisInstance)
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
statusCount, err := state.DB.CountInstanceStatuses(ctx, thisInstance)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -105,8 +105,8 @@ func InitializeMetrics(ctx context.Context, db db.DB) error {
|
|||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.instance.total_federating_instances",
|
||||
metric.WithDescription("Total number of other instances this instance is federating with"),
|
||||
metric.WithInt64Callback(func(c context.Context, o metric.Int64Observer) error {
|
||||
federatingCount, err := db.CountInstanceDomains(c, thisInstance)
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
federatingCount, err := state.DB.CountInstanceDomains(ctx, thisInstance)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -118,6 +118,150 @@ func InitializeMetrics(ctx context.Context, db db.DB) error {
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.workers.delivery.count",
|
||||
metric.WithDescription("Current number of delivery workers"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Delivery.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableUpDownCounter(
|
||||
"gotosocial.workers.delivery.queue",
|
||||
metric.WithDescription("Current number of queued delivery worker tasks"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Delivery.Queue.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.workers.dereference.count",
|
||||
metric.WithDescription("Current number of dereference workers"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Dereference.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableUpDownCounter(
|
||||
"gotosocial.workers.dereference.queue",
|
||||
metric.WithDescription("Current number of queued dereference worker tasks"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Dereference.Queue.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.workers.client_api.count",
|
||||
metric.WithDescription("Current number of client API workers"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Client.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableUpDownCounter(
|
||||
"gotosocial.workers.client_api.queue",
|
||||
metric.WithDescription("Current number of queued client API worker tasks"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Client.Queue.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.workers.fedi_api.count",
|
||||
metric.WithDescription("Current number of federator API workers"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Federator.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableUpDownCounter(
|
||||
"gotosocial.workers.fedi_api.queue",
|
||||
metric.WithDescription("Current number of queued federator API worker tasks"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Federator.Queue.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.workers.processing.count",
|
||||
metric.WithDescription("Current number of processing workers"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Processing.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableUpDownCounter(
|
||||
"gotosocial.workers.processing.queue",
|
||||
metric.WithDescription("Current number of queued processing worker tasks"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.Processing.Queue.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableGauge(
|
||||
"gotosocial.workers.webpush.count",
|
||||
metric.WithDescription("Current number of webpush workers"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.WebPush.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = meter.Int64ObservableUpDownCounter(
|
||||
"gotosocial.workers.webpush.queue",
|
||||
metric.WithDescription("Current number of queued webpush worker tasks"),
|
||||
metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error {
|
||||
o.Observe(int64(state.Workers.WebPush.Queue.Len()))
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue