<commit_before>package main

import (
	"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)
	}
}

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, 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, 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.%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.%s.%s.duration %d\n", bucket, subhost, port, ms)
	s.Timing(fmt.Sprintf("%s.%s.%s", bucket, host, port), ms, 1)
	conn.Close()
}

func main() {
	if len(os.Args) < 3 {
		fmt.Println("Usage: smoketcp <statsd_host>:<statsd_port> <bucket_prefix>")
		fmt.Println("\nEx: smoketcp statsd.example.com:8125 Location.for.smokeping.values")
		os.Exit(1)
	}

	hostname, err := os.Hostname()
	dieIfError(err)
	s, err := statsd.Dial(os.Args[1], fmt.Sprintf("smoketcp.%s", hostname))
	dieIfError(err)
	bucket := os.Args[2]
	defer s.Close()
	doEvery(time.Second, s, bucket)
}<commit_msg>fix how I connect to statsd, with the prefix bucket, remove bucket from all the other functions, output appears correct now<commit_after>package main

import (
	"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)
	}
}

func doEvery(d time.Duration, f func(*statsd.Client), s *statsd.Client) {
	f(s)
	for _ = range time.Tick(d) {
		f(s)
	}
}

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 test(target string, s *statsd.Client) {
	tuple := strings.Split(target, ":")
	host := tuple[0]
	port := tuple[1]
	subhost := strings.Replace(host, ".", "_", -1)

	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)
		return
	}
	duration := time.Since(pre)
	ms := int64(duration / time.Millisecond)
	fmt.Printf("%s.%s.duration %d\n", subhost, port, ms)
	s.Timing(fmt.Sprintf("%s.%s", subhost, port), ms, 1)
	conn.Close()
}

func main() {
	if len(os.Args) < 3 {
		fmt.Println("Usage: smoketcp <statsd_host>:<statsd_port> <bucket_prefix>")
		fmt.Println("\nEx: smoketcp statsd.example.com:8125 Location.for.smokeping.values")
		os.Exit(1)
	}

	s, err := statsd.Dial(os.Args[1], fmt.Sprintf("%s", os.Args[2]))
	dieIfError(err)
	defer s.Close()
	doEvery(time.Second, process_targets, s)
}
{'fraction_non_alphanumeric': 0.18574635241301907, 'fraction_numerical': 0.010101010101010102, 'mean_word_length': 4.144300144300145, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1716035', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1426, 'n_words': 309}