コード例 #1
0
ファイル: 3.go プロジェクト: jingzhaoyang/rrdtool-golang
func grapher() {

	g := rrd.NewGrapher()
	g.SetTitle("Test")
	g.SetVLabel("some variable")
	g.SetSize(800, 300)
	g.SetWatermark("some watermark")
	g.Def("v1", dbfile, "p4p1_in", "AVERAGE")
	g.Def("v2", dbfile, "p4p1_out", "AVERAGE")

	g.Def("v3", dbfile, "cnt", "AVERAGE")

	g.VDef("max1", "v1,MAXIMUM")
	g.VDef("avg2", "v2,AVERAGE")
	g.VDef("avg3", "v3,AVERAGE") //avg3 是可变无特殊含义

	g.Line(1, "v1", "ff0000", "p4p1_in")
	g.Line(1, "v2", "0000ff", "p4p1_out")

	g.Line(1, "v3", "00ff00", "cnt")

	g.GPrintT("max1", "max1 at %c")
	g.GPrint("avg2", "avg2=%lf")
	g.PrintT("max1", "max1 at %c")
	g.Print("avg2", "avg2=%lf")

	now := time.Now()
	fmt.Println(now.Add(-1800 * time.Second))
	i, err := g.SaveGraph("/tmp/test_rrd1.png", now.Add(-1800*time.Second), now)
	fmt.Printf("%+v\n", i)
	if err != nil {
		fmt.Println(err)
		//	i, buf, err := g.Graph(now.Add(-1800*time.Second), now)
		//	i, _, err := g.Graph(now.Add(-1800*time.Second), now)
		//	fmt.Printf("%+v\n", i)
		//	if err != nil {
		//		fmt.Println(err)
		//	}
		//	err = ioutil.WriteFile("/tmp/test_rrd2.png", buf, 0666)
		//	if err != nil {
		//		fmt.Println(err)
		//	}
	}
}
コード例 #2
0
func grapher() {

	g := rrd.NewGrapher()
	g.SetTitle("Test")
	g.SetVLabel("some variable")
	g.SetSize(800, 300)
	g.SetWatermark("some watermark")
	for key, _ := range traffic_in_map {
		in_name := key + "_in"
		out_name := key + "_out"
		max_in_name := key + "_max"
		avg_out_name := key + "_avg"
		g.Def(in_name, dbfile, in_name, "AVERAGE")
		g.Def(out_name, dbfile, out_name, "AVERAGE")
		g.VDef(max_in_name, fmt.Sprintf("%s,MAXIMUM", in_name))
		g.VDef(avg_out_name, fmt.Sprintf("%s,AVERAGE", out_name))
		g.Line(1, in_name, "ff0000", in_name)
		g.Line(1, out_name, "0000ff", out_name)
	}

	//	g.GPrintT("max1", "max1 at %c")
	//	g.GPrint("avg2", "avg2=%lf")
	//	g.PrintT("max1", "max1 at %c")
	//	g.Print("avg2", "avg2=%lf")

	now := time.Now()
	fmt.Println(now.Add(-1800 * time.Second))
	i, err := g.SaveGraph("/tmp/test_rrd1.png", now.Add(-1800*time.Second), now)
	fmt.Printf("%+v\n", i)
	if err != nil {
		fmt.Println(err)
		//	i, buf, err := g.Graph(now.Add(-1800*time.Second), now)
		//	i, _, err := g.Graph(now.Add(-1800*time.Second), now)
		//	fmt.Printf("%+v\n", i)
		//	if err != nil {
		//		fmt.Println(err)
		//	}
		//	err = ioutil.WriteFile("/tmp/test_rrd2.png", buf, 0666)
		//	if err != nil {
		//		fmt.Println(err)
		//	}
	}
}