<commit_before>// Copyright 2015 bs authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package metric

import (
	"log"
	"net"
	"os"
	"time"

	statsdClient "github.com/quipo/statsd"
)

func newStatsd() statter {
	var (
		defaultPrefix string = ""
		defaultPort   string = "8125"
		defaultHost   string = "localhost"
	)
	prefix := os.Getenv("METRICS_STATSD_CLIENT")
	if prefix == "" {
		prefix = defaultPrefix
	}
	port := os.Getenv("METRICS_STATSD_PORT")
	if port == "" {
		port = defaultPort
	}
	host := os.Getenv("METRICS_STATSD_HOST")
	if host == "" {
		host = defaultHost
	}
	return &statsd{
		Host:   host,
		Port:   port,
		Prefix: prefix,
	}
}

type statsd struct {
	Host   string
	Port   string
	Prefix string
}

func (s *statsd) Send(key, value string) error {
	prefix := "myproject."
	client := statsdClient.NewStatsdClient(net.JoinHostPort(s.Host, s.Port), prefix)
	client.CreateSocket()
	interval := time.Second * 2
	stats := statsdClient.NewStatsdBuffer(interval, client)
	err := stats.Gauge(key, 0.0)
	if err != nil {
		log.Printf("[ERROR] unable to send metrics to statsd via UDP: %s", err)
		return err
	}
	return nil
}<commit_msg>metrics/statsd: get prefix from env<commit_after>// Copyright 2015 bs authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package metric

import (
    "fmt"
	"log"
	"net"
	"os"
	"time"

	statsdClient "github.com/quipo/statsd"
)

func newStatsd() statter {
	var (
		defaultPrefix string = ""
		defaultPort   string = "8125"
		defaultHost   string = "localhost"
	)
	prefix := os.Getenv("METRICS_STATSD_CLIENT")
	if prefix == "" {
		prefix = defaultPrefix
	}
	port := os.Getenv("METRICS_STATSD_PORT")
	if port == "" {
		port = defaultPort
	}
	host := os.Getenv("METRICS_STATSD_HOST")
	if host == "" {
		host = defaultHost
	}
	return &statsd{
		Host:   host,
		Port:   port,
		Prefix: prefix,
	}
}

type statsd struct {
	Host   string
	Port   string
	Prefix string
}

func (s *statsd) Send(key, value string) error {
	prefix := fmt.Sprintf("%stsuru.app.host", s.Prefix)
	client := statsdClient.NewStatsdClient(net.JoinHostPort(s.Host, s.Port), prefix)
	client.CreateSocket()
	interval := time.Second * 2
	stats := statsdClient.NewStatsdBuffer(interval, client)
	err := stats.Gauge(key, 0.0)
	if err != nil {
		log.Printf("[ERROR] unable to send metrics to statsd via UDP: %s", err)
		return err
	}
	return nil
}
{'fraction_non_alphanumeric': 0.1274315204446209, 'fraction_numerical': 0.008733624454148471, 'mean_word_length': 3.6408839779005526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7272580', 'n_tokens_mistral': 948, 'n_tokens_neox': 907, 'n_words': 254}