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: { scales: {
x: { x: {
type: 'time', type: 'time',
time: { // time: {
unit: 'second' // unit: 'second'
}, // },
position: 'bottom' position: 'bottom'
}, },
y: { y: {
type: 'category', type: 'category',
labels: ['', 'ok','failed',''] labels: ['', 'ok','failed','down']
} }
}, },
decimation: { decimation: {

25
main.go
View File

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