示例#1
0
func metric(ctx *web.Context, nodename string, property string) {
	m, err := graphpaper.GetMetric(nodename, property)
	if err != nil {
		log.Println("error: failed to fetch metric", err)
		ctx.Abort(500, "Error")
	} else {
		metricTemplate.render(ctx, m)
	}
}
示例#2
0
文件: index.go 项目: Qyrus/graphpaper
func index(ctx *web.Context) {
	nodes, err := graphpaper.NodeList(time.Seconds())
	if err != nil {
		log.Println("error: failed to fetch nodes", err)
		ctx.Abort(500, "Error")
	} else {
		data := struct{ Nodes *[]graphpaper.Node }{nodes}
		indexTemplate.render(ctx, data)
	}
}
示例#3
0
func node(ctx *web.Context, nodename string) {
	n := graphpaper.Node{nodename} // todo: should be a real method
	metrics, err := n.Metrics(time.Nanoseconds()-(86400*1000000000), time.Nanoseconds())
	if err != nil {
		log.Println("error: failed to fetch metrics", err)
		ctx.Abort(500, "Error")
	} else {
		data := struct {
			graphpaper.Node
			Metrics *[]graphpaper.Metric
		}{n, metrics}
		nodeTemplate.render(ctx, data)
	}
}
示例#4
0
文件: graph.go 项目: Qyrus/graphpaper
func graph(ctx *web.Context, nodename string, property string, width string, height string) {

	m, err := graphpaper.GetMetric(nodename, property)
	if err != nil {
		log.Println("error: failed to get metric", err)
		ctx.Abort(500, "Error")
		return
	}

	w, err := strconv.Atoui(width)
	if err != nil {
		log.Println("error: failed to convert height", err)
		ctx.Abort(500, "Error")
		return
	}

	h, err := strconv.Atoui(height)
	if err != nil {
		log.Println("error: failed to convert height", err)
		ctx.Abort(500, "Error")
		return
	}

	table, err := m.GetMeasurements(time.Seconds()-86400, time.Seconds())
	if err != nil {
		log.Println("error: failed to fetch metrics", err)
		ctx.Abort(500, "Error")
		return
	}

	ctx.SetHeader("Content-type", "image/png", true)
	err = graphpaper.DrawTable(ctx, table, w, h)
	if err != nil {
		log.Println("error: failed to draw graph", err)
		ctx.Abort(500, "Error")
	}
}