func clean(keyPart string) string {
	return specialChars.ReplaceAllString(keyPart, "-")
}
clean replaces special characters [{}/\\:\s.] with '-'
package metrics
import (
	"regexp"
	"strings"
	"time"
	"github.com/cactus/go-statsd-client/statsd"
)
const samplingRate = 1.0
type StatsdReporter struct {
	client statsd.Statter
	addr   string
	tags   map[string]string
}
type StatsdStopwatch struct {
	client    statsd.Statter
	startTime time.Time
	name      string
	tags      map[string]string
}
func NewStatsdReporter(HostPort string, Prefix string, FlushInterval time.Duration, FlushBytes int, tags map[string]string) Reporter {
	client, err := statsd.NewBufferedClient(HostPort, Prefix, FlushInterval, FlushBytes)
	if err != nil {
		return nil
	}
	return &StatsdReporter{client: client, addr: HostPort, tags: tags}
}
func (r *StatsdReporter) InitMetrics(metricMap map[MetricName]MetricType) {
}
func (r *StatsdReporter) GetChildReporter(tags map[string]string) Reporter {
	client, err := statsd.NewBufferedClient(r.addr, "cherami", time.Second, 0)
	if err != nil {
		return nil
	}
	statsdReporter := &StatsdReporter{client: client, addr: r.addr, tags: tags}
	mergeDictoRight(r.tags, statsdReporter.tags)
	return statsdReporter
}
func (r *StatsdReporter) GetTags() map[string]string {
	return r.tags
}
func (r *StatsdReporter) IncCounter(name string, tags map[string]string, delta int64) {
	reporterTags := mergeDicts(r.tags, tags)
	r.client.Inc(metricstoPrefix(name, reporterTags), delta, samplingRate)
}
func (r *StatsdReporter) UpdateGauge(name string, tags map[string]string, value int64) {
	reporterTags := mergeDicts(r.tags, tags)
	r.client.Gauge(metricstoPrefix(name, reporterTags), value, samplingRate)
}
func newStatsdStopWatch(client statsd.Statter, name string, tags map[string]string) Stopwatch {
	return &StatsdStopwatch{client: client, name: name, startTime: time.Now(), tags: tags}
}
func (r *StatsdReporter) StartTimer(name string, tags map[string]string) Stopwatch {
	reporterTags := mergeDicts(r.tags, tags)
	return newStatsdStopWatch(r.client, name, reporterTags)
}
func (r *StatsdReporter) RecordTimer(name string, tags map[string]string, d time.Duration) {
	reporterTags := mergeDicts(r.tags, tags)
	r.client.TimingDuration(metricstoPrefix(name, reporterTags), d, samplingRate)
}
func (s *StatsdStopwatch) Stop() time.Duration {
	d := time.Since(s.startTime)
	s.client.TimingDuration(metricstoPrefix(s.name, s.tags), d, samplingRate)
	return d
}
func mergeDictoRight(src map[string]string, dest map[string]string) {
	for k, v := range src {
		dest[k] = v
	}
}
func mergeDicts(dic1 map[string]string, dic2 map[string]string) (resultDict map[string]string) {
	resultDict = make(map[string]string)
	mergeDictoRight(dic1, resultDict)
	mergeDictoRight(dic2, resultDict)
	return
}
func metricstoPrefix(name string, tags map[string]string) string {
	parts := []string{name}
	for _, tag := range tagsFlattenOrder {
		if v, ok := tags[tag]; ok {
			parts = append(parts, clean(v))
		}
	}
	return strings.Join(parts, ".")
}
var specialChars = regexp.MustCompile(`[{}/\\:\s.]`)