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
1aadb442
Unverified
Commit
1aadb442
authored
Jun 06, 2019
by
Carl Bergquist
Committed by
GitHub
Jun 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
metrics: expose stats about roles as metrics (#17469)
parent
c31b939e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
32 deletions
+98
-32
pkg/infra/metrics/metrics.go
+52
-1
pkg/infra/usagestats/usage_stats.go
+6
-0
pkg/models/stats.go
+8
-0
pkg/services/alerting/models.go
+1
-2
pkg/services/sqlstore/stats.go
+31
-29
No files found.
pkg/infra/metrics/metrics.go
View file @
1aadb442
...
@@ -43,8 +43,10 @@ var (
...
@@ -43,8 +43,10 @@ var (
// Timers
// Timers
M_DataSource_ProxyReq_Timer
prometheus
.
Summary
M_DataSource_ProxyReq_Timer
prometheus
.
Summary
M_Alerting_Execution_Time
prometheus
.
Summary
M_Alerting_Execution_Time
prometheus
.
Summary
)
// StatTotals
// StatTotals
var
(
M_Alerting_Active_Alerts
prometheus
.
Gauge
M_Alerting_Active_Alerts
prometheus
.
Gauge
M_StatTotal_Dashboards
prometheus
.
Gauge
M_StatTotal_Dashboards
prometheus
.
Gauge
M_StatTotal_Users
prometheus
.
Gauge
M_StatTotal_Users
prometheus
.
Gauge
...
@@ -52,6 +54,13 @@ var (
...
@@ -52,6 +54,13 @@ var (
M_StatTotal_Orgs
prometheus
.
Gauge
M_StatTotal_Orgs
prometheus
.
Gauge
M_StatTotal_Playlists
prometheus
.
Gauge
M_StatTotal_Playlists
prometheus
.
Gauge
StatsTotalViewers
prometheus
.
Gauge
StatsTotalEditors
prometheus
.
Gauge
StatsTotalAdmins
prometheus
.
Gauge
StatsTotalActiveViewers
prometheus
.
Gauge
StatsTotalActiveEditors
prometheus
.
Gauge
StatsTotalActiveAdmins
prometheus
.
Gauge
// M_Grafana_Version is a gauge that contains build info about this binary
// M_Grafana_Version is a gauge that contains build info about this binary
//
//
// Deprecated: use M_Grafana_Build_Version instead.
// Deprecated: use M_Grafana_Build_Version instead.
...
@@ -274,6 +283,42 @@ func init() {
...
@@ -274,6 +283,42 @@ func init() {
Namespace
:
exporterName
,
Namespace
:
exporterName
,
})
})
StatsTotalViewers
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"stat_totals_viewers"
,
Help
:
"total amount of viewers"
,
Namespace
:
exporterName
,
})
StatsTotalEditors
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"stat_totals_editors"
,
Help
:
"total amount of editors"
,
Namespace
:
exporterName
,
})
StatsTotalAdmins
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"stat_totals_admins"
,
Help
:
"total amount of admins"
,
Namespace
:
exporterName
,
})
StatsTotalActiveViewers
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"stat_totals_active_viewers"
,
Help
:
"total amount of viewers"
,
Namespace
:
exporterName
,
})
StatsTotalActiveEditors
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"stat_totals_active_editors"
,
Help
:
"total amount of active editors"
,
Namespace
:
exporterName
,
})
StatsTotalActiveAdmins
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"stat_totals_active_admins"
,
Help
:
"total amount of active admins"
,
Namespace
:
exporterName
,
})
M_Grafana_Version
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
M_Grafana_Version
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"info"
,
Name
:
"info"
,
Help
:
"Information about the Grafana. This metric is deprecated. please use `grafana_build_info`"
,
Help
:
"Information about the Grafana. This metric is deprecated. please use `grafana_build_info`"
,
...
@@ -339,6 +384,12 @@ func initMetricVars() {
...
@@ -339,6 +384,12 @@ func initMetricVars() {
M_StatTotal_Orgs
,
M_StatTotal_Orgs
,
M_StatTotal_Playlists
,
M_StatTotal_Playlists
,
M_Grafana_Version
,
M_Grafana_Version
,
StatsTotalViewers
,
StatsTotalEditors
,
StatsTotalAdmins
,
StatsTotalActiveViewers
,
StatsTotalActiveEditors
,
StatsTotalActiveAdmins
,
grafanaBuildVersion
)
grafanaBuildVersion
)
}
}
...
...
pkg/infra/usagestats/usage_stats.go
View file @
1aadb442
...
@@ -166,6 +166,12 @@ func (uss *UsageStatsService) updateTotalStats() {
...
@@ -166,6 +166,12 @@ func (uss *UsageStatsService) updateTotalStats() {
metrics
.
M_StatActive_Users
.
Set
(
float64
(
statsQuery
.
Result
.
ActiveUsers
))
metrics
.
M_StatActive_Users
.
Set
(
float64
(
statsQuery
.
Result
.
ActiveUsers
))
metrics
.
M_StatTotal_Playlists
.
Set
(
float64
(
statsQuery
.
Result
.
Playlists
))
metrics
.
M_StatTotal_Playlists
.
Set
(
float64
(
statsQuery
.
Result
.
Playlists
))
metrics
.
M_StatTotal_Orgs
.
Set
(
float64
(
statsQuery
.
Result
.
Orgs
))
metrics
.
M_StatTotal_Orgs
.
Set
(
float64
(
statsQuery
.
Result
.
Orgs
))
metrics
.
StatsTotalViewers
.
Set
(
float64
(
statsQuery
.
Result
.
Viewers
))
metrics
.
StatsTotalActiveViewers
.
Set
(
float64
(
statsQuery
.
Result
.
ActiveViewers
))
metrics
.
StatsTotalEditors
.
Set
(
float64
(
statsQuery
.
Result
.
Editors
))
metrics
.
StatsTotalActiveEditors
.
Set
(
float64
(
statsQuery
.
Result
.
ActiveEditors
))
metrics
.
StatsTotalAdmins
.
Set
(
float64
(
statsQuery
.
Result
.
Admins
))
metrics
.
StatsTotalActiveAdmins
.
Set
(
float64
(
statsQuery
.
Result
.
ActiveAdmins
))
}
}
func
getEdition
()
string
{
func
getEdition
()
string
{
...
...
pkg/models/stats.go
View file @
1aadb442
...
@@ -16,6 +16,14 @@ type SystemStats struct {
...
@@ -16,6 +16,14 @@ type SystemStats struct {
Folders
int64
Folders
int64
ProvisionedDashboards
int64
ProvisionedDashboards
int64
AuthTokens
int64
AuthTokens
int64
Admins
int
Editors
int
Viewers
int
ActiveAdmins
int
ActiveEditors
int
ActiveViewers
int
ActiveSessions
int
}
}
type
DataSourceStats
struct
{
type
DataSourceStats
struct
{
...
...
pkg/services/alerting/models.go
View file @
1aadb442
...
@@ -2,8 +2,7 @@ package alerting
...
@@ -2,8 +2,7 @@ package alerting
import
"github.com/grafana/grafana/pkg/components/null"
import
"github.com/grafana/grafana/pkg/components/null"
// Job holds state about when the alert rule should
// Job holds state about when the alert rule should be evaluated.
// be evaluated.
type
Job
struct
{
type
Job
struct
{
Offset
int64
Offset
int64
OffsetWait
bool
OffsetWait
bool
...
...
pkg/services/sqlstore/stats.go
View file @
1aadb442
...
@@ -75,7 +75,11 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
...
@@ -75,7 +75,11 @@ 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_provisioning"
)
+
`) AS provisioned_dashboards,`
)
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"dashboard_snapshot"
)
+
`) AS snapshots,`
)
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 auth_tokens`
)
sb
.
Write
(
`(SELECT COUNT(id) FROM `
+
dialect
.
Quote
(
"user_auth_token"
)
+
`) AS auth_tokens,`
)
sb
.
Write
(
roleCounterSQL
(
"Viewer"
,
"viewers"
)
+
`,`
,
activeUserDeadlineDate
)
sb
.
Write
(
roleCounterSQL
(
"Editor"
,
"editors"
)
+
`,`
,
activeUserDeadlineDate
)
sb
.
Write
(
roleCounterSQL
(
"Admin"
,
"admins"
)
+
``
,
activeUserDeadlineDate
)
var
stats
m
.
SystemStats
var
stats
m
.
SystemStats
_
,
err
:=
x
.
SQL
(
sb
.
GetSqlString
(),
sb
.
params
...
)
.
Get
(
&
stats
)
_
,
err
:=
x
.
SQL
(
sb
.
GetSqlString
(),
sb
.
params
...
)
.
Get
(
&
stats
)
...
@@ -88,33 +92,31 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
...
@@ -88,33 +92,31 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
return
err
return
err
}
}
func
roleCounterSQL
(
role
,
alias
string
)
string
{
return
`
(
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
) 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
}
func
GetAdminStats
(
query
*
m
.
GetAdminStatsQuery
)
error
{
func
GetAdminStats
(
query
*
m
.
GetAdminStatsQuery
)
error
{
activeEndDate
:=
time
.
Now
()
.
Add
(
-
activeUserTimeLimit
)
activeEndDate
:=
time
.
Now
()
.
Add
(
-
activeUserTimeLimit
)
roleCounter
:=
func
(
role
,
alias
string
)
string
{
sql
:=
`
(
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
) 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
var
rawSql
=
`SELECT
(
(
...
@@ -156,9 +158,9 @@ func GetAdminStats(query *m.GetAdminStatsQuery) error {
...
@@ -156,9 +158,9 @@ func GetAdminStats(query *m.GetAdminStatsQuery) error {
SELECT COUNT(*)
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user"
)
+
` where last_seen_at > ?
FROM `
+
dialect
.
Quote
(
"user"
)
+
` where last_seen_at > ?
) as active_users,
) as active_users,
`
+
roleCounter
(
"Admin"
,
"admins"
)
+
`,
`
+
roleCounter
SQL
(
"Admin"
,
"admins"
)
+
`,
`
+
roleCounter
(
"Editor"
,
"editors"
)
+
`,
`
+
roleCounter
SQL
(
"Editor"
,
"editors"
)
+
`,
`
+
roleCounter
(
"Viewer"
,
"viewers"
)
+
`,
`
+
roleCounter
SQL
(
"Viewer"
,
"viewers"
)
+
`,
(
(
SELECT COUNT(*)
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user_auth_token"
)
+
` where rotated_at > ?
FROM `
+
dialect
.
Quote
(
"user_auth_token"
)
+
` where rotated_at > ?
...
...
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