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
2a9b51d8
Commit
2a9b51d8
authored
Jun 02, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(instrumentation): influxdb is working, now need to find a way to better support tags, #4696
parent
6b2a4fe8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
5 deletions
+99
-5
pkg/metrics/publishers/graphite.go
+5
-5
pkg/metrics/publishers/influxdb.go
+87
-0
pkg/metrics/settings.go
+7
-0
No files found.
pkg/metrics/publishers/graphite.go
View file @
2a9b51d8
...
@@ -22,12 +22,12 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) {
...
@@ -22,12 +22,12 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) {
return
nil
,
nil
return
nil
,
nil
}
}
graphiteReceiv
er
:=
&
GraphitePublisher
{}
publish
er
:=
&
GraphitePublisher
{}
graphiteReceiv
er
.
Protocol
=
"tcp"
publish
er
.
Protocol
=
"tcp"
graphiteReceiv
er
.
Address
=
graphiteSection
.
Key
(
"address"
)
.
MustString
(
"localhost:2003"
)
publish
er
.
Address
=
graphiteSection
.
Key
(
"address"
)
.
MustString
(
"localhost:2003"
)
graphiteReceiv
er
.
Prefix
=
graphiteSection
.
Key
(
"prefix"
)
.
MustString
(
"service.grafana.%(instance_name)s"
)
publish
er
.
Prefix
=
graphiteSection
.
Key
(
"prefix"
)
.
MustString
(
"service.grafana.%(instance_name)s"
)
return
graphiteReceiv
er
,
nil
return
publish
er
,
nil
}
}
func
(
this
*
GraphitePublisher
)
Publish
(
metrics
map
[
string
]
interface
{})
{
func
(
this
*
GraphitePublisher
)
Publish
(
metrics
map
[
string
]
interface
{})
{
...
...
pkg/metrics/publishers/influxdb.go
0 → 100644
View file @
2a9b51d8
package
publishers
import
(
"net/url"
"time"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/influxdata/influxdb/client"
)
type
InfluxPublisher
struct
{
database
string
tags
map
[
string
]
string
client
*
client
.
Client
}
func
CreateInfluxPublisher
()
(
*
InfluxPublisher
,
error
)
{
influxSection
,
err
:=
setting
.
Cfg
.
GetSection
(
"metrics.influxdb"
)
if
err
!=
nil
{
return
nil
,
nil
}
publisher
:=
&
InfluxPublisher
{
tags
:
make
(
map
[
string
]
string
),
}
urlStr
:=
influxSection
.
Key
(
"url"
)
.
MustString
(
"localhost:2003"
)
urlParsed
,
err
:=
url
.
Parse
(
urlStr
)
if
err
!=
nil
{
log
.
Error
(
3
,
"Metics: InfluxPublisher: failed to init influxdb publisher"
,
err
)
return
nil
,
nil
}
publisher
.
database
=
influxSection
.
Key
(
"database"
)
.
MustString
(
"grafana_metrics"
)
username
:=
influxSection
.
Key
(
"User"
)
.
MustString
(
"grafana"
)
password
:=
influxSection
.
Key
(
"Password"
)
.
MustString
(
"grafana"
)
publisher
.
client
,
err
=
client
.
NewClient
(
client
.
Config
{
URL
:
*
urlParsed
,
Username
:
username
,
Password
:
password
,
})
tagsSec
,
err
:=
setting
.
Cfg
.
GetSection
(
"metrics.influxdb.tags"
)
if
err
!=
nil
{
log
.
Error
(
3
,
"Metics: InfluxPublisher: failed to init influxdb settings no metrics.influxdb.tags section"
)
return
nil
,
nil
}
for
_
,
key
:=
range
tagsSec
.
Keys
()
{
publisher
.
tags
[
key
.
Name
()]
=
key
.
String
()
}
if
err
!=
nil
{
log
.
Error
(
3
,
"Metics: InfluxPublisher: failed to init influxdb publisher"
,
err
)
}
return
publisher
,
nil
}
func
(
this
*
InfluxPublisher
)
Publish
(
metrics
map
[
string
]
interface
{})
{
bp
:=
client
.
BatchPoints
{
Time
:
time
.
Now
(),
Database
:
this
.
database
,
Tags
:
map
[
string
]
string
{},
}
for
key
,
value
:=
range
this
.
tags
{
bp
.
Tags
[
key
]
=
value
}
for
key
,
value
:=
range
metrics
{
bp
.
Points
=
append
(
bp
.
Points
,
client
.
Point
{
Measurement
:
key
,
Fields
:
map
[
string
]
interface
{}{
"value"
:
value
,
},
})
}
_
,
err
:=
this
.
client
.
Write
(
bp
)
if
err
!=
nil
{
log
.
Error
(
3
,
"Metrics: InfluxPublisher: publish error"
,
err
)
}
}
pkg/metrics/settings.go
View file @
2a9b51d8
...
@@ -43,5 +43,12 @@ func readSettings() *MetricSettings {
...
@@ -43,5 +43,12 @@ func readSettings() *MetricSettings {
settings
.
Publishers
=
append
(
settings
.
Publishers
,
graphitePublisher
)
settings
.
Publishers
=
append
(
settings
.
Publishers
,
graphitePublisher
)
}
}
if
influxPublisher
,
err
:=
publishers
.
CreateInfluxPublisher
();
err
!=
nil
{
log
.
Error
(
3
,
"Metrics: Failed to init InfluxDB metric publisher"
,
err
)
}
else
if
influxPublisher
!=
nil
{
log
.
Info
(
"Metrics: Internal metrics publisher InfluxDB initialized"
)
settings
.
Publishers
=
append
(
settings
.
Publishers
,
influxPublisher
)
}
return
settings
return
settings
}
}
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