Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3e076052
Commit
3e076052
authored
Jan 06, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a /api/metrics/test query that returns random walk series
parent
0e3f9150
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
20 deletions
+49
-20
grafana
+1
-1
pkg/api/api.go
+3
-0
pkg/api/dtos/models.go
+9
-19
pkg/api/metrics.go
+36
-0
No files found.
grafana
@
49b18e17
Subproject commit
34427f34e89fe3913523b5b236a149b88931b71d
Subproject commit
49b18e17d7574540cdbf8d208c968ea4db202954
pkg/api/api.go
View file @
3e076052
...
...
@@ -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
)
{
...
...
pkg/api/dtos/models.go
View file @
3e076052
...
...
@@ -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
{
...
...
pkg/api/metrics.go
0 → 100644
View file @
3e076052
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment