Created
December 12, 2012 19:31
-
-
Save benhamill/4270814 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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