Skip to content

Commit bb52c79

Browse files
committed
Add an interval flag to customize URL fetch interval
Fixes #3
1 parent 256cd5f commit bb52c79

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/wcharczuk/go-chart/seq"
2525
)
2626

27+
const titleBarSize = 25
28+
2729
type graphSpec struct {
2830
fields []field
2931
}
@@ -37,6 +39,8 @@ type field struct {
3739

3840
func main() {
3941
url := flag.String("url", "", "URL to fetch every second. Read JSON objects from stdin if not specified.")
42+
interval := flag.Duration("interval", time.Second, "When url is provided, defines the interval between fetches."+
43+
" Note that counter fields are computed based on this interval.")
4044
steps := flag.Int("steps", 100, "Number of values to plot.")
4145
flag.Parse()
4246

@@ -64,17 +68,17 @@ func main() {
6468
}
6569
select {
6670
case <-t.C:
67-
render(specs, dp, width, height-25)
71+
render(specs, dp, width, height-titleBarSize)
6872
case <-exit:
69-
render(specs, dp, width, height-25)
73+
render(specs, dp, width, height-titleBarSize)
7074
return
7175
}
7276
}
7377
}()
7478

7579
var s source.Getter = source.NewStdin()
7680
if *url != "" {
77-
s = source.NewHTTP(*url, time.Second)
81+
s = source.NewHTTP(*url, *interval)
7882
}
7983
defer s.Close()
8084
for {

0 commit comments

Comments
 (0)