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
13e8eb6d
Commit
13e8eb6d
authored
Sep 19, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v4.5.x'
parents
3a7ed230
fe3c6ac3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
10 deletions
+45
-10
pkg/metrics/graphitebridge/graphite.go
+17
-6
pkg/metrics/graphitebridge/graphite_test.go
+28
-4
No files found.
pkg/metrics/graphitebridge/graphite.go
View file @
13e8eb6d
...
...
@@ -54,7 +54,17 @@ const (
AbortOnError
)
var
metricCategoryPrefix
[]
string
=
[]
string
{
"proxy_"
,
"api_"
,
"page_"
,
"alerting_"
,
"aws_"
,
"db_"
,
"stat_"
,
"go_"
,
"process_"
}
var
metricCategoryPrefix
[]
string
=
[]
string
{
"proxy_"
,
"api_"
,
"page_"
,
"alerting_"
,
"aws_"
,
"db_"
,
"stat_"
,
"go_"
,
"process_"
}
var
trimMetricPrefix
[]
string
=
[]
string
{
"grafana_"
}
// Config defines the Graphite bridge config.
...
...
@@ -240,16 +250,17 @@ func writeMetric(buf *bufio.Writer, m model.Metric, mf *dto.MetricFamily) error
if
!
hasName
{
numLabels
=
len
(
m
)
}
for
_
,
v
:=
range
metricCategoryPrefix
{
for
_
,
v
:=
range
trimMetricPrefix
{
if
strings
.
HasPrefix
(
string
(
metricName
),
v
)
{
group
:=
strings
.
Replace
(
v
,
"_"
,
" "
,
1
)
metricName
=
model
.
LabelValue
(
strings
.
Replace
(
string
(
metricName
),
v
,
group
,
1
))
metricName
=
model
.
LabelValue
(
strings
.
Replace
(
string
(
metricName
),
v
,
""
,
1
))
}
}
for
_
,
v
:=
range
trimMetric
Prefix
{
for
_
,
v
:=
range
metricCategory
Prefix
{
if
strings
.
HasPrefix
(
string
(
metricName
),
v
)
{
metricName
=
model
.
LabelValue
(
strings
.
Replace
(
string
(
metricName
),
v
,
""
,
1
))
group
:=
strings
.
Replace
(
v
,
"_"
,
" "
,
1
)
metricName
=
model
.
LabelValue
(
strings
.
Replace
(
string
(
metricName
),
v
,
group
,
1
))
}
}
...
...
pkg/metrics/graphitebridge/graphite_test.go
View file @
13e8eb6d
...
...
@@ -128,6 +128,7 @@ func TestWriteSummary(t *testing.T) {
prometheus
.
SummaryOpts
{
Name
:
"name"
,
Help
:
"docstring"
,
Namespace
:
"grafana"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
Objectives
:
map
[
float64
]
float64
{
0.5
:
0.05
,
0.9
:
0.01
,
0.99
:
0.001
},
},
...
...
@@ -187,6 +188,7 @@ func TestWriteHistogram(t *testing.T) {
prometheus
.
HistogramOpts
{
Name
:
"name"
,
Help
:
"docstring"
,
Namespace
:
"grafana"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
Buckets
:
[]
float64
{
0.01
,
0.02
,
0.05
,
0.1
},
},
...
...
@@ -248,6 +250,17 @@ func TestCounterVec(t *testing.T) {
cntVec
:=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"page_response"
,
Namespace
:
"grafana"
,
Help
:
"docstring"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
},
[]
string
{
"labelname"
},
)
apicntVec
:=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"api_response"
,
Namespace
:
"grafana"
,
Help
:
"docstring"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
},
...
...
@@ -256,9 +269,12 @@ func TestCounterVec(t *testing.T) {
reg
:=
prometheus
.
NewRegistry
()
reg
.
MustRegister
(
cntVec
)
reg
.
MustRegister
(
apicntVec
)
cntVec
.
WithLabelValues
(
"val1"
)
.
Inc
()
cntVec
.
WithLabelValues
(
"val2"
)
.
Inc
()
apicntVec
.
WithLabelValues
(
"val1"
)
.
Inc
()
apicntVec
.
WithLabelValues
(
"val2"
)
.
Inc
()
b
,
err
:=
NewBridge
(
&
Config
{
URL
:
"localhost:8080"
,
...
...
@@ -281,7 +297,9 @@ func TestCounterVec(t *testing.T) {
t
.
Fatalf
(
"error: %v"
,
err
)
}
want
:=
`prefix.page.response.constname.constvalue.labelname.val1.count 1 1477043
want
:=
`prefix.api.response.constname.constvalue.labelname.val1.count 1 1477043
prefix.api.response.constname.constvalue.labelname.val2.count 1 1477043
prefix.page.response.constname.constvalue.labelname.val1.count 1 1477043
prefix.page.response.constname.constvalue.labelname.val2.count 1 1477043
`
if
got
:=
buf
.
String
();
want
!=
got
{
...
...
@@ -291,6 +309,8 @@ prefix.page.response.constname.constvalue.labelname.val2.count 1 1477043
//next collect
cntVec
.
WithLabelValues
(
"val1"
)
.
Inc
()
cntVec
.
WithLabelValues
(
"val2"
)
.
Inc
()
apicntVec
.
WithLabelValues
(
"val1"
)
.
Inc
()
apicntVec
.
WithLabelValues
(
"val2"
)
.
Inc
()
mfs
,
err
=
reg
.
Gather
()
if
err
!=
nil
{
...
...
@@ -303,7 +323,9 @@ prefix.page.response.constname.constvalue.labelname.val2.count 1 1477043
t
.
Fatalf
(
"error: %v"
,
err
)
}
want2
:=
`prefix.page.response.constname.constvalue.labelname.val1.count 1 1477053
want2
:=
`prefix.api.response.constname.constvalue.labelname.val1.count 1 1477053
prefix.api.response.constname.constvalue.labelname.val2.count 1 1477053
prefix.page.response.constname.constvalue.labelname.val1.count 1 1477053
prefix.page.response.constname.constvalue.labelname.val2.count 1 1477053
`
if
got
:=
buf
.
String
();
want2
!=
got
{
...
...
@@ -316,6 +338,7 @@ func TestCounter(t *testing.T) {
prometheus
.
CounterOpts
{
Name
:
"page_response"
,
Help
:
"docstring"
,
Namespace
:
"grafana"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
})
...
...
@@ -373,7 +396,7 @@ func TestCounter(t *testing.T) {
func
TestTrimGrafanaNamespace
(
t
*
testing
.
T
)
{
cntVec
:=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"
grafana_
http_request_total"
,
Name
:
"http_request_total"
,
Help
:
"docstring"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
})
...
...
@@ -413,7 +436,7 @@ func TestTrimGrafanaNamespace(t *testing.T) {
func
TestSkipNanValues
(
t
*
testing
.
T
)
{
cntVec
:=
prometheus
.
NewSummary
(
prometheus
.
SummaryOpts
{
Name
:
"
grafana_
http_request_total"
,
Name
:
"http_request_total"
,
Help
:
"docstring"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
})
...
...
@@ -457,6 +480,7 @@ func TestPush(t *testing.T) {
prometheus
.
CounterOpts
{
Name
:
"name"
,
Help
:
"docstring"
,
Namespace
:
"grafana"
,
ConstLabels
:
prometheus
.
Labels
{
"constname"
:
"constvalue"
},
},
[]
string
{
"labelname"
},
...
...
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