feat(metrics): add total number of attachments metric
This commit is contained in:
parent
fd0b2d103d
commit
cca42b9188
@ -28,11 +28,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ProjectCountKey = `project_count`
|
ProjectCountKey = `project_count`
|
||||||
UserCountKey = `user_count`
|
UserCountKey = `user_count`
|
||||||
TaskCountKey = `task_count`
|
TaskCountKey = `task_count`
|
||||||
TeamCountKey = `team_count`
|
TeamCountKey = `team_count`
|
||||||
FilesCountKey = `files_count`
|
FilesCountKey = `files_count`
|
||||||
|
AttachmentsCountKey = `attachments_count`
|
||||||
)
|
)
|
||||||
|
|
||||||
var registry *prometheus.Registry
|
var registry *prometheus.Registry
|
||||||
@ -69,6 +70,7 @@ func InitMetrics() {
|
|||||||
registerPromMetric(TaskCountKey, "The total number of tasks on this instance")
|
registerPromMetric(TaskCountKey, "The total number of tasks on this instance")
|
||||||
registerPromMetric(TeamCountKey, "The total number of teams on this instance")
|
registerPromMetric(TeamCountKey, "The total number of teams on this instance")
|
||||||
registerPromMetric(FilesCountKey, "The total number of files on this instance")
|
registerPromMetric(FilesCountKey, "The total number of files on this instance")
|
||||||
|
registerPromMetric(AttachmentsCountKey, "The total number of attachments on this instance")
|
||||||
|
|
||||||
setupActiveUsersMetric()
|
setupActiveUsersMetric()
|
||||||
setupActiveLinkSharesMetric()
|
setupActiveLinkSharesMetric()
|
||||||
|
@ -37,12 +37,16 @@ import (
|
|||||||
|
|
||||||
// RegisterListeners registers all event listeners
|
// RegisterListeners registers all event listeners
|
||||||
func RegisterListeners() {
|
func RegisterListeners() {
|
||||||
events.RegisterListener((&ProjectCreatedEvent{}).Name(), &IncreaseProjectCounter{})
|
if config.MetricsEnabled.GetBool() {
|
||||||
events.RegisterListener((&ProjectDeletedEvent{}).Name(), &DecreaseProjectCounter{})
|
events.RegisterListener((&ProjectCreatedEvent{}).Name(), &IncreaseProjectCounter{})
|
||||||
events.RegisterListener((&TaskCreatedEvent{}).Name(), &IncreaseTaskCounter{})
|
events.RegisterListener((&ProjectDeletedEvent{}).Name(), &DecreaseProjectCounter{})
|
||||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &DecreaseTaskCounter{})
|
events.RegisterListener((&TaskCreatedEvent{}).Name(), &IncreaseTaskCounter{})
|
||||||
events.RegisterListener((&TeamDeletedEvent{}).Name(), &DecreaseTeamCounter{})
|
events.RegisterListener((&TaskDeletedEvent{}).Name(), &DecreaseTaskCounter{})
|
||||||
events.RegisterListener((&TeamCreatedEvent{}).Name(), &IncreaseTeamCounter{})
|
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((&TaskCommentCreatedEvent{}).Name(), &SendTaskCommentNotification{})
|
||||||
events.RegisterListener((&TaskAssigneeCreatedEvent{}).Name(), &SendTaskAssignedNotification{})
|
events.RegisterListener((&TaskAssigneeCreatedEvent{}).Name(), &SendTaskAssignedNotification{})
|
||||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &SendTaskDeletedNotification{})
|
events.RegisterListener((&TaskDeletedEvent{}).Name(), &SendTaskDeletedNotification{})
|
||||||
@ -558,6 +562,34 @@ func (l *AddTaskToTypesense) Handle(msg *message.Message) (err error) {
|
|||||||
return
|
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
|
// Project Event Listeners
|
||||||
|
|
||||||
|
@ -64,6 +64,10 @@ func setupMetrics(a *echo.Group) {
|
|||||||
metrics.FilesCountKey,
|
metrics.FilesCountKey,
|
||||||
files.File{},
|
files.File{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
metrics.AttachmentsCountKey,
|
||||||
|
models.TaskAttachment{},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
// Set initial totals
|
// Set initial totals
|
||||||
total, err := models.GetTotalCount(c.Type)
|
total, err := models.GetTotalCount(c.Type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user