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
b2c0679a
Commit
b2c0679a
authored
Jun 01, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(metrics): initial graphite metrics writer for internal stats
parent
8db00073
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
2 deletions
+81
-2
pkg/metrics/receiver/graphite.go
+44
-0
pkg/metrics/report_usage.go
+37
-2
No files found.
pkg/metrics/receiver/graphite.go
0 → 100644
View file @
b2c0679a
package
receiver
import
(
"bytes"
"fmt"
"github.com/grafana/grafana/pkg/log"
"net"
"time"
)
type
GraphiteSender
struct
{
Host
string
Port
string
Protocol
string
Prefix
string
}
func
(
this
*
GraphiteSender
)
Send
(
metrics
map
[
string
]
interface
{})
error
{
log
.
Debug
(
"GraphiteSender: Sending metrics to graphite"
)
address
:=
fmt
.
Sprintf
(
"%s:%s"
,
this
.
Host
,
this
.
Port
)
conn
,
err
:=
net
.
DialTimeout
(
this
.
Protocol
,
address
,
time
.
Second
*
5
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Graphite Sender: Failed to connec to %s!"
,
err
)
}
buf
:=
bytes
.
NewBufferString
(
""
)
now
:=
time
.
Now
()
.
Unix
()
for
key
,
value
:=
range
metrics
{
metricName
:=
this
.
Prefix
+
key
line
:=
fmt
.
Sprintf
(
"%s %d %d
\n
"
,
metricName
,
value
,
now
)
log
.
Debug
(
"SendMetric: sending %s"
,
line
)
buf
.
WriteString
(
line
)
}
_
,
err
=
conn
.
Write
(
buf
.
Bytes
())
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Graphite Sender: Failed to send metrics!"
,
err
)
}
return
nil
}
pkg/metrics/report_usage.go
View file @
b2c0679a
...
...
@@ -9,23 +9,58 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics/receiver"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/setting"
)
type
MetricSender
interface
{
Send
(
metrics
map
[
string
]
interface
{})
error
}
func
StartUsageReportLoop
()
chan
struct
{}
{
M_Instance_Start
.
Inc
(
1
)
ticker
:=
time
.
NewTicker
(
time
.
Hour
*
24
)
hourTicker
:=
time
.
NewTicker
(
time
.
Hour
*
24
)
secondTicker
:=
time
.
NewTicker
(
time
.
Second
*
10
)
sender
:=
&
receiver
.
GraphiteSender
{
Host
:
"localhost"
,
Port
:
"2003"
,
Protocol
:
"tcp"
,
Prefix
:
"grafana."
,
}
for
{
select
{
case
<-
t
icker
.
C
:
case
<-
hourT
icker
.
C
:
sendUsageStats
()
case
<-
secondTicker
.
C
:
sendMetricUsage
(
sender
)
}
}
}
func
sendMetricUsage
(
sender
MetricSender
)
{
metrics
:=
map
[
string
]
interface
{}{}
MetricStats
.
Each
(
func
(
name
string
,
i
interface
{})
{
switch
metric
:=
i
.
(
type
)
{
case
Counter
:
if
metric
.
Count
()
>
0
{
metrics
[
name
+
".count"
]
=
metric
.
Count
()
metric
.
Clear
()
}
}
})
err
:=
sender
.
Send
(
metrics
)
if
err
!=
nil
{
log
.
Error
(
1
,
"Failed to send metrics:"
,
err
)
}
}
func
sendUsageStats
()
{
log
.
Trace
(
"Sending anonymous usage stats to stats.grafana.org"
)
...
...
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