Skip to content

Commit

Permalink
fixed how dimensions work
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisenuf committed Jul 31, 2015
1 parent b4288a7 commit 4b525ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fullerite.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"handlers": {
"Graphite": {
"server": "10.40.11.51"
"server": "10.40.11.51",
"port": "2003"
},
"SignalFx": {
Expand Down
32 changes: 21 additions & 11 deletions src/fullerite/handler/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"
"fmt"
"net"
"sort"
)

// Graphite type
Expand Down Expand Up @@ -42,37 +43,45 @@ func (g *Graphite) Configure(config *map[string]string) {
func (g *Graphite) Run() {
lastEmission := time.Now()
metrics := make([]string, 0, g.maxBufferSize)
log.Info("graphite handler started")


for metric := range g.channel {
for metric := range g.Channel() {
log.Println("Sending metric to Graphite:", metric)
datapoints := g.convertToGraphite(&metric)
datapoint := g.convertToGraphite(&metric)

metrics = append(metrics, datapoint)

//if the datapoints from metric would overflow the buffer, flush it and then add the new datapoints
if time.Since(lastEmission).Seconds() >= float64(g.interval) || len(metrics) + len(*datapoints) > g.maxBufferSize {
if time.Since(lastEmission).Seconds() >= float64(g.interval) || len(metrics) >=g.maxBufferSize {
g.emitMetrics(metrics)
lastEmission = time.Now()
metrics = make([]string, 0, g.maxBufferSize)
}
metrics = append(metrics, *datapoints...)
}

}

func (g *Graphite) convertToGraphite(metric *metric.Metric) *[]string{
func (g *Graphite) convertToGraphite(metric *metric.Metric) string{
outname := g.Prefix() + (*metric).Name
dimensions := metric.GetDimensions(g.DefaultDimensions())
datapoints := make([]string, 0, len(dimensions) + 1)
// for key in dimensions, generate a new metric data point, add to a list, return
//what timestamp to use?
datapoints = append(datapoints, fmt.Sprintf("%s %f %s\n", outname, metric.Value, time.Now())) //find out what time to use

for key, value := range dimensions {
//orders keys so datapoint keeps consistent name
var keys []string
for k := range dimensions {
keys = append(keys, k)
}
sort.Strings(keys)

for _, key := range keys {
//create a list of datapoints for this metric, then append that list the a global list
datapoints = append(datapoints, fmt.Sprintf("%s.%s %f %s\n", outname, key, value, time.Now()))
outname = fmt.Sprintf("%s.%s.%s", outname, key, dimensions[key])
}

return &datapoints
outname = fmt.Sprintf("%s %f %d", outname, metric.Value, time.Now().Unix())

return outname
}

func (g *Graphite) emitMetrics(datapoints []string) {
Expand All @@ -86,6 +95,7 @@ func (g *Graphite) emitMetrics(datapoints []string) {
conn, _ := net.Dial("tcp", fmt.Sprintf("%s:%s", g.server, g.port))
for _, datapoint := range datapoints {
fmt.Fprintf(conn, datapoint)
fmt.Println(datapoint)
}
}

Expand Down

0 comments on commit 4b525ce

Please sign in to comment.