diff --git a/grafana b/grafana index 34427f34e89..49b18e17d75 160000 --- a/grafana +++ b/grafana @@ -1 +1 @@ -Subproject commit 34427f34e89fe3913523b5b236a149b88931b71d +Subproject commit 49b18e17d7574540cdbf8d208c968ea4db202954 diff --git a/pkg/api/api.go b/pkg/api/api.go index d8489f493d3..bd28aef0413 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -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) { diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 5fcc773170d..34bb721231b 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -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 { diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go new file mode 100644 index 00000000000..0c314480657 --- /dev/null +++ b/pkg/api/metrics.go @@ -0,0 +1,36 @@ +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) +}