master
Evan Chen 2023-08-18 10:34:20 +08:00
parent 8e07df263d
commit e5e3ba7530
2 changed files with 24 additions and 9 deletions

View File

@ -43,14 +43,14 @@
scales: {
x: {
type: 'time',
time: {
unit: 'second'
},
// time: {
// unit: 'second'
// },
position: 'bottom'
},
y: {
type: 'category',
labels: ['', 'ok','failed','']
labels: ['', 'ok','failed','down']
}
},
decimation: {

25
main.go
View File

@ -122,7 +122,7 @@ func main() {
go func() {
for {
<-time.After(time.Minute * 5)
CleanLog()
CleanLog(false)
WriteReport()
}
}()
@ -145,7 +145,7 @@ func main() {
<-wait
CleanLog()
CleanLog(true)
WriteReport()
}
@ -194,7 +194,7 @@ func (p point) GetTime() time.Time {
return t
}
func CleanLog() error {
func CleanLog(down bool) error {
file, err := os.OpenFile("network.log", os.O_RDONLY|os.O_CREATE, os.ModePerm)
if err != nil {
@ -217,8 +217,6 @@ func CleanLog() error {
return err
}
end[pt.Name] = pt
last_pt, ok := last[pt.Name]
if !ok {
last[pt.Name] = pt
@ -226,9 +224,15 @@ func CleanLog() error {
} else {
if last_pt.Stat != pt.Stat {
last[pt.Name] = pt
if pre_last, ok := end[pt.Name]; ok {
queue = append(queue, pre_last)
}
queue = append(queue, pt)
}
}
end[pt.Name] = pt
}
if err := scanner.Err(); err != nil {
log.Println(err)
@ -244,6 +248,17 @@ func CleanLog() error {
}
}
// if down {
// now := time.Now().Format("2006-01-02 15:04:05")
// for pt := range end {
// queue = append(queue, &point{
// Time: now,
// Stat: "down",
// Name: pt,
// })
// }
// }
wr.Lock()
defer wr.Unlock()
file, err = os.OpenFile("network.log", os.O_WRONLY|os.O_TRUNC, os.ModePerm)