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
53153c82
Unverified
Commit
53153c82
authored
Sep 15, 2020
by
Dan Cech
Committed by
GitHub
Sep 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add method to get usage report (#27555)
parent
cade6dd0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
25 deletions
+45
-25
pkg/infra/usagestats/service.go
+1
-1
pkg/infra/usagestats/usage_stats.go
+40
-20
pkg/infra/usagestats/usage_stats_test.go
+4
-4
No files found.
pkg/infra/usagestats/service.go
View file @
53153c82
...
...
@@ -50,7 +50,7 @@ func (uss *UsageStatsService) Run(ctx context.Context) error {
for
{
select
{
case
<-
onceEveryDayTick
.
C
:
uss
.
sendUsageStats
(
uss
.
oauthProviders
)
uss
.
sendUsageStats
()
case
<-
everyMinuteTicker
.
C
:
uss
.
updateTotalStats
()
case
<-
ctx
.
Done
()
:
...
...
pkg/infra/usagestats/usage_stats.go
View file @
53153c82
...
...
@@ -17,30 +17,35 @@ import (
var
usageStatsURL
=
"https://stats.grafana.org/grafana-usage-report"
func
(
uss
*
UsageStatsService
)
sendUsageStats
(
oauthProviders
map
[
string
]
bool
)
{
if
!
setting
.
ReportingEnabled
{
return
}
metricsLogger
.
Debug
(
fmt
.
Sprintf
(
"Sending anonymous usage stats to %s"
,
usageStatsURL
))
type
UsageReport
struct
{
Version
string
`json:"version"`
Metrics
map
[
string
]
interface
{}
`json:"metrics"`
Os
string
`json:"os"`
Arch
string
`json:"arch"`
Edition
string
`json:"edition"`
HasValidLicense
bool
`json:"hasValidLicense"`
Packaging
string
`json:"packaging"`
}
func
(
uss
*
UsageStatsService
)
GetUsageReport
()
(
UsageReport
,
error
)
{
version
:=
strings
.
Replace
(
setting
.
BuildVersion
,
"."
,
"_"
,
-
1
)
metrics
:=
map
[
string
]
interface
{}{}
report
:=
map
[
string
]
interface
{}{
"version"
:
version
,
"metrics"
:
metrics
,
"os"
:
runtime
.
GOOS
,
"arch"
:
runtime
.
GOARCH
,
"edition"
:
getEdition
(),
"hasValidLicense"
:
uss
.
License
.
HasValidLicense
(),
"packaging"
:
setting
.
Packaging
,
report
:=
UsageReport
{
Version
:
version
,
Metrics
:
metrics
,
Os
:
runtime
.
GOOS
,
Arch
:
runtime
.
GOARCH
,
Edition
:
getEdition
(),
HasValidLicense
:
uss
.
License
.
HasValidLicense
(),
Packaging
:
setting
.
Packaging
,
}
statsQuery
:=
models
.
GetSystemStatsQuery
{}
if
err
:=
uss
.
Bus
.
Dispatch
(
&
statsQuery
);
err
!=
nil
{
metricsLogger
.
Error
(
"Failed to get system stats"
,
"error"
,
err
)
return
return
report
,
err
}
metrics
[
"stats.dashboards.count"
]
=
statsQuery
.
Result
.
Dashboards
...
...
@@ -78,7 +83,7 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
dsStats
:=
models
.
GetDataSourceStatsQuery
{}
if
err
:=
uss
.
Bus
.
Dispatch
(
&
dsStats
);
err
!=
nil
{
metricsLogger
.
Error
(
"Failed to get datasource stats"
,
"error"
,
err
)
return
return
report
,
err
}
// send counters for each data source
...
...
@@ -100,7 +105,7 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
alertingUsageStats
,
err
:=
uss
.
AlertingUsageStats
.
QueryUsageStats
()
if
err
!=
nil
{
uss
.
log
.
Error
(
"Failed to get alerting usage stats"
,
"error"
,
err
)
return
return
report
,
err
}
var
addAlertingUsageStats
=
func
(
dsType
string
,
usageCount
int
)
{
...
...
@@ -122,7 +127,7 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
dsAccessStats
:=
models
.
GetDataSourceAccessStatsQuery
{}
if
err
:=
uss
.
Bus
.
Dispatch
(
&
dsAccessStats
);
err
!=
nil
{
metricsLogger
.
Error
(
"Failed to get datasource access stats"
,
"error"
,
err
)
return
return
report
,
err
}
// send access counters for each data source
...
...
@@ -152,7 +157,7 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
anStats
:=
models
.
GetAlertNotifierUsageStatsQuery
{}
if
err
:=
uss
.
Bus
.
Dispatch
(
&
anStats
);
err
!=
nil
{
metricsLogger
.
Error
(
"Failed to get alert notification stats"
,
"error"
,
err
)
return
return
report
,
err
}
for
_
,
stats
:=
range
anStats
.
Result
{
...
...
@@ -166,7 +171,7 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
authTypes
[
"ldap"
]
=
setting
.
LDAPEnabled
authTypes
[
"auth_proxy"
]
=
setting
.
AuthProxyEnabled
for
provider
,
enabled
:=
range
oauthProviders
{
for
provider
,
enabled
:=
range
uss
.
oauthProviders
{
authTypes
[
"oauth_"
+
provider
]
=
enabled
}
...
...
@@ -178,6 +183,21 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
metrics
[
"stats.auth_enabled."
+
authType
+
".count"
]
=
enabledValue
}
return
report
,
nil
}
func
(
uss
*
UsageStatsService
)
sendUsageStats
()
{
if
!
setting
.
ReportingEnabled
{
return
}
metricsLogger
.
Debug
(
fmt
.
Sprintf
(
"Sending anonymous usage stats to %s"
,
usageStatsURL
))
report
,
err
:=
uss
.
GetUsageReport
()
if
err
!=
nil
{
return
}
out
,
_
:=
json
.
MarshalIndent
(
report
,
""
,
" "
)
data
:=
bytes
.
NewBuffer
(
out
)
...
...
pkg/infra/usagestats/usage_stats_test.go
View file @
53153c82
...
...
@@ -162,7 +162,7 @@ func TestMetrics(t *testing.T) {
}))
usageStatsURL
=
ts
.
URL
oauthProviders
:
=
map
[
string
]
bool
{
uss
.
oauthProviders
=
map
[
string
]
bool
{
"github"
:
true
,
"gitlab"
:
true
,
"azuread"
:
true
,
...
...
@@ -171,11 +171,11 @@ func TestMetrics(t *testing.T) {
"grafana_com"
:
true
,
}
uss
.
sendUsageStats
(
oauthProviders
)
uss
.
sendUsageStats
()
Convey
(
"Given reporting not enabled and sending usage stats"
,
func
()
{
setting
.
ReportingEnabled
=
false
uss
.
sendUsageStats
(
oauthProviders
)
uss
.
sendUsageStats
()
Convey
(
"Should not gather stats or call http endpoint"
,
func
()
{
So
(
getSystemStatsQuery
,
ShouldBeNil
)
...
...
@@ -195,7 +195,7 @@ func TestMetrics(t *testing.T) {
setting
.
Packaging
=
"deb"
wg
.
Add
(
1
)
uss
.
sendUsageStats
(
oauthProviders
)
uss
.
sendUsageStats
()
Convey
(
"Should gather stats and call http endpoint"
,
func
()
{
if
waitTimeout
(
&
wg
,
2
*
time
.
Second
)
{
...
...
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