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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
14 deletions
+80
-14
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
+13
-11
No files found.
pkg/infra/metrics/metrics.go
View file @
1aadb442
...
...
@@ -43,8 +43,10 @@ var (
// Timers
M_DataSource_ProxyReq_Timer
prometheus
.
Summary
M_Alerting_Execution_Time
prometheus
.
Summary
)
// StatTotals
// StatTotals
var
(
M_Alerting_Active_Alerts
prometheus
.
Gauge
M_StatTotal_Dashboards
prometheus
.
Gauge
M_StatTotal_Users
prometheus
.
Gauge
...
...
@@ -52,6 +54,13 @@ var (
M_StatTotal_Orgs
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
//
// Deprecated: use M_Grafana_Build_Version instead.
...
...
@@ -274,6 +283,42 @@ func init() {
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
{
Name
:
"info"
,
Help
:
"Information about the Grafana. This metric is deprecated. please use `grafana_build_info`"
,
...
...
@@ -339,6 +384,12 @@ func initMetricVars() {
M_StatTotal_Orgs
,
M_StatTotal_Playlists
,
M_Grafana_Version
,
StatsTotalViewers
,
StatsTotalEditors
,
StatsTotalAdmins
,
StatsTotalActiveViewers
,
StatsTotalActiveEditors
,
StatsTotalActiveAdmins
,
grafanaBuildVersion
)
}
...
...
pkg/infra/usagestats/usage_stats.go
View file @
1aadb442
...
...
@@ -166,6 +166,12 @@ func (uss *UsageStatsService) updateTotalStats() {
metrics
.
M_StatActive_Users
.
Set
(
float64
(
statsQuery
.
Result
.
ActiveUsers
))
metrics
.
M_StatTotal_Playlists
.
Set
(
float64
(
statsQuery
.
Result
.
Playlists
))
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
{
...
...
pkg/models/stats.go
View file @
1aadb442
...
...
@@ -16,6 +16,14 @@ type SystemStats struct {
Folders
int64
ProvisionedDashboards
int64
AuthTokens
int64
Admins
int
Editors
int
Viewers
int
ActiveAdmins
int
ActiveEditors
int
ActiveViewers
int
ActiveSessions
int
}
type
DataSourceStats
struct
{
...
...
pkg/services/alerting/models.go
View file @
1aadb442
...
...
@@ -2,8 +2,7 @@ package alerting
import
"github.com/grafana/grafana/pkg/components/null"
// Job holds state about when the alert rule should
// be evaluated.
// Job holds state about when the alert rule should be evaluated.
type
Job
struct
{
Offset
int64
OffsetWait
bool
...
...
pkg/services/sqlstore/stats.go
View file @
1aadb442
...
...
@@ -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_snapshot"
)
+
`) AS snapshots,`
)
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
_
,
err
:=
x
.
SQL
(
sb
.
GetSqlString
(),
sb
.
params
...
)
.
Get
(
&
stats
)
...
...
@@ -88,11 +92,8 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
return
err
}
func
GetAdminStats
(
query
*
m
.
GetAdminStatsQuery
)
error
{
activeEndDate
:=
time
.
Now
()
.
Add
(
-
activeUserTimeLimit
)
roleCounter
:=
func
(
role
,
alias
string
)
string
{
sql
:=
`
func
roleCounterSQL
(
role
,
alias
string
)
string
{
return
`
(
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user"
)
+
` as u
...
...
@@ -112,9 +113,10 @@ func GetAdminStats(query *m.GetAdminStatsQuery) error {
AND org_user.role='`
+
role
+
`')>0
AND u.last_seen_at>?
) as active_`
+
alias
}
return
sql
}
func
GetAdminStats
(
query
*
m
.
GetAdminStatsQuery
)
error
{
activeEndDate
:=
time
.
Now
()
.
Add
(
-
activeUserTimeLimit
)
var
rawSql
=
`SELECT
(
...
...
@@ -156,9 +158,9 @@ func GetAdminStats(query *m.GetAdminStatsQuery) error {
SELECT COUNT(*)
FROM `
+
dialect
.
Quote
(
"user"
)
+
` where last_seen_at > ?
) as active_users,
`
+
roleCounter
(
"Admin"
,
"admins"
)
+
`,
`
+
roleCounter
(
"Editor"
,
"editors"
)
+
`,
`
+
roleCounter
(
"Viewer"
,
"viewers"
)
+
`,
`
+
roleCounter
SQL
(
"Admin"
,
"admins"
)
+
`,
`
+
roleCounter
SQL
(
"Editor"
,
"editors"
)
+
`,
`
+
roleCounter
SQL
(
"Viewer"
,
"viewers"
)
+
`,
(
SELECT COUNT(*)
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