feat(metrics): add total number of attachments metric
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
fd0b2d103d
commit
cca42b9188
@ -28,11 +28,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ProjectCountKey = `project_count`
|
||||
UserCountKey = `user_count`
|
||||
TaskCountKey = `task_count`
|
||||
TeamCountKey = `team_count`
|
||||
FilesCountKey = `files_count`
|
||||
ProjectCountKey = `project_count`
|
||||
UserCountKey = `user_count`
|
||||
TaskCountKey = `task_count`
|
||||
TeamCountKey = `team_count`
|
||||
FilesCountKey = `files_count`
|
||||
AttachmentsCountKey = `attachments_count`
|
||||
)
|
||||
|
||||
var registry *prometheus.Registry
|
||||
@ -69,6 +70,7 @@ func InitMetrics() {
|
||||
registerPromMetric(TaskCountKey, "The total number of tasks on this instance")
|
||||
registerPromMetric(TeamCountKey, "The total number of teams on this instance")
|
||||
registerPromMetric(FilesCountKey, "The total number of files on this instance")
|
||||
registerPromMetric(AttachmentsCountKey, "The total number of attachments on this instance")
|
||||
|
||||
setupActiveUsersMetric()
|
||||
setupActiveLinkSharesMetric()
|
||||
|
@ -37,12 +37,16 @@ import (
|
||||
|
||||
// RegisterListeners registers all event listeners
|
||||
func RegisterListeners() {
|
||||
events.RegisterListener((&ProjectCreatedEvent{}).Name(), &IncreaseProjectCounter{})
|
||||
events.RegisterListener((&ProjectDeletedEvent{}).Name(), &DecreaseProjectCounter{})
|
||||
events.RegisterListener((&TaskCreatedEvent{}).Name(), &IncreaseTaskCounter{})
|
||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &DecreaseTaskCounter{})
|
||||
events.RegisterListener((&TeamDeletedEvent{}).Name(), &DecreaseTeamCounter{})
|
||||
events.RegisterListener((&TeamCreatedEvent{}).Name(), &IncreaseTeamCounter{})
|
||||
if config.MetricsEnabled.GetBool() {
|
||||
events.RegisterListener((&ProjectCreatedEvent{}).Name(), &IncreaseProjectCounter{})
|
||||
events.RegisterListener((&ProjectDeletedEvent{}).Name(), &DecreaseProjectCounter{})
|
||||
events.RegisterListener((&TaskCreatedEvent{}).Name(), &IncreaseTaskCounter{})
|
||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &DecreaseTaskCounter{})
|
||||
events.RegisterListener((&TeamDeletedEvent{}).Name(), &DecreaseTeamCounter{})
|
||||
events.RegisterListener((&TeamCreatedEvent{}).Name(), &IncreaseTeamCounter{})
|
||||
events.RegisterListener((&TaskAttachmentCreatedEvent{}).Name(), &IncreaseAttachmentCounter{})
|
||||
events.RegisterListener((&TaskAttachmentDeletedEvent{}).Name(), &DecreaseAttachmentCounter{})
|
||||
}
|
||||
events.RegisterListener((&TaskCommentCreatedEvent{}).Name(), &SendTaskCommentNotification{})
|
||||
events.RegisterListener((&TaskAssigneeCreatedEvent{}).Name(), &SendTaskAssignedNotification{})
|
||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &SendTaskDeletedNotification{})
|
||||
@ -558,6 +562,34 @@ func (l *AddTaskToTypesense) Handle(msg *message.Message) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// IncreaseAttachmentCounter represents a listener
|
||||
type IncreaseAttachmentCounter struct {
|
||||
}
|
||||
|
||||
// Name defines the name for the IncreaseAttachmentCounter listener
|
||||
func (s *IncreaseAttachmentCounter) Name() string {
|
||||
return "increase.attachment.counter"
|
||||
}
|
||||
|
||||
// Handle is executed when the event IncreaseAttachmentCounter listens on is fired
|
||||
func (s *IncreaseAttachmentCounter) Handle(msg *message.Message) (err error) {
|
||||
return keyvalue.IncrBy(metrics.AttachmentsCountKey, 1)
|
||||
}
|
||||
|
||||
// DecreaseAttachmentCounter represents a listener
|
||||
type DecreaseAttachmentCounter struct {
|
||||
}
|
||||
|
||||
// Name defines the name for the DecreaseAttachmentCounter listener
|
||||
func (s *DecreaseAttachmentCounter) Name() string {
|
||||
return "decrease.attachment.counter"
|
||||
}
|
||||
|
||||
// Handle is executed when the event DecreaseAttachmentCounter listens on is fired
|
||||
func (s *DecreaseAttachmentCounter) Handle(msg *message.Message) (err error) {
|
||||
return keyvalue.DecrBy(metrics.AttachmentsCountKey, 1)
|
||||
}
|
||||
|
||||
///////
|
||||
// Project Event Listeners
|
||||
|
||||
|
@ -64,6 +64,10 @@ func setupMetrics(a *echo.Group) {
|
||||
metrics.FilesCountKey,
|
||||
files.File{},
|
||||
},
|
||||
{
|
||||
metrics.AttachmentsCountKey,
|
||||
models.TaskAttachment{},
|
||||
},
|
||||
} {
|
||||
// Set initial totals
|
||||
total, err := models.GetTotalCount(c.Type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user