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
2be60887
Commit
2be60887
authored
Feb 07, 2019
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds usage stats for sessions
parent
6e7941d3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
6 deletions
+23
-6
pkg/infra/usagestats/service.go
+4
-4
pkg/infra/usagestats/usage_stats.go
+9
-0
pkg/infra/usagestats/usage_stats_test.go
+7
-1
pkg/models/stats.go
+1
-0
pkg/services/sqlstore/stats.go
+2
-1
No files found.
pkg/infra/usagestats/service.go
View file @
2be60887
...
...
@@ -5,7 +5,7 @@ import (
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/services/
auth
"
"github.com/grafana/grafana/pkg/services/
sqlstore
"
"github.com/grafana/grafana/pkg/social"
"github.com/grafana/grafana/pkg/log"
...
...
@@ -20,9 +20,9 @@ func init() {
}
type
UsageStatsService
struct
{
Cfg
*
setting
.
Cfg
`inject:""`
TokenService
*
auth
.
UserAuthTokenService
`inject:""`
Bus
bus
.
Bus
`inject:""`
Cfg
*
setting
.
Cfg
`inject:""`
Bus
bus
.
Bus
`inject:""`
SQLStore
*
sqlstore
.
SqlStore
`inject:""`
oauthProviders
map
[
string
]
bool
}
...
...
pkg/infra/usagestats/usage_stats.go
View file @
2be60887
...
...
@@ -59,6 +59,15 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
metrics
[
"stats.provisioned_dashboards.count"
]
=
statsQuery
.
Result
.
ProvisionedDashboards
metrics
[
"stats.snapshots.count"
]
=
statsQuery
.
Result
.
Snapshots
metrics
[
"stats.teams.count"
]
=
statsQuery
.
Result
.
Teams
metrics
[
"stats.total_sessions.count"
]
=
statsQuery
.
Result
.
Sessions
userCount
:=
statsQuery
.
Result
.
Users
avgSessionsPerUser
:=
statsQuery
.
Result
.
Sessions
if
userCount
!=
0
{
avgSessionsPerUser
=
avgSessionsPerUser
/
userCount
}
metrics
[
"stats.avg_sessions_per_user.count"
]
=
avgSessionsPerUser
dsStats
:=
models
.
GetDataSourceStatsQuery
{}
if
err
:=
uss
.
Bus
.
Dispatch
(
&
dsStats
);
err
!=
nil
{
...
...
pkg/infra/usagestats/usage_stats_test.go
View file @
2be60887
...
...
@@ -15,6 +15,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
.
"github.com/smartystreets/goconvey/convey"
)
...
...
@@ -22,7 +23,8 @@ import (
func
TestMetrics
(
t
*
testing
.
T
)
{
Convey
(
"Test send usage stats"
,
t
,
func
()
{
uss
:=
&
UsageStatsService
{
Bus
:
bus
.
New
(),
Bus
:
bus
.
New
(),
SQLStore
:
sqlstore
.
InitTestDB
(
t
),
}
var
getSystemStatsQuery
*
models
.
GetSystemStatsQuery
...
...
@@ -43,6 +45,7 @@ func TestMetrics(t *testing.T) {
ProvisionedDashboards
:
12
,
Snapshots
:
13
,
Teams
:
14
,
Sessions
:
15
,
}
getSystemStatsQuery
=
query
return
nil
...
...
@@ -226,6 +229,8 @@ func TestMetrics(t *testing.T) {
So
(
metrics
.
Get
(
"stats.provisioned_dashboards.count"
)
.
MustInt
(),
ShouldEqual
,
getSystemStatsQuery
.
Result
.
ProvisionedDashboards
)
So
(
metrics
.
Get
(
"stats.snapshots.count"
)
.
MustInt
(),
ShouldEqual
,
getSystemStatsQuery
.
Result
.
Snapshots
)
So
(
metrics
.
Get
(
"stats.teams.count"
)
.
MustInt
(),
ShouldEqual
,
getSystemStatsQuery
.
Result
.
Teams
)
So
(
metrics
.
Get
(
"stats.total_sessions.count"
)
.
MustInt64
(),
ShouldEqual
,
15
)
So
(
metrics
.
Get
(
"stats.avg_sessions_per_user.count"
)
.
MustInt64
(),
ShouldEqual
,
5
)
So
(
metrics
.
Get
(
"stats.ds."
+
models
.
DS_ES
+
".count"
)
.
MustInt
(),
ShouldEqual
,
9
)
So
(
metrics
.
Get
(
"stats.ds."
+
models
.
DS_PROMETHEUS
+
".count"
)
.
MustInt
(),
ShouldEqual
,
10
)
...
...
@@ -251,6 +256,7 @@ func TestMetrics(t *testing.T) {
So
(
metrics
.
Get
(
"stats.auth_enabled.oauth_grafana_com.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.packaging.deb.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
})
})
...
...
pkg/models/stats.go
View file @
2be60887
...
...
@@ -15,6 +15,7 @@ type SystemStats struct {
FolderPermissions
int64
Folders
int64
ProvisionedDashboards
int64
Sessions
int64
}
type
DataSourceStats
struct
{
...
...
pkg/services/sqlstore/stats.go
View file @
2be60887
...
...
@@ -74,7 +74,8 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"dashboard_provisioning"
)
+
`) AS provisioned_dashboards,`
)
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"dashboard_snapshot"
)
+
`) AS snapshots,`
)
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"team"
)
+
`) AS teams`
)
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"team"
)
+
`) AS teams,`
)
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"user_auth_token"
)
+
`) AS sessions`
)
var
stats
m
.
SystemStats
_
,
err
:=
x
.
SQL
(
sb
.
GetSqlString
(),
sb
.
params
...
)
.
Get
(
&
stats
)
...
...
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