Skip to content

Commit

Permalink
if there is no data in an interval for one host, the time series woul…
Browse files Browse the repository at this point in the history
…d get mixed up, ensure a consistent (alphabetical) ordering of the hosts to avoid that
  • Loading branch information
fazalmajid committed Dec 1, 2020
1 parent a330607 commit 98bf268
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
35 changes: 22 additions & 13 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ func get_dests(db *sql.DB) []string {
}

func db_add_dest(db *sql.DB, host string) {
log.Printf("adding host %s", host)
_ , err := db.Exec("insert into dests (host) values (?)", host);
if err != nil {
log.Printf("adding host %s", host)
_, err := db.Exec("insert into dests (host) values (?)", host)
if err != nil {
log.Fatal("could not insert host into destinations", err)
}
}

func db_del_dest(db *sql.DB, host string) {
log.Printf("deleting host %s", host)
_ , err := db.Exec("delete from dests where host=?", host);
if err != nil {
log.Printf("deleting host %s", host)
_, err := db.Exec("delete from dests where host=?", host)
if err != nil {
log.Fatal("could not delete host from destinations", err)
}
}
Expand Down Expand Up @@ -94,13 +94,23 @@ func ResultWorker(db *sql.DB) chan *Result {
}

func get_data(db *sql.DB, since float64) (header []string, ordered []int64, points map[int64][]float64) {
rows, err := db.Query("SELECT time, host, ip, rtt FROM pings WHERE time > julianday('now')-? AND time > ?ORDER by 1, 2", display.Seconds()/86400.0, 2440587.5+since/86400000.0)
rows, err := db.Query("SELECT DISTINCT host FROM dests ORDER BY 1")
var host string
cols := make(map[string]int, 0)
colnum := 0
for rows.Next() {
err = rows.Scan(&host)
if err != nil {
log.Fatal(err)
}
colnum += 1
cols[host] = colnum
}
rows, err = db.Query("SELECT time, host, ip, rtt FROM pings WHERE time > julianday('now')-? AND time > ?ORDER by 1, 2", display.Seconds()/86400.0, 2440587.5+since/86400000.0)
if err != nil {
log.Fatal(err)
}
points = make(map[int64][]float64, 0)
colnum := 0
cols := make(map[string]int, 0)
var col int
var ok bool
var rounded time.Time
Expand All @@ -109,7 +119,7 @@ func get_data(db *sql.DB, since float64) (header []string, ordered []int64, poin

for rows.Next() {
var fts, rtt float64
var host, ip string
var ip string
err = rows.Scan(&fts, &host, &ip, &rtt)
if rtt == 0.0 || rtt == -3600e3 {
continue
Expand All @@ -126,9 +136,8 @@ func get_data(db *sql.DB, since float64) (header []string, ordered []int64, poin
ts := rounded.Unix() * 1000
col, ok = cols[host]
if !ok {
colnum += 1
cols[host] = colnum
col = colnum
log.Printf("ERROR: skipping host=%v not found in dests\n", host)
continue
}
row, ok = points[ts]
if !ok {
Expand Down
4 changes: 3 additions & 1 deletion delta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ var delta = [
{{- if (ne $i 0) }},{{end}}
[new Date({{$ts -}})
{{- range (index $.Points $ts ) -}},
{{- if (or (eq . 0.0) (eq . -3600e3)) -}}
{{- if (eq . 0.0) -}}
null
{{- else if (eq . -3600e3) -}}
{{- -100.0 -}}
{{- else -}}
{{- . -}}
Expand Down
4 changes: 3 additions & 1 deletion initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ var data = [
{{- if (ne $i 0) }},{{end}}
[new Date({{$ts -}})
{{- range (index $.Points $ts ) -}},
{{- if (or (eq . 0.0) (eq . -3600e3)) -}}
{{- if (eq . 0.0) -}}
null
{{- else if (eq . -3600e3) -}}
{{- -100.0 -}}
{{- else -}}
{{- . -}}
Expand Down
2 changes: 1 addition & 1 deletion statik.go

Large diffs are not rendered by default.

0 comments on commit 98bf268

Please sign in to comment.