Skip to content

Instantly share code, notes, and snippets.

@benhamill
Created December 12, 2012 19:31
Show Gist options
  • Save benhamill/4270814 to your computer and use it in GitHub Desktop.
Save benhamill/4270814 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"flag"
"time"
"net"
"fmt"
"bufio"
)
var (
ns *string = flag.String("ns", "namespace", "namespace")
)
func main() {
name := "name"
var count uint64
count = 3
t := time.Now().Unix()
conn, err := net.Dial("tcp", "metrics.prod.ec2.oib.com:2003")
if err != nil {
log.Printf("Connection error: %v", err)
return
}
defer conn.Close()
writer := bufio.NewWriter(conn)
log.Printf("%s.%s %d %d", *ns, name, count, t)
bytes, err := fmt.Fprintf(writer, "%s.%s %d %d", *ns, name, count, t)
writer.Flush()
if err != nil {
log.Printf("Printing error after %v bytes: %v", bytes, err)
} else {
log.Printf("Done.")
}
}
ubuntu@imap-proxy-i-8e5448f3:~$ ./foo
2012/12/12 19:12:50 namespace.name 3 1355339570
2012/12/12 19:12:50 Done. # no metric
ubuntu@imap-proxy-i-8e5448f3:~$ echo "namespace.name 3 1355339570" | nc metrics.prod.ec2.oib.com 2003 # metric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment