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
03f0bc46
Commit
03f0bc46
authored
Aug 10, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(metrics): make metrics cfg backwards compatible
parent
c5d0c9f0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
13 deletions
+41
-13
conf/defaults.ini
+1
-1
conf/sample.ini
+2
-2
pkg/metrics/graphite.go
+6
-2
pkg/metrics/graphite_test.go
+32
-8
No files found.
conf/defaults.ini
View file @
03f0bc46
...
...
@@ -358,7 +358,7 @@ interval_seconds = 60
# Send internal Grafana metrics to graphite
; [metrics.graphite]
; address = localhost:2003
; prefix = service.grafana.%(instance_name)s
.
; prefix = service.grafana.%(instance_name)s
[grafana_net]
url
=
https://grafana.net
conf/sample.ini
View file @
03f0bc46
...
...
@@ -303,10 +303,10 @@ enabled = true
# Publish interval
;interval_seconds = 10
# Send internal metrics to Graphite
. %instance_name% in prefix will be replaced with the value of instance_name
# Send internal metrics to Graphite
; [metrics.graphite]
; address = localhost:2003
; prefix = service.grafana.%
instance_name%
; prefix = service.grafana.%
(instance_name)s
#################################### Internal Grafana Metrics ##########################
# Url used to to import dashboards directly from Grafana.net
...
...
pkg/metrics/graphite.go
View file @
03f0bc46
...
...
@@ -30,9 +30,13 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) {
publisher
.
address
=
graphiteSection
.
Key
(
"address"
)
.
MustString
(
"localhost:2003"
)
safeInstanceName
:=
strings
.
Replace
(
setting
.
InstanceName
,
"."
,
"_"
,
-
1
)
prefix
:=
graphiteSection
.
Key
(
"prefix"
)
.
MustString
(
"service.grafana.%instance_name%"
)
prefix
:=
graphiteSection
.
Key
(
"prefix"
)
.
Value
(
)
publisher
.
prefix
=
strings
.
Replace
(
prefix
,
"%instance_name%"
,
safeInstanceName
,
-
1
)
if
prefix
==
""
{
prefix
=
"service.grafana.%(instance_name)s"
}
publisher
.
prefix
=
strings
.
Replace
(
prefix
,
"%(instance_name)s"
,
safeInstanceName
,
-
1
)
return
publisher
,
nil
}
...
...
pkg/metrics/graphite_test.go
View file @
03f0bc46
...
...
@@ -10,22 +10,46 @@ import (
func
TestGraphitePublisher
(
t
*
testing
.
T
)
{
Convey
(
"Test graphite prefix"
,
t
,
func
()
{
err
:=
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
Convey
(
"Test graphite prefix replacement"
,
t
,
func
()
{
var
err
error
err
=
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
HomePath
:
"../../"
,
Args
:
[]
string
{
"cfg:metrics.graphite.prefix=service.grafana.%instance_name%"
,
"cfg:metrics.graphite.address=localhost:2003"
,
},
})
So
(
err
,
ShouldBeNil
)
sec
,
err
:=
setting
.
Cfg
.
NewSection
(
"metrics.graphite"
)
sec
.
NewKey
(
"prefix"
,
"service.grafana.%(instance_name)s"
)
sec
.
NewKey
(
"address"
,
"localhost:2003"
)
So
(
err
,
ShouldBeNil
)
setting
.
InstanceName
=
"hostname.with.dots.com"
publisher
,
err2
:=
CreateGraphitePublisher
()
publisher
,
err
:=
CreateGraphitePublisher
()
So
(
err
,
ShouldBeNil
)
So
(
publisher
,
ShouldNotBeNil
)
So
(
publisher
.
prefix
,
ShouldEqual
,
"service.grafana.hostname_with_dots_com"
)
})
So
(
err2
,
ShouldBeNil
)
Convey
(
"Test graphite publisher default values"
,
t
,
func
()
{
var
err
error
err
=
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
HomePath
:
"../../"
,
})
So
(
err
,
ShouldBeNil
)
_
,
err
=
setting
.
Cfg
.
NewSection
(
"metrics.graphite"
)
setting
.
InstanceName
=
"hostname.with.dots.com"
publisher
,
err
:=
CreateGraphitePublisher
()
So
(
err
,
ShouldBeNil
)
So
(
publisher
,
ShouldNotBeNil
)
So
(
publisher
.
prefix
,
ShouldEqual
,
"service.grafana.hostname_with_dots_com"
)
So
(
publisher
.
address
,
ShouldEqual
,
"localhost:2003"
)
})
}
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