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
eb8af01a
Unverified
Commit
eb8af01a
authored
Apr 24, 2019
by
Carl Bergquist
Committed by
GitHub
Apr 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin: add more stats about roles (#16667)
closes #14967
parent
739cdcfb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
22 deletions
+73
-22
pkg/models/stats.go
+8
-1
pkg/services/sqlstore/stars_test.go
+0
-1
pkg/services/sqlstore/stats.go
+40
-8
pkg/services/sqlstore/stats_test.go
+12
-7
public/app/features/admin/state/apis.ts
+8
-1
scripts/circle-test-postgres.sh
+5
-4
No files found.
pkg/models/stats.go
View file @
eb8af01a
...
...
@@ -51,7 +51,6 @@ type GetAlertNotifierUsageStatsQuery struct {
}
type
AdminStats
struct
{
Users
int
`json:"users"`
Orgs
int
`json:"orgs"`
Dashboards
int
`json:"dashboards"`
Snapshots
int
`json:"snapshots"`
...
...
@@ -60,7 +59,15 @@ type AdminStats struct {
Playlists
int
`json:"playlists"`
Stars
int
`json:"stars"`
Alerts
int
`json:"alerts"`
Users
int
`json:"users"`
Admins
int
`json:"admins"`
Editors
int
`json:"editors"`
Viewers
int
`json:"viewers"`
ActiveUsers
int
`json:"activeUsers"`
ActiveAdmins
int
`json:"activeAdmins"`
ActiveEditors
int
`json:"activeEditors"`
ActiveViewers
int
`json:"activeViewers"`
ActiveSessions
int
`json:"activeSessions"`
}
type
GetAdminStatsQuery
struct
{
...
...
pkg/services/sqlstore/stars_test.go
View file @
eb8af01a
...
...
@@ -36,7 +36,6 @@ func TestUserStarsDataAccess(t *testing.T) {
So
(
query
.
Result
,
ShouldBeFalse
)
})
})
})
}
pkg/services/sqlstore/stats.go
View file @
eb8af01a
...
...
@@ -89,11 +89,34 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
}
func
GetAdminStats
(
query
*
m
.
GetAdminStatsQuery
)
error
{
var
rawSql
=
`SELECT
activeEndDate
:=
time
.
Now
()
.
Add
(
-
activeUserTimeLimit
)
roleCounter
:=
func
(
role
,
alias
string
)
string
{
sql
:=
`
(
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user"
)
+
`
) AS users,
FROM `
+
dialect
.
Quote
(
"user"
)
+
` as u
WHERE
(SELECT COUNT(*)
FROM org_user
WHERE org_user.user_id=u.id
AND org_user.role='`
+
role
+
`')>0
) as `
+
alias
+
`,
(
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user"
)
+
` as u
WHERE
(SELECT COUNT(*)
FROM org_user
WHERE org_user.user_id=u.id
AND org_user.role='`
+
role
+
`')>0
AND u.last_seen_at>?
) as active_`
+
alias
return
sql
}
var
rawSql
=
`SELECT
(
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"org"
)
+
`
...
...
@@ -127,14 +150,23 @@ func GetAdminStats(query *m.GetAdminStatsQuery) error {
) AS alerts,
(
SELECT COUNT(*)
from `
+
dialect
.
Quote
(
"user"
)
+
` where last_seen_at > ?
) as active_users
FROM `
+
dialect
.
Quote
(
"user"
)
+
`
) AS users,
(
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user"
)
+
` where last_seen_at > ?
) as active_users,
`
+
roleCounter
(
"Admin"
,
"admins"
)
+
`,
`
+
roleCounter
(
"Editor"
,
"editors"
)
+
`,
`
+
roleCounter
(
"Viewer"
,
"viewers"
)
+
`,
(
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user_auth_token"
)
+
` where rotated_at > ?
) as active_sessions
`
activeUserDeadlineDate
:=
time
.
Now
()
.
Add
(
-
activeUserTimeLimit
)
var
stats
m
.
AdminStats
_
,
err
:=
x
.
SQL
(
rawSql
,
active
UserDeadlineDate
)
.
Get
(
&
stats
)
_
,
err
:=
x
.
SQL
(
rawSql
,
active
EndDate
,
activeEndDate
,
activeEndDate
,
activeEndDate
,
activeEndDate
.
Unix
()
)
.
Get
(
&
stats
)
if
err
!=
nil
{
return
err
}
...
...
pkg/services/sqlstore/stats_test.go
View file @
eb8af01a
...
...
@@ -4,43 +4,48 @@ import (
"context"
"testing"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
)
func
TestStatsDataAccess
(
t
*
testing
.
T
)
{
Convey
(
"Testing Stats Data Access"
,
t
,
func
()
{
InitTestDB
(
t
)
Convey
(
"Get system stats should not results in error"
,
func
()
{
query
:=
m
.
GetSystemStatsQuery
{}
query
:=
m
odels
.
GetSystemStatsQuery
{}
err
:=
GetSystemStats
(
&
query
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Get system user count stats should not results in error"
,
func
()
{
query
:=
m
.
GetSystemUserCountStatsQuery
{}
query
:=
m
odels
.
GetSystemUserCountStatsQuery
{}
err
:=
GetSystemUserCountStats
(
context
.
Background
(),
&
query
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Get datasource stats should not results in error"
,
func
()
{
query
:=
m
.
GetDataSourceStatsQuery
{}
query
:=
m
odels
.
GetDataSourceStatsQuery
{}
err
:=
GetDataSourceStats
(
&
query
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Get datasource access stats should not results in error"
,
func
()
{
query
:=
m
.
GetDataSourceAccessStatsQuery
{}
query
:=
m
odels
.
GetDataSourceAccessStatsQuery
{}
err
:=
GetDataSourceAccessStats
(
&
query
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Get alert notifier stats should not results in error"
,
func
()
{
query
:=
m
.
GetAlertNotifierUsageStatsQuery
{}
query
:=
m
odels
.
GetAlertNotifierUsageStatsQuery
{}
err
:=
GetAlertNotifiersUsageStats
(
context
.
Background
(),
&
query
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Get admin stats should not result in error"
,
func
()
{
query
:=
models
.
GetAdminStatsQuery
{}
err
:=
GetAdminStats
(
&
query
)
So
(
err
,
ShouldBeNil
)
})
})
}
public/app/features/admin/state/apis.ts
View file @
eb8af01a
...
...
@@ -10,8 +10,15 @@ export const getServerStats = async (): Promise<ServerStat[]> => {
const
res
=
await
getBackendSrv
().
get
(
'api/admin/stats'
);
return
[
{
name
:
'Total users'
,
value
:
res
.
users
},
{
name
:
'Total dashboards'
,
value
:
res
.
dashboards
},
{
name
:
'Total admins'
,
value
:
res
.
admins
},
{
name
:
'Total editors'
,
value
:
res
.
editors
},
{
name
:
'Total viewers'
,
value
:
res
.
viewers
},
{
name
:
'Active users (seen last 30 days)'
,
value
:
res
.
activeUsers
},
{
name
:
'Active admins (seen last 30 days)'
,
value
:
res
.
activeAdmins
},
{
name
:
'Active editors (seen last 30 days)'
,
value
:
res
.
activeEditors
},
{
name
:
'Active viewers (seen last 30 days)'
,
value
:
res
.
activeViewers
},
{
name
:
'Active sessions'
,
value
:
res
.
activeSessions
},
{
name
:
'Total dashboards'
,
value
:
res
.
dashboards
},
{
name
:
'Total orgs'
,
value
:
res
.
orgs
},
{
name
:
'Total playlists'
,
value
:
res
.
playlists
},
{
name
:
'Total snapshots'
,
value
:
res
.
snapshots
},
...
...
scripts/circle-test-postgres.sh
View file @
eb8af01a
...
...
@@ -12,6 +12,7 @@ function exit_if_fail {
export
GRAFANA_TEST_DB
=
postgres
time
for
d
in
$(
go list ./pkg/...
)
;
do
exit_if_fail go
test
-tags
=
integration
$d
done
\ No newline at end of file
exit_if_fail go
test
-v
-run
=
"StatsDataAccess"
-tags
=
integration ./pkg/services/sqlstore/...
#time for d in $(go list ./pkg/...); do
# exit_if_fail go test -tags=integration $d
#done
\ No newline at end of file
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