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
9268ecf3
Commit
9268ecf3
authored
Mar 25, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some refinements to dashboard snapshots
parent
c8687560
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
27 deletions
+56
-27
pkg/api/dashboard_snapshot.go
+35
-2
pkg/metrics/metrics.go
+3
-2
pkg/metrics/report_usage.go
+10
-9
pkg/models/dashboard_snapshot.go
+1
-0
src/app/features/dashboard/shareSnapshotCtrl.js
+7
-14
No files found.
pkg/api/dashboard_snapshot.go
View file @
9268ecf3
package
api
import
(
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"time"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
func
CreateDashboardSnapshot
(
c
*
middleware
.
Context
,
cmd
m
.
CreateDashboardSnapshotCommand
)
{
cmd
.
Key
=
util
.
GetRandomString
(
32
)
if
cmd
.
External
{
createExternalSnapshot
(
c
,
cmd
)
}
cmd
.
Key
=
util
.
GetRandomString
(
32
)
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to create snaphost"
,
err
)
return
...
...
@@ -19,7 +29,30 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho
metrics
.
M_Api_Dashboard_Snapshot_Create
.
Inc
(
1
)
c
.
JSON
(
200
,
util
.
DynMap
{
"key"
:
cmd
.
Key
})
c
.
JSON
(
200
,
util
.
DynMap
{
"key"
:
cmd
.
Key
,
"url"
:
setting
.
ToAbsUrl
(
"/dashboard/snapshots"
)})
}
func
createExternalSnapshot
(
c
*
middleware
.
Context
,
cmd
m
.
CreateDashboardSnapshotCommand
)
{
metrics
.
M_Api_Dashboard_Snapshot_External
.
Inc
(
1
)
json
,
_
:=
json
.
Marshal
(
cmd
)
jsonData
:=
bytes
.
NewBuffer
(
json
)
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
5
*
time
.
Second
)}
resp
,
err
:=
client
.
Post
(
"http://snapshots-origin.raintank.io/api/snapshots"
,
"application/json"
,
jsonData
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to publish external snapshot"
,
err
)
return
}
c
.
Header
()
.
Set
(
"Content-Type"
,
resp
.
Header
.
Get
(
"Content-Type"
))
c
.
WriteHeader
(
resp
.
StatusCode
)
if
resp
.
ContentLength
>
0
{
bytes
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
c
.
Write
(
bytes
)
}
}
func
GetDashboardSnapshot
(
c
*
middleware
.
Context
)
{
...
...
pkg/metrics/metrics.go
View file @
9268ecf3
...
...
@@ -21,8 +21,9 @@ var (
M_Api_Login_OAuth
=
NewComboCounterRef
(
"api.login.oauth"
)
M_Api_Org_Create
=
NewComboCounterRef
(
"api.org.create"
)
M_Api_Dashboard_Snapshot_Create
=
NewComboCounterRef
(
"api.dashboard_snapshot.create"
)
M_Api_Dashboard_Snapshot_Get
=
NewComboCounterRef
(
"api.dashboard_snapshot.get"
)
M_Api_Dashboard_Snapshot_Create
=
NewComboCounterRef
(
"api.dashboard_snapshot.create"
)
M_Api_Dashboard_Snapshot_External
=
NewComboCounterRef
(
"api.dashboard_snapshot.external"
)
M_Api_Dashboard_Snapshot_Get
=
NewComboCounterRef
(
"api.dashboard_snapshot.get"
)
M_Models_Dashboard_Insert
=
NewComboCounterRef
(
"models.dashboard.insert"
)
)
pkg/metrics/report_usage.go
View file @
9268ecf3
...
...
@@ -7,7 +7,9 @@ import (
"strings"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
...
...
@@ -34,11 +36,11 @@ func sendUsageStats() {
"metrics"
:
metrics
,
}
//
statsQuery := m.GetSystemStatsQuery{}
//
if err := bus.Dispatch(&statsQuery); err != nil {
//
log.Error(3, "Failed to get system stats", err)
//
return
//
}
statsQuery
:=
m
.
GetSystemStatsQuery
{}
if
err
:=
bus
.
Dispatch
(
&
statsQuery
);
err
!=
nil
{
log
.
Error
(
3
,
"Failed to get system stats"
,
err
)
return
}
UsageStats
.
Each
(
func
(
name
string
,
i
interface
{})
{
switch
metric
:=
i
.
(
type
)
{
...
...
@@ -50,14 +52,13 @@ func sendUsageStats() {
}
})
//
metrics["stats.dashboards.count"] = statsQuery.Result.DashboardCount
//
metrics["stats.users.count"] = statsQuery.Result.UserCount
//
metrics["stats.orgs.count"] = statsQuery.Result.OrgCount
metrics
[
"stats.dashboards.count"
]
=
statsQuery
.
Result
.
DashboardCount
metrics
[
"stats.users.count"
]
=
statsQuery
.
Result
.
UserCount
metrics
[
"stats.orgs.count"
]
=
statsQuery
.
Result
.
OrgCount
out
,
_
:=
json
.
Marshal
(
report
)
data
:=
bytes
.
NewBuffer
(
out
)
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
5
*
time
.
Second
)}
go
client
.
Post
(
"https://stats.grafana.org/grafana-usage-report"
,
"application/json"
,
data
)
}
pkg/models/dashboard_snapshot.go
View file @
9268ecf3
...
...
@@ -20,6 +20,7 @@ type DashboardSnapshot struct {
type
CreateDashboardSnapshotCommand
struct
{
Dashboard
map
[
string
]
interface
{}
`json:"dashboard" binding:"Required"`
External
bool
Key
string
`json:"-"`
...
...
src/app/features/dashboard/shareSnapshotCtrl.js
View file @
9268ecf3
...
...
@@ -22,7 +22,7 @@ function (angular) {
},
2000
);
};
$scope
.
saveSnapshot
=
function
(
makePublic
)
{
$scope
.
saveSnapshot
=
function
(
external
)
{
var
dash
=
angular
.
copy
(
$scope
.
dashboard
);
// change title
dash
.
title
=
$scope
.
snapshot
.
name
;
...
...
@@ -40,22 +40,15 @@ function (angular) {
delete
panel
.
snapshotData
;
});
var
apiUrl
=
'/api/snapshots'
;
if
(
makePublic
)
{
apiUrl
=
'http://snapshots.raintank.io/api/snapshots'
;
}
backendSrv
.
post
(
apiUrl
,
{
dashboard
:
dash
}).
then
(
function
(
results
)
{
backendSrv
.
post
(
'/api/snapshots'
,
{
dashboard
:
dash
,
external
:
external
}).
then
(
function
(
results
)
{
$scope
.
loading
=
false
;
var
baseUrl
=
$location
.
absUrl
().
replace
(
$location
.
url
(),
""
);
if
(
makePublic
)
{
baseUrl
=
'http://snapshots.raintank.io'
;
if
(
external
)
{
$scope
.
snapshotUrl
=
results
.
url
;
}
else
{
var
baseUrl
=
$location
.
absUrl
().
replace
(
$location
.
url
(),
""
);
$scope
.
snapshotUrl
=
baseUrl
+
'/dashboard/snapshots/'
+
results
.
key
;
}
$scope
.
snapshotUrl
=
baseUrl
+
'/dashboard/snapshots/'
+
results
.
key
;
},
function
()
{
$scope
.
loading
=
false
;
});
...
...
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