Permalink
Browse files

Merge pull request #19 from kopiczko/master

Make Nop a short branch
  • Loading branch information...
2 parents 8c9e337 + 66f86fd commit 066bd3c4bfd3ae21514b08fc291b093f6ddf1332 @marpaia committed on GitHub Nov 29, 2016
Showing with 30 additions and 30 deletions.
  1. +30 −30 graphite.go
View
@@ -82,39 +82,39 @@ func (graphite *Graphite) SendMetrics(metrics []Metric) error {
// sendMetrics is an internal function that is used to write to the TCP
// connection in order to communicate metrics to the remote Graphite host
func (graphite *Graphite) sendMetrics(metrics []Metric) error {
- zeroed_metric := Metric{} // ignore unintialized metrics
- if !graphite.IsNop() {
- buf := bytes.NewBufferString("")
+ if graphite.IsNop() {
for _, metric := range metrics {
- if metric == zeroed_metric {
- continue // ignore unintialized metrics
- }
- if metric.Timestamp == 0 {
- metric.Timestamp = time.Now().Unix()
- }
- metric_name := ""
- if graphite.Prefix != "" {
- metric_name = fmt.Sprintf("%s.%s", graphite.Prefix, metric.Name)
- } else {
- metric_name = metric.Name
- }
- if graphite.Protocol == "udp" {
- bufString := bytes.NewBufferString(fmt.Sprintf("%s %s %d\n", metric_name, metric.Value, metric.Timestamp))
- graphite.conn.Write(bufString.Bytes())
- continue
- }
- buf.WriteString(fmt.Sprintf("%s %s %d\n", metric_name, metric.Value, metric.Timestamp))
+ log.Printf("Graphite: %s\n", metric)
}
- if graphite.Protocol == "tcp" {
- _, err := graphite.conn.Write(buf.Bytes())
- //fmt.Print("Sent msg:", buf.String(), "'")
- if err != nil {
- return err
- }
+ return nil
+ }
+ zeroed_metric := Metric{} // ignore unintialized metrics
+ buf := bytes.NewBufferString("")
+ for _, metric := range metrics {
+ if metric == zeroed_metric {
+ continue // ignore unintialized metrics
}
- } else {
- for _, metric := range metrics {
- log.Printf("Graphite: %s\n", metric)
+ if metric.Timestamp == 0 {
+ metric.Timestamp = time.Now().Unix()
+ }
+ metric_name := ""
+ if graphite.Prefix != "" {
+ metric_name = fmt.Sprintf("%s.%s", graphite.Prefix, metric.Name)
+ } else {
+ metric_name = metric.Name
+ }
+ if graphite.Protocol == "udp" {
+ bufString := bytes.NewBufferString(fmt.Sprintf("%s %s %d\n", metric_name, metric.Value, metric.Timestamp))
+ graphite.conn.Write(bufString.Bytes())
+ continue
+ }
+ buf.WriteString(fmt.Sprintf("%s %s %d\n", metric_name, metric.Value, metric.Timestamp))
+ }
+ if graphite.Protocol == "tcp" {
+ _, err := graphite.conn.Write(buf.Bytes())
+ //fmt.Print("Sent msg:", buf.String(), "'")
+ if err != nil {
+ return err
}
}
return nil

0 comments on commit 066bd3c

Please sign in to comment.