diff --git a/server/graph.go b/server/graph.go
index 054fe8eac4a18827b82bfe6c8f84519493d1f705..941e51de6b8a994b65111c26181178e7cc2258c4 100644 (file)
--- a/server/graph.go
+++ b/server/graph.go
"fmt"
"io"
"net/http"
- "strings"
"time"
"code.google.com/p/plotinum/plot"
)
func (s *Server) graph(w http.ResponseWriter, req request) {
- if len(req.args) < 2 {
- s.internal(w, fmt.Errorf("Missing host/metric information"))
+ if len(req.args) != 2 {
+ s.badrequest(w, fmt.Errorf("Missing host/metric information"))
}
host := proto.EscapeString(req.args[0])
- metric := proto.EscapeString(strings.Join(req.args[1:], "/"))
+ metric := proto.EscapeString(req.args[1])
res, err := s.query(fmt.Sprintf("TIMESERIES %s.%s", host, metric))
if err != nil {
s.internal(w, fmt.Errorf("Failed to retrieve graph data: %v", err))
return
}
p.Add(plotter.NewGrid())
+ p.X.Tick.Marker = dateTicks
var i int
for name, data := range ts.Data {
io.Copy(w, &buf)
}
+func dateTicks(min, max float64) []plot.Tick {
+ // TODO: this is surely not the best we can do
+ // but it'll distribute ticks evenly.
+ ticks := plot.DefaultTicks(min, max)
+ for i, t := range ticks {
+ if t.Label == "" {
+ // Skip minor ticks.
+ continue
+ }
+ ticks[i].Label = time.Unix(0, int64(t.Value)).Format(time.RFC822)
+ }
+ return ticks
+}
+
// vim: set tw=78 sw=4 sw=4 noexpandtab :