Beispiel #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)
	}
}
Beispiel #2
0
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)
	}
}
Beispiel #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)
	}
}
Beispiel #4
0
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")
	}
}