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
c816ed25
Commit
c816ed25
authored
Sep 29, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(usage stats): added data source count stats
parent
8a39b32b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
7 deletions
+68
-7
pkg/metrics/report_usage.go
+26
-7
pkg/models/datasource.go
+21
-0
pkg/models/stats.go
+9
-0
pkg/services/sqlstore/stats.go
+12
-0
No files found.
pkg/metrics/report_usage.go
View file @
c816ed25
...
@@ -36,12 +36,6 @@ func sendUsageStats() {
...
@@ -36,12 +36,6 @@ func sendUsageStats() {
"metrics"
:
metrics
,
"metrics"
:
metrics
,
}
}
statsQuery
:=
m
.
GetSystemStatsQuery
{}
if
err
:=
bus
.
Dispatch
(
&
statsQuery
);
err
!=
nil
{
log
.
Error
(
3
,
"Failed to get system stats"
,
err
)
return
}
UsageStats
.
Each
(
func
(
name
string
,
i
interface
{})
{
UsageStats
.
Each
(
func
(
name
string
,
i
interface
{})
{
switch
metric
:=
i
.
(
type
)
{
switch
metric
:=
i
.
(
type
)
{
case
Counter
:
case
Counter
:
...
@@ -52,11 +46,36 @@ func sendUsageStats() {
...
@@ -52,11 +46,36 @@ func sendUsageStats() {
}
}
})
})
statsQuery
:=
m
.
GetSystemStatsQuery
{}
if
err
:=
bus
.
Dispatch
(
&
statsQuery
);
err
!=
nil
{
log
.
Error
(
3
,
"Failed to get system stats"
,
err
)
return
}
metrics
[
"stats.dashboards.count"
]
=
statsQuery
.
Result
.
DashboardCount
metrics
[
"stats.dashboards.count"
]
=
statsQuery
.
Result
.
DashboardCount
metrics
[
"stats.users.count"
]
=
statsQuery
.
Result
.
UserCount
metrics
[
"stats.users.count"
]
=
statsQuery
.
Result
.
UserCount
metrics
[
"stats.orgs.count"
]
=
statsQuery
.
Result
.
OrgCount
metrics
[
"stats.orgs.count"
]
=
statsQuery
.
Result
.
OrgCount
out
,
_
:=
json
.
Marshal
(
report
)
dsStats
:=
m
.
GetDataSourceStatsQuery
{}
if
err
:=
bus
.
Dispatch
(
&
dsStats
);
err
!=
nil
{
log
.
Error
(
3
,
"Failed to get datasource stats"
,
err
)
return
}
// send counters for each data source
// but ignore any custom data sources
// as sending that name could be sensitive information
dsOtherCount
:=
0
for
_
,
dsStat
:=
range
dsStats
.
Result
{
if
m
.
IsStandardDataSource
(
dsStat
.
Type
)
{
metrics
[
"stats.ds."
+
dsStat
.
Type
+
".count"
]
=
dsStat
.
Count
}
else
{
dsOtherCount
+=
dsStat
.
Count
}
}
metrics
[
"stats.ds.other.count"
]
=
dsOtherCount
out
,
_
:=
json
.
MarshalIndent
(
report
,
""
,
" "
)
data
:=
bytes
.
NewBuffer
(
out
)
data
:=
bytes
.
NewBuffer
(
out
)
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
5
*
time
.
Second
)}
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
5
*
time
.
Second
)}
...
...
pkg/models/datasource.go
View file @
c816ed25
...
@@ -12,6 +12,8 @@ const (
...
@@ -12,6 +12,8 @@ const (
DS_ES
=
"elasticsearch"
DS_ES
=
"elasticsearch"
DS_OPENTSDB
=
"opentsdb"
DS_OPENTSDB
=
"opentsdb"
DS_CLOUDWATCH
=
"cloudwatch"
DS_CLOUDWATCH
=
"cloudwatch"
DS_KAIROSDB
=
"kairosdb"
DS_PROMETHEUS
=
"prometheus"
DS_ACCESS_DIRECT
=
"direct"
DS_ACCESS_DIRECT
=
"direct"
DS_ACCESS_PROXY
=
"proxy"
DS_ACCESS_PROXY
=
"proxy"
)
)
...
@@ -45,6 +47,25 @@ type DataSource struct {
...
@@ -45,6 +47,25 @@ type DataSource struct {
Updated
time
.
Time
Updated
time
.
Time
}
}
func
IsStandardDataSource
(
dsType
string
)
bool
{
switch
dsType
{
case
DS_ES
:
return
true
case
DS_INFLUXDB
:
return
true
case
DS_OPENTSDB
:
return
true
case
DS_CLOUDWATCH
:
return
true
case
DS_PROMETHEUS
:
return
true
case
DS_GRAPHITE
:
return
true
default
:
return
false
}
}
// ----------------------
// ----------------------
// COMMANDS
// COMMANDS
...
...
pkg/models/stats.go
View file @
c816ed25
...
@@ -6,6 +6,15 @@ type SystemStats struct {
...
@@ -6,6 +6,15 @@ type SystemStats struct {
OrgCount
int
OrgCount
int
}
}
type
DataSourceStats
struct
{
Count
int
Type
string
}
type
GetSystemStatsQuery
struct
{
type
GetSystemStatsQuery
struct
{
Result
*
SystemStats
Result
*
SystemStats
}
}
type
GetDataSourceStatsQuery
struct
{
Result
[]
*
DataSourceStats
}
pkg/services/sqlstore/stats.go
View file @
c816ed25
...
@@ -7,6 +7,18 @@ import (
...
@@ -7,6 +7,18 @@ import (
func
init
()
{
func
init
()
{
bus
.
AddHandler
(
"sql"
,
GetSystemStats
)
bus
.
AddHandler
(
"sql"
,
GetSystemStats
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceStats
)
}
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
)
err
:=
x
.
Sql
(
rawSql
)
.
Find
(
&
query
.
Result
)
if
err
!=
nil
{
return
err
}
return
err
}
}
func
GetSystemStats
(
query
*
m
.
GetSystemStatsQuery
)
error
{
func
GetSystemStats
(
query
*
m
.
GetSystemStatsQuery
)
error
{
...
...
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