Add monitor configuration, history, and daily rollup models for the operations channel monitoring module.
42 lines
1.8 KiB
Go
42 lines
1.8 KiB
Go
package model
|
|
|
|
type ChannelMonitorDailyRollup struct {
|
|
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
MonitorId int `json:"monitor_id" gorm:"not null;index;uniqueIndex:idx_channel_monitor_daily_rollup,priority:1"`
|
|
ChannelId int `json:"channel_id" gorm:"index;uniqueIndex:idx_channel_monitor_daily_rollup,priority:2"`
|
|
ModelName string `json:"model_name" gorm:"size:128;not null;uniqueIndex:idx_channel_monitor_daily_rollup,priority:3"`
|
|
Date string `json:"date" gorm:"size:10;not null;uniqueIndex:idx_channel_monitor_daily_rollup,priority:4"`
|
|
TotalChecks int `json:"total_checks" gorm:"not null;default:0"`
|
|
PassCount int `json:"pass_count" gorm:"not null;default:0"`
|
|
DegradedCount int `json:"degraded_count" gorm:"not null;default:0"`
|
|
FailedCount int `json:"failed_count" gorm:"not null;default:0"`
|
|
AvgLatencyMs int `json:"avg_latency_ms" gorm:"not null;default:0"`
|
|
}
|
|
|
|
func (ChannelMonitorDailyRollup) TableName() string {
|
|
return "channel_monitor_daily_rollups"
|
|
}
|
|
|
|
func GetChannelMonitorDailyRollups(monitorId int, modelName string, startDate string, endDate string) ([]ChannelMonitorDailyRollup, error) {
|
|
var rollups []ChannelMonitorDailyRollup
|
|
query := DB.Model(&ChannelMonitorDailyRollup{})
|
|
if monitorId > 0 {
|
|
query = query.Where("monitor_id = ?", monitorId)
|
|
}
|
|
if modelName != "" {
|
|
query = query.Where("model_name = ?", modelName)
|
|
}
|
|
if startDate != "" {
|
|
query = query.Where("date >= ?", startDate)
|
|
}
|
|
if endDate != "" {
|
|
query = query.Where("date <= ?", endDate)
|
|
}
|
|
err := query.Order("date DESC").Find(&rollups).Error
|
|
return rollups, err
|
|
}
|
|
|
|
func GetMonitorDailyRollups(monitorId int, modelName string, startDate string, endDate string) ([]ChannelMonitorDailyRollup, error) {
|
|
return GetChannelMonitorDailyRollups(monitorId, modelName, startDate, endDate)
|
|
}
|