Commit 3e076052 by Torkel Ödegaard

added a /api/metrics/test query that returns random walk series

parent 0e3f9150
Subproject commit 34427f34e89fe3913523b5b236a149b88931b71d
Subproject commit 49b18e17d7574540cdbf8d208c968ea4db202954
......@@ -49,6 +49,9 @@ func Register(m *macaron.Macaron) {
// rendering
m.Get("/render/*", auth, RenderToPng)
// metrics
m.Get("/api/metrics/test", auth, GetTestMetrics)
}
func Index(ctx *middleware.Context) {
......
......@@ -19,25 +19,6 @@ type CurrentUser struct {
GravatarUrl string `json:"gravatarUrl"`
}
type AccountInfo struct {
Email string `json:"email"`
Name string `json:"name"`
Collaborators []*Collaborator `json:"collaborators"`
}
type OtherAccount struct {
Id int64 `json:"id"`
Name string `json:"name"`
Role string `json:"role"`
IsUsing bool `json:"isUsing"`
}
type Collaborator struct {
AccountId int64 `json:"accountId"`
Email string `json:"email"`
Role string `json:"role"`
}
type DataSource struct {
Id int64 `json:"id"`
AccountId int64 `json:"accountId"`
......@@ -51,6 +32,15 @@ type DataSource struct {
BasicAuth bool `json:"basicAuth"`
}
type MetricQueryResultDto struct {
Data []MetricQueryResultDataDto `json:"data"`
}
type MetricQueryResultDataDto struct {
Target string `json:"target"`
DataPoints [][2]float64 `json:"datapoints"`
}
func NewCurrentUser(account *models.Account) *CurrentUser {
model := &CurrentUser{}
if account != nil {
......
package api
import (
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/middleware"
"math/rand"
"strconv"
)
func GetTestMetrics(c *middleware.Context) {
from := c.QueryInt64("from")
to := c.QueryInt64("to")
maxDataPoints := c.QueryInt64("maxDataPoints")
stepInSeconds := (to - from) / maxDataPoints
result := dtos.MetricQueryResultDto{}
result.Data = make([]dtos.MetricQueryResultDataDto, 1)
for seriesIndex := range result.Data {
points := make([][2]float64, maxDataPoints)
walker := rand.Float64() * 100
time := from
for i := range points {
points[i][0] = walker
points[i][1] = float64(time)
walker += rand.Float64() - 0.5
time += stepInSeconds
}
result.Data[seriesIndex].Target = "test-series-" + strconv.Itoa(seriesIndex)
result.Data[seriesIndex].DataPoints = points
}
c.JSON(200, &result)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment