|
|
@ -3,18 +3,15 @@ package db
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status/check"
|
|
|
|
"status/check"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
//PingEntry represents an entry of Ping that is persisted in the DB.
|
|
|
|
//PingEntry represents an entry of Ping that is persisted in the DB.
|
|
|
|
type PingEntry struct {
|
|
|
|
type PingEntry struct {
|
|
|
|
gorm.Model
|
|
|
|
ServiceName string `json:"service_name"`
|
|
|
|
ServiceName string
|
|
|
|
Time time.Time `json:"query_time"`
|
|
|
|
Time time.Time
|
|
|
|
Ping int64 `json:"ping"`
|
|
|
|
Ping int64
|
|
|
|
Status check.Result `json:"status"`
|
|
|
|
Status check.Result
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p PingEntry) AddToDB() {
|
|
|
|
func (p PingEntry) AddToDB() {
|
|
|
@ -24,8 +21,12 @@ func (p PingEntry) AddToDB() {
|
|
|
|
db.Create(&p)
|
|
|
|
db.Create(&p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func GetFromDB(serviceName string, from, to time.Time) []*PingEntry {
|
|
|
|
func GetFromDB(serviceName string, from, to time.Time) []PingEntry {
|
|
|
|
entries := make([]*PingEntry, 0)
|
|
|
|
entries := make([]PingEntry, 0)
|
|
|
|
|
|
|
|
if serviceName == "" {
|
|
|
|
|
|
|
|
db.Where("time BETWEEN ? AND ?", from, to).Find(&entries)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
db.Where("service_name = ? AND time BETWEEN ? AND ?", serviceName, from, to).Find(&entries)
|
|
|
|
db.Where("service_name = ? AND time BETWEEN ? AND ?", serviceName, from, to).Find(&entries)
|
|
|
|
|
|
|
|
}
|
|
|
|
return entries
|
|
|
|
return entries
|
|
|
|
}
|
|
|
|
}
|
|
|
|