Exemple #1
0
func init() {
	d = dal.NewDAL()
	d.CreateBuckets()

	const (
		hostUsage         = "The host IP or hostname to ping"
		ipUsage           = "The ip to query"
		showExamplesUsage = "Show example usage"
		startUsage        = "The time to start querying ping times"
		endUsage          = "The time to end querying ping times (all time up to this point)"
		groupUsage        = "The duration by which to group the results, supports (s)econds, (m)inutes, (h)ours"
	)

	flag.BoolVar(&showExamples, "examples", false, showExamplesUsage)

	flag.StringVar(&ip, "ip", "", ipUsage)

	flag.StringVar(&host, "host", "", hostUsage)
	flag.StringVar(&host, "h", "", "-host")

	flag.StringVar(&start, "start", "", startUsage)
	flag.StringVar(&start, "s", "", "-start")

	flag.StringVar(&start, "end", "", endUsage)
	flag.StringVar(&end, "e", "", "-end")

	flag.StringVar(&groupBy, "groupby", "1h", groupUsage)
	flag.StringVar(&groupBy, "g", "", "-groupby")
}
Exemple #2
0
func Test_main_integration(t *testing.T) {
	Convey("Should ping localhost once and save to db", t, func() {
		Reset(func() {
			os.Remove("pinghist.db")
		})
		ip := "127.0.0.1"
		startTime := time.Now()

		pr, err := ping.Ping(ip)
		So(pr, ShouldNotBeNil)
		So(err, ShouldBeNil)

		d := dal.NewDAL()
		d.CreateBuckets()
		err = d.SavePing(ip, startTime, float32(pr.Time))
		So(err, ShouldBeNil)

		groups, err := d.GetPings(ip, startTime, startTime.Add(1*time.Minute), 1*time.Hour)

		So(err, ShouldBeNil)
		So(len(groups), ShouldEqual, 1)
		So(groups[0].MaxTime, ShouldEqual, pr.Time)
		So(groups[0].MinTime, ShouldEqual, pr.Time)
		So(groups[0].AvgTime, ShouldEqual, pr.Time)
		So(groups[0].StdDev, ShouldEqual, 0)
		So(groups[0].Received, ShouldEqual, 1)
		So(groups[0].Timedout, ShouldEqual, 0)
		So(groups[0].TotalTime, ShouldEqual, pr.Time)
	})
}