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
b070784b
Commit
b070784b
authored
Sep 06, 2018
by
Carl Bergquist
Committed by
Torkel Ödegaard
Sep 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds usage stats for alert notifiers (#13173)
parent
44cd738d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
0 deletions
+55
-0
pkg/metrics/metrics.go
+10
-0
pkg/metrics/metrics_test.go
+22
-0
pkg/models/stats.go
+9
-0
pkg/services/sqlstore/stats.go
+8
-0
pkg/services/sqlstore/stats_test.go
+6
-0
No files found.
pkg/metrics/metrics.go
View file @
b070784b
...
...
@@ -440,6 +440,16 @@ func sendUsageStats() {
metrics
[
"stats.ds_access.other."
+
access
+
".count"
]
=
count
}
anStats
:=
models
.
GetAlertNotifierUsageStatsQuery
{}
if
err
:=
bus
.
Dispatch
(
&
anStats
);
err
!=
nil
{
metricsLogger
.
Error
(
"Failed to get alert notification stats"
,
"error"
,
err
)
return
}
for
_
,
stats
:=
range
anStats
.
Result
{
metrics
[
"stats.alert_notifiers."
+
stats
.
Type
+
".count"
]
=
stats
.
Count
}
out
,
_
:=
json
.
MarshalIndent
(
report
,
""
,
" "
)
data
:=
bytes
.
NewBuffer
(
out
)
...
...
pkg/metrics/metrics_test.go
View file @
b070784b
...
...
@@ -115,6 +115,24 @@ func TestMetrics(t *testing.T) {
return
nil
})
var
getAlertNotifierUsageStatsQuery
*
models
.
GetAlertNotifierUsageStatsQuery
bus
.
AddHandler
(
"test"
,
func
(
query
*
models
.
GetAlertNotifierUsageStatsQuery
)
error
{
query
.
Result
=
[]
*
models
.
NotifierUsageStats
{
{
Type
:
"slack"
,
Count
:
1
,
},
{
Type
:
"webhook"
,
Count
:
2
,
},
}
getAlertNotifierUsageStatsQuery
=
query
return
nil
})
var
wg
sync
.
WaitGroup
var
responseBuffer
*
bytes
.
Buffer
var
req
*
http
.
Request
...
...
@@ -157,6 +175,7 @@ func TestMetrics(t *testing.T) {
So
(
getSystemStatsQuery
,
ShouldNotBeNil
)
So
(
getDataSourceStatsQuery
,
ShouldNotBeNil
)
So
(
getDataSourceAccessStatsQuery
,
ShouldNotBeNil
)
So
(
getAlertNotifierUsageStatsQuery
,
ShouldNotBeNil
)
So
(
req
,
ShouldNotBeNil
)
So
(
req
.
Method
,
ShouldEqual
,
http
.
MethodPost
)
So
(
req
.
Header
.
Get
(
"Content-Type"
),
ShouldEqual
,
"application/json"
)
...
...
@@ -198,6 +217,9 @@ func TestMetrics(t *testing.T) {
So
(
metrics
.
Get
(
"stats.ds_access."
+
models
.
DS_PROMETHEUS
+
".proxy.count"
)
.
MustInt
(),
ShouldEqual
,
3
)
So
(
metrics
.
Get
(
"stats.ds_access.other.direct.count"
)
.
MustInt
(),
ShouldEqual
,
6
+
7
)
So
(
metrics
.
Get
(
"stats.ds_access.other.proxy.count"
)
.
MustInt
(),
ShouldEqual
,
4
+
8
)
So
(
metrics
.
Get
(
"stats.alert_notifiers.slack.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.alert_notifiers.webhook.count"
)
.
MustInt
(),
ShouldEqual
,
2
)
})
})
...
...
pkg/models/stats.go
View file @
b070784b
...
...
@@ -40,6 +40,15 @@ type GetDataSourceAccessStatsQuery struct {
Result
[]
*
DataSourceAccessStats
}
type
NotifierUsageStats
struct
{
Type
string
Count
int64
}
type
GetAlertNotifierUsageStatsQuery
struct
{
Result
[]
*
NotifierUsageStats
}
type
AdminStats
struct
{
Users
int
`json:"users"`
Orgs
int
`json:"orgs"`
...
...
pkg/services/sqlstore/stats.go
View file @
b070784b
...
...
@@ -13,11 +13,19 @@ func init() {
bus
.
AddHandler
(
"sql"
,
GetDataSourceStats
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceAccessStats
)
bus
.
AddHandler
(
"sql"
,
GetAdminStats
)
bus
.
AddHandlerCtx
(
"sql"
,
GetAlertNotifiersUsageStats
)
bus
.
AddHandlerCtx
(
"sql"
,
GetSystemUserCountStats
)
}
var
activeUserTimeLimit
=
time
.
Hour
*
24
*
30
func
GetAlertNotifiersUsageStats
(
ctx
context
.
Context
,
query
*
m
.
GetAlertNotifierUsageStatsQuery
)
error
{
var
rawSql
=
`SELECT COUNT(*) as count, type FROM alert_notification GROUP BY type`
query
.
Result
=
make
([]
*
m
.
NotifierUsageStats
,
0
)
err
:=
x
.
SQL
(
rawSql
)
.
Find
(
&
query
.
Result
)
return
err
}
func
GetDataSourceStats
(
query
*
m
.
GetDataSourceStatsQuery
)
error
{
var
rawSql
=
`SELECT COUNT(*) as count, type FROM data_source GROUP BY type`
query
.
Result
=
make
([]
*
m
.
DataSourceStats
,
0
)
...
...
pkg/services/sqlstore/stats_test.go
View file @
b070784b
...
...
@@ -36,5 +36,11 @@ func TestStatsDataAccess(t *testing.T) {
err
:=
GetDataSourceAccessStats
(
&
query
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Get alert notifier stats should not results in error"
,
func
()
{
query
:=
m
.
GetAlertNotifierUsageStatsQuery
{}
err
:=
GetAlertNotifiersUsageStats
(
context
.
Background
(),
&
query
)
So
(
err
,
ShouldBeNil
)
})
})
}
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