From ae13d35c25165e4cd04af0ec3b416fbe34b49c80 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 10:49:09 -0400 Subject: [PATCH 01/15] specify graphite bucket prefix on the command line --- smoketcp.go | 122 +++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index e547d8b..f7f57a5 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -1,70 +1,82 @@ package main import ( - "fmt" - "github.com/cactus/go-statsd-client/statsd" - "io/ioutil" - "net" - "os" - "strings" - "time" + "fmt" + "github.com/cactus/go-statsd-client/statsd" + "io/ioutil" + "net" + "os" + "strings" + "time" ) + func dieIfError(err error) { - if err != nil { - fmt.Fprintf(os.Stderr, "Fatal error: %s\n", err.Error()) - os.Exit(1) - } + if err != nil { + fmt.Fprintf(os.Stderr, "Fatal error: %s\n", err.Error()) + os.Exit(1) + } } -func doEvery(d time.Duration, f func(*statsd.Client), s *statsd.Client) { - f(s) - for _ = range time.Tick(d) { - f(s) - } + + +func doEvery(d time.Duration, s *statsd.Client, bucket string) { + process_targets(s, bucket) + for _ = range time.Tick(d) { + process_targets(s, bucket) + } } -func process_targets(s *statsd.Client) { - content, err := ioutil.ReadFile("targets") - if err != nil { - fmt.Println("couldn't open targets file") - return - } - targets := strings.Split(string(content), "\n") - for _, target := range targets { - if len(target) < 1 { - continue - } - go test(target, s) - } + +func process_targets(s *statsd.Client, bucket string) { + content, err := ioutil.ReadFile("targets") + if err != nil { + fmt.Println("couldn't open targets file") + return + } + targets := strings.Split(string(content), "\n") + for _, target := range targets { + if len(target) < 1 { + continue + } + go test(target, s, bucket) + } } -func test(target string, s *statsd.Client) { - pre := time.Now() - conn, err := net.Dial("tcp", target) - if err != nil { - fmt.Println("connect error", target) - s.Inc(fmt.Sprintf("error.%s.dial_failed", target), 1, 1) - return - } - duration := time.Since(pre) - tuple := strings.Split(target, ":") - host := strings.Replace(tuple[0], ".", "_", -1) - port := tuple[1] - ms := int64(duration / time.Millisecond) - fmt.Printf("%s.%s.duration %d\n", host, port, ms) - s.Timing(fmt.Sprintf("dial.%s.%s", host, port), ms, 1) - conn.Close() + + +func test(target string, s *statsd.Client, bucket string) { + tuple := strings.Split(target, ":") + host := tuple[0] + port := tuple[1] + hostport := strings.Join([]string{host, port}, ":") + + pre := time.Now() + conn, err := net.Dial("tcp", hostport) + if err != nil { + fmt.Println("connect error", target) + s.Inc(fmt.Sprintf("%s.smokeping.%s.%s.dial_failed", bucket, host, port), 1, 1) + return + } + duration := time.Since(pre) + subhost := strings.Replace(host, ".", "_", -1) + ms := int64(duration / time.Millisecond) + fmt.Printf("%s.smokeping.%s.%s.duration %d\n", bucket, subhost, port, ms) + s.Timing(fmt.Sprintf("%s.smokeping.%s.%s", bucket, host, port), ms, 1) + conn.Close() } + func main() { - if len(os.Args) == 1 { - fmt.Println("Usage: smoketcp :") - os.Exit(1) - } + if len(os.Args) < 3 { + fmt.Println("Usage: smoketcp : ") + fmt.Println("\nEx: smoketcp statsd.cashstar.net:8125 PROD.us-east-1.dw1") + os.Exit(1) + } - hostname, err := os.Hostname() - dieIfError(err) - s, err := statsd.Dial(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) - dieIfError(err) - defer s.Close() - doEvery(time.Second, process_targets, s) + hostname, err := os.Hostname() + dieIfError(err) + s, err := statsd.New(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) + dieIfError(err) + bucket := os.Args[2] + defer s.Close() + doEvery(time.Second, s, bucket) } From 3cd19b829862579d210f2add5a35ef9c443ffc56 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 10:51:26 -0400 Subject: [PATCH 02/15] update README.md to include new bucket info --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38d6a31..488366e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ Create a "targets" file that looks like: : : ``` -then just `go build smoketcp.go` and `./smoketcp :` and boom. +then just `go build smoketcp.go` and `./smoketcp : ` and boom. + +#Ex: +`./smoketcp statsd.example.com:8125 Location.for.smokeping.values` Every second it tests every entry (in parallel), and reports errors and time-to-connection to statsd. Statsd then aggregates across the flushInterval (in our case 60s) and stores in graphite per target the errors rate, From 6e596f03e387abac6f3d803be1d6ddb4977f6f17 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 11:04:25 -0400 Subject: [PATCH 03/15] fix formatting --- smoketcp.go | 117 +++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 61 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index f7f57a5..dc0b050 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -1,82 +1,77 @@ package main import ( - "fmt" - "github.com/cactus/go-statsd-client/statsd" - "io/ioutil" - "net" - "os" - "strings" - "time" + "fmt" + "github.com/cactus/go-statsd-client/statsd" + "io/ioutil" + "net" + "os" + "strings" + "time" ) - func dieIfError(err error) { - if err != nil { - fmt.Fprintf(os.Stderr, "Fatal error: %s\n", err.Error()) - os.Exit(1) - } + if err != nil { + fmt.Fprintf(os.Stderr, "Fatal error: %s\n", err.Error()) + os.Exit(1) + } } - func doEvery(d time.Duration, s *statsd.Client, bucket string) { - process_targets(s, bucket) - for _ = range time.Tick(d) { - process_targets(s, bucket) - } + process_targets(s, bucket) + for _ = range time.Tick(d) { + process_targets(s, bucket) + } } - func process_targets(s *statsd.Client, bucket string) { - content, err := ioutil.ReadFile("targets") - if err != nil { - fmt.Println("couldn't open targets file") - return - } - targets := strings.Split(string(content), "\n") - for _, target := range targets { - if len(target) < 1 { - continue - } - go test(target, s, bucket) - } + content, err := ioutil.ReadFile("targets") + if err != nil { + fmt.Println("couldn't open targets file") + return + } + targets := strings.Split(string(content), "\n") + for _, target := range targets { + if len(target) < 1 { + continue + } + go test(target, s, bucket) + } } - func test(target string, s *statsd.Client, bucket string) { - tuple := strings.Split(target, ":") - host := tuple[0] - port := tuple[1] - hostport := strings.Join([]string{host, port}, ":") + tuple := strings.Split(target, ":") + host := tuple[0] + port := tuple[1] + hostport := strings.Join([]string{host, port}, ":") - pre := time.Now() - conn, err := net.Dial("tcp", hostport) - if err != nil { - fmt.Println("connect error", target) - s.Inc(fmt.Sprintf("%s.smokeping.%s.%s.dial_failed", bucket, host, port), 1, 1) - return - } - duration := time.Since(pre) - subhost := strings.Replace(host, ".", "_", -1) - ms := int64(duration / time.Millisecond) - fmt.Printf("%s.smokeping.%s.%s.duration %d\n", bucket, subhost, port, ms) - s.Timing(fmt.Sprintf("%s.smokeping.%s.%s", bucket, host, port), ms, 1) - conn.Close() + pre := time.Now() + conn, err := net.Dial("tcp", hostport) + if err != nil { + fmt.Println("connect error", target) + s.Inc(fmt.Sprintf("%s.smokeping.%s.%s.dial_failed", bucket, host, port), 1, 1) + return + } + duration := time.Since(pre) + subhost := strings.Replace(host, ".", "_", -1) + ms := int64(duration / time.Millisecond) + fmt.Printf("%s.smokeping.%s.%s.duration %d\n", bucket, subhost, port, ms) + s.Timing(fmt.Sprintf("%s.smokeping.%s.%s", bucket, host, port), ms, 1) + conn.Close() } - func main() { - if len(os.Args) < 3 { - fmt.Println("Usage: smoketcp : ") - fmt.Println("\nEx: smoketcp statsd.cashstar.net:8125 PROD.us-east-1.dw1") - os.Exit(1) - } + if len(os.Args) < 3 { + fmt.Println("Usage: smoketcp : ") + fmt.Println("\nEx: smoketcp statsd.cashstar.net:8125 PROD.us-east-1.dw1") + os.Exit(1) + } - hostname, err := os.Hostname() - dieIfError(err) - s, err := statsd.New(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) - dieIfError(err) - bucket := os.Args[2] - defer s.Close() - doEvery(time.Second, s, bucket) + hostname, err := os.Hostname() + dieIfError(err) + s, err := statsd.New(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) + dieIfError(err) + bucket := os.Args[2] + defer s.Close() + doEvery(time.Second, s, bucket) } From 2c318e59795cdf2784e62cfaa0f07ddfcc4c5377 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 11:12:25 -0400 Subject: [PATCH 04/15] remove company specific info --- smoketcp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoketcp.go b/smoketcp.go index dc0b050..0ceb77f 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -63,7 +63,7 @@ func test(target string, s *statsd.Client, bucket string) { func main() { if len(os.Args) < 3 { fmt.Println("Usage: smoketcp : ") - fmt.Println("\nEx: smoketcp statsd.cashstar.net:8125 PROD.us-east-1.dw1") + fmt.Println("\nEx: smoketcp statsd.example.com:8125 Location.for.smokeping.values") os.Exit(1) } From 693b8c883da8c2eb20cdf7ee7a8a8e1ece72c6ec Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 11:33:58 -0400 Subject: [PATCH 05/15] change New back to Dial, and remove smokeping from the statsd Timing bucket --- smoketcp.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index 0ceb77f..a3ee4f4 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -49,14 +49,14 @@ func test(target string, s *statsd.Client, bucket string) { conn, err := net.Dial("tcp", hostport) if err != nil { fmt.Println("connect error", target) - s.Inc(fmt.Sprintf("%s.smokeping.%s.%s.dial_failed", bucket, host, port), 1, 1) + s.Inc(fmt.Sprintf("%s.%s.%s.dial_failed", bucket, host, port), 1, 1) return } duration := time.Since(pre) subhost := strings.Replace(host, ".", "_", -1) ms := int64(duration / time.Millisecond) - fmt.Printf("%s.smokeping.%s.%s.duration %d\n", bucket, subhost, port, ms) - s.Timing(fmt.Sprintf("%s.smokeping.%s.%s", bucket, host, port), ms, 1) + fmt.Printf("%s.%s.%s.duration %d\n", bucket, subhost, port, ms) + s.Timing(fmt.Sprintf("%s.%s.%s", bucket, host, port), ms, 1) conn.Close() } @@ -69,7 +69,7 @@ func main() { hostname, err := os.Hostname() dieIfError(err) - s, err := statsd.New(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) + s, err := statsd.Dial(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) dieIfError(err) bucket := os.Args[2] defer s.Close() From f9a63d8d5acdcdbffd2d9d3d6c3b5184015040dd Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 12:01:08 -0400 Subject: [PATCH 06/15] fix how I connect to statsd, with the prefix bucket, remove bucket from all the other functions, output appears correct now --- smoketcp.go | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index a3ee4f4..fd8bd4a 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -17,14 +17,14 @@ func dieIfError(err error) { } } -func doEvery(d time.Duration, s *statsd.Client, bucket string) { - process_targets(s, bucket) +func doEvery(d time.Duration, f func(*statsd.Client), s *statsd.Client) { + f(s) for _ = range time.Tick(d) { - process_targets(s, bucket) + f(s) } } -func process_targets(s *statsd.Client, bucket string) { +func process_targets(s *statsd.Client) { content, err := ioutil.ReadFile("targets") if err != nil { fmt.Println("couldn't open targets file") @@ -35,28 +35,27 @@ func process_targets(s *statsd.Client, bucket string) { if len(target) < 1 { continue } - go test(target, s, bucket) + go test(target, s) } } -func test(target string, s *statsd.Client, bucket string) { +func test(target string, s *statsd.Client) { tuple := strings.Split(target, ":") host := tuple[0] port := tuple[1] - hostport := strings.Join([]string{host, port}, ":") + subhost := strings.Replace(host, ".", "_", -1) pre := time.Now() - conn, err := net.Dial("tcp", hostport) + conn, err := net.Dial("tcp", target) if err != nil { fmt.Println("connect error", target) - s.Inc(fmt.Sprintf("%s.%s.%s.dial_failed", bucket, host, port), 1, 1) + s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) return } duration := time.Since(pre) - subhost := strings.Replace(host, ".", "_", -1) ms := int64(duration / time.Millisecond) - fmt.Printf("%s.%s.%s.duration %d\n", bucket, subhost, port, ms) - s.Timing(fmt.Sprintf("%s.%s.%s", bucket, host, port), ms, 1) + fmt.Printf("%s.%s.duration %d\n", subhost, port, ms) + s.Timing(fmt.Sprintf("%s.%s", subhost, port), ms, 1) conn.Close() } @@ -67,11 +66,8 @@ func main() { os.Exit(1) } - hostname, err := os.Hostname() - dieIfError(err) - s, err := statsd.Dial(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname)) + s, err := statsd.Dial(os.Args[1], fmt.Sprintf("%s", os.Args[2])) dieIfError(err) - bucket := os.Args[2] defer s.Close() - doEvery(time.Second, s, bucket) + doEvery(time.Second, process_targets, s) } From 819cee12e29a884329df8de0edf3f49e52d31121 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 13:10:33 -0400 Subject: [PATCH 07/15] use flags on the commandline, statsd_host, statsd_port, and bucket --- smoketcp.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index fd8bd4a..63da9d8 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "github.com/cactus/go-statsd-client/statsd" "io/ioutil" @@ -60,13 +61,12 @@ func test(target string, s *statsd.Client) { } func main() { - if len(os.Args) < 3 { - fmt.Println("Usage: smoketcp : ") - fmt.Println("\nEx: smoketcp statsd.example.com:8125 Location.for.smokeping.values") - os.Exit(1) - } + var statsd_host = flag.String("statsd_host", "localhost", "Statsd Hostname") + var statsd_port = flag.String("statsd_port", "8125", "Statsd port") + var bucket = flag.String("bucket", "smoketcp", "Graphite bucket prefix") + flag.Parse() - s, err := statsd.Dial(os.Args[1], fmt.Sprintf("%s", os.Args[2])) + s, err := statsd.Dial(fmt.Sprintf("%s:%s", *statsd_host, *statsd_port), fmt.Sprintf("%s", *bucket)) dieIfError(err) defer s.Close() doEvery(time.Second, process_targets, s) From 7b4559db955c53023b11f7075842ae7444c55661 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 13:30:32 -0400 Subject: [PATCH 08/15] add debug flag, to only output to stdout if set to true --- smoketcp.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index 63da9d8..ea27671 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -18,17 +18,19 @@ func dieIfError(err error) { } } -func doEvery(d time.Duration, f func(*statsd.Client), s *statsd.Client) { - f(s) +func doEvery(d time.Duration, f func(*statsd.Client, string, bool), s *statsd.Client, target_file string, debug bool) { + f(s, target_file, debug) for _ = range time.Tick(d) { - f(s) + f(s, target_file, debug) } } -func process_targets(s *statsd.Client) { - content, err := ioutil.ReadFile("targets") +func process_targets(s *statsd.Client, target_file string, debug bool) { + content, err := ioutil.ReadFile(target_file) if err != nil { - fmt.Println("couldn't open targets file") + if debug { + fmt.Println("couldn't open targets file: %s", target_file) + } return } targets := strings.Split(string(content), "\n") @@ -36,11 +38,11 @@ func process_targets(s *statsd.Client) { if len(target) < 1 { continue } - go test(target, s) + go test(target, s, debug) } } -func test(target string, s *statsd.Client) { +func test(target string, s *statsd.Client, debug bool) { tuple := strings.Split(target, ":") host := tuple[0] port := tuple[1] @@ -49,13 +51,17 @@ func test(target string, s *statsd.Client) { pre := time.Now() conn, err := net.Dial("tcp", target) if err != nil { - fmt.Println("connect error", target) - s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) + if debug { + fmt.Println("connect error", target) + } + s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) return } duration := time.Since(pre) ms := int64(duration / time.Millisecond) - fmt.Printf("%s.%s.duration %d\n", subhost, port, ms) + if debug { + fmt.Printf("%s.%s.duration %d\n", subhost, port, ms) + } s.Timing(fmt.Sprintf("%s.%s", subhost, port), ms, 1) conn.Close() } @@ -64,10 +70,12 @@ func main() { var statsd_host = flag.String("statsd_host", "localhost", "Statsd Hostname") var statsd_port = flag.String("statsd_port", "8125", "Statsd port") var bucket = flag.String("bucket", "smoketcp", "Graphite bucket prefix") + var target_file = flag.String("target_file", "targets", "File containing the list of targets, ex: server1:80") + var debug = flag.Bool("debug", false, "if true, turn on debugging output") flag.Parse() s, err := statsd.Dial(fmt.Sprintf("%s:%s", *statsd_host, *statsd_port), fmt.Sprintf("%s", *bucket)) dieIfError(err) defer s.Close() - doEvery(time.Second, process_targets, s) + doEvery(time.Second, process_targets, s, *target_file, *debug) } From c057214f30838566c29c4e2ff2ef417b589bc8dc Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 13:43:56 -0400 Subject: [PATCH 09/15] fix formatting again --- smoketcp.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index ea27671..f5da337 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -28,9 +28,9 @@ func doEvery(d time.Duration, f func(*statsd.Client, string, bool), s *statsd.Cl func process_targets(s *statsd.Client, target_file string, debug bool) { content, err := ioutil.ReadFile(target_file) if err != nil { - if debug { - fmt.Println("couldn't open targets file: %s", target_file) - } + if debug { + fmt.Println("couldn't open targets file: %s", target_file) + } return } targets := strings.Split(string(content), "\n") @@ -51,28 +51,28 @@ func test(target string, s *statsd.Client, debug bool) { pre := time.Now() conn, err := net.Dial("tcp", target) if err != nil { - if debug { - fmt.Println("connect error", target) + if debug { + fmt.Println("connect error", target) } - s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) + s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) return } duration := time.Since(pre) ms := int64(duration / time.Millisecond) - if debug { - fmt.Printf("%s.%s.duration %d\n", subhost, port, ms) - } + if debug { + fmt.Printf("%s.%s.duration %d\n", subhost, port, ms) + } s.Timing(fmt.Sprintf("%s.%s", subhost, port), ms, 1) conn.Close() } func main() { - var statsd_host = flag.String("statsd_host", "localhost", "Statsd Hostname") - var statsd_port = flag.String("statsd_port", "8125", "Statsd port") - var bucket = flag.String("bucket", "smoketcp", "Graphite bucket prefix") - var target_file = flag.String("target_file", "targets", "File containing the list of targets, ex: server1:80") - var debug = flag.Bool("debug", false, "if true, turn on debugging output") - flag.Parse() + var statsd_host = flag.String("statsd_host", "localhost", "Statsd Hostname") + var statsd_port = flag.String("statsd_port", "8125", "Statsd port") + var bucket = flag.String("bucket", "smoketcp", "Graphite bucket prefix") + var target_file = flag.String("target_file", "targets", "File containing the list of targets, ex: server1:80") + var debug = flag.Bool("debug", false, "if true, turn on debugging output") + flag.Parse() s, err := statsd.Dial(fmt.Sprintf("%s:%s", *statsd_host, *statsd_port), fmt.Sprintf("%s", *bucket)) dieIfError(err) From d9e0e9ada3ecfc9917fc354bbbec73c53b32fa0f Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 14:06:38 -0400 Subject: [PATCH 10/15] fix output for failed target file, and failed connection --- smoketcp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index f5da337..dfc06b3 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -29,7 +29,7 @@ func process_targets(s *statsd.Client, target_file string, debug bool) { content, err := ioutil.ReadFile(target_file) if err != nil { if debug { - fmt.Println("couldn't open targets file: %s", target_file) + fmt.Println("couldn't open targets file:", target_file) } return } @@ -52,7 +52,7 @@ func test(target string, s *statsd.Client, debug bool) { conn, err := net.Dial("tcp", target) if err != nil { if debug { - fmt.Println("connect error", target) + fmt.Println("connect error:", subhost, port) } s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) return From e39e1a13a788ad04732a62debf82d56d7c782561 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Wed, 29 Oct 2014 16:56:57 -0400 Subject: [PATCH 11/15] add interval flag, there is no reason to hig this every second --- smoketcp.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/smoketcp.go b/smoketcp.go index dfc06b3..95df520 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -57,13 +57,13 @@ func test(target string, s *statsd.Client, debug bool) { s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1) return } + conn.Close() duration := time.Since(pre) ms := int64(duration / time.Millisecond) if debug { fmt.Printf("%s.%s.duration %d\n", subhost, port, ms) } s.Timing(fmt.Sprintf("%s.%s", subhost, port), ms, 1) - conn.Close() } func main() { @@ -72,10 +72,11 @@ func main() { var bucket = flag.String("bucket", "smoketcp", "Graphite bucket prefix") var target_file = flag.String("target_file", "targets", "File containing the list of targets, ex: server1:80") var debug = flag.Bool("debug", false, "if true, turn on debugging output") + var interval = flag.Int("interval", 10, "How often to run the tests") flag.Parse() s, err := statsd.Dial(fmt.Sprintf("%s:%s", *statsd_host, *statsd_port), fmt.Sprintf("%s", *bucket)) dieIfError(err) defer s.Close() - doEvery(time.Second, process_targets, s, *target_file, *debug) + doEvery(time.Duration(*interval)*time.Second, process_targets, s, *target_file, *debug) } From ad8762001fbea7ebdea1d7ebc577e36a1758a448 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Thu, 30 Oct 2014 13:17:28 -0400 Subject: [PATCH 12/15] update README.md to show new options --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 488366e..49eafc2 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,23 @@ Create a "targets" file that looks like: : : ``` -then just `go build smoketcp.go` and `./smoketcp : ` and boom. + +then just `go build smoketcp.go` and `./smoketcp --statsd_host --statsd_port --bucket ` + +The available flags are available with --help: +``` +./smoketcp --help +Usage of ./smoketcp: + -bucket="smoketcp": Graphite bucket prefix + -debug=false: if true, turn on debugging output + -interval=10: How often to run the tests + -statsd_host="localhost": Statsd Hostname + -statsd_port="8125": Statsd port + -target_file="targets": File containing the list of targets, ex: server1:80 +``` #Ex: -`./smoketcp statsd.example.com:8125 Location.for.smokeping.values` +`./smoketcp -- statsd_host statsd.example.com --statsd_port 8125 --bucket Location.for.smokeping.values --interval 1 --target_file /etc/smoketcp_targets.txt` Every second it tests every entry (in parallel), and reports errors and time-to-connection to statsd. Statsd then aggregates across the flushInterval (in our case 60s) and stores in graphite per target the errors rate, From 30492d218dda53ef862b6ce9905fdedef753425d Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Thu, 30 Oct 2014 13:21:08 -0400 Subject: [PATCH 13/15] remove Example and clean up formatting a bit --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 49eafc2..3c421a4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Create a "targets" file that looks like: : ``` -then just `go build smoketcp.go` and `./smoketcp --statsd_host --statsd_port --bucket ` +then just: + `go build smoketcp.go` +and: + `./smoketcp --statsd_host --statsd_port --bucket ` The available flags are available with --help: ``` @@ -25,9 +28,6 @@ Usage of ./smoketcp: -target_file="targets": File containing the list of targets, ex: server1:80 ``` -#Ex: -`./smoketcp -- statsd_host statsd.example.com --statsd_port 8125 --bucket Location.for.smokeping.values --interval 1 --target_file /etc/smoketcp_targets.txt` - -Every second it tests every entry (in parallel), and reports errors and time-to-connection to statsd. +Every ten seconds (configurable with --interval) it tests every entry (in parallel), and reports errors and time-to-connection to statsd. Statsd then aggregates across the flushInterval (in our case 60s) and stores in graphite per target the errors rate, and the mean, lower, upper, upper_90 etc values. From 927e4c2113a16bfd813302f25aa38a41364fd69f Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Thu, 30 Oct 2014 13:22:47 -0400 Subject: [PATCH 14/15] more readme layout changes --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3c421a4..a628a0e 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,16 @@ Create a "targets" file that looks like: ``` then just: - `go build smoketcp.go` +``` +go build smoketcp.go +``` + and: - `./smoketcp --statsd_host --statsd_port --bucket ` +``` +./smoketcp --statsd_host --statsd_port --bucket +``` -The available flags are available with --help: +The flags are available with --help: ``` ./smoketcp --help Usage of ./smoketcp: From eca24ccb1ef8d15e30fa44f68ff1c7eb5edc4639 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Sat, 1 Nov 2014 20:21:54 -0400 Subject: [PATCH 15/15] change variable names to conform to go formatting requirements --- README.md | 8 ++++---- smoketcp.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a628a0e..7b9a0c7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ go build smoketcp.go and: ``` -./smoketcp --statsd_host --statsd_port --bucket +./smoketcp --statsdHost --statsdPort --bucket ``` The flags are available with --help: @@ -28,9 +28,9 @@ Usage of ./smoketcp: -bucket="smoketcp": Graphite bucket prefix -debug=false: if true, turn on debugging output -interval=10: How often to run the tests - -statsd_host="localhost": Statsd Hostname - -statsd_port="8125": Statsd port - -target_file="targets": File containing the list of targets, ex: server1:80 + -statsdHost="localhost": Statsd Hostname + -statsdPort="8125": Statsd port + -targetFile="targets": File containing the list of targets, ex: server1:80 ``` Every ten seconds (configurable with --interval) it tests every entry (in parallel), and reports errors and time-to-connection to statsd. diff --git a/smoketcp.go b/smoketcp.go index 95df520..4416105 100644 --- a/smoketcp.go +++ b/smoketcp.go @@ -18,18 +18,18 @@ func dieIfError(err error) { } } -func doEvery(d time.Duration, f func(*statsd.Client, string, bool), s *statsd.Client, target_file string, debug bool) { - f(s, target_file, debug) +func doEvery(d time.Duration, f func(*statsd.Client, string, bool), s *statsd.Client, targetFile string, debug bool) { + f(s, targetFile, debug) for _ = range time.Tick(d) { - f(s, target_file, debug) + f(s, targetFile, debug) } } -func process_targets(s *statsd.Client, target_file string, debug bool) { - content, err := ioutil.ReadFile(target_file) +func processTargets(s *statsd.Client, targetFile string, debug bool) { + content, err := ioutil.ReadFile(targetFile) if err != nil { if debug { - fmt.Println("couldn't open targets file:", target_file) + fmt.Println("couldn't open targets file:", targetFile) } return } @@ -67,16 +67,16 @@ func test(target string, s *statsd.Client, debug bool) { } func main() { - var statsd_host = flag.String("statsd_host", "localhost", "Statsd Hostname") - var statsd_port = flag.String("statsd_port", "8125", "Statsd port") + var statsdHost = flag.String("statsdHost", "localhost", "Statsd Hostname") + var statsdPort = flag.String("statsdPort", "8125", "Statsd port") var bucket = flag.String("bucket", "smoketcp", "Graphite bucket prefix") - var target_file = flag.String("target_file", "targets", "File containing the list of targets, ex: server1:80") + var targetFile = flag.String("targetFile", "targets", "File containing the list of targets, ex: server1:80") var debug = flag.Bool("debug", false, "if true, turn on debugging output") var interval = flag.Int("interval", 10, "How often to run the tests") flag.Parse() - s, err := statsd.Dial(fmt.Sprintf("%s:%s", *statsd_host, *statsd_port), fmt.Sprintf("%s", *bucket)) + s, err := statsd.Dial(fmt.Sprintf("%s:%s", *statsdHost, *statsdPort), fmt.Sprintf("%s", *bucket)) dieIfError(err) defer s.Close() - doEvery(time.Duration(*interval)*time.Second, process_targets, s, *target_file, *debug) + doEvery(time.Duration(*interval)*time.Second, processTargets, s, *targetFile, *debug) }