From 6cb32b9f1f24b39297fdb6dc6afb000c16ce274c Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 9 Aug 2016 16:34:48 -0700 Subject: [PATCH] Updates circonus-labs/circonus-gometrics and circonus-labs/circonusllhist. --- .../circonus-gometrics/.gitignore | 2 - .../circonus-gometrics/DEVINFO.md | 69 ------------------- .../circonus-gometrics/README.md | 14 ++-- .../circonus-gometrics/circonus-gometrics.go | 4 +- .../circonus-gometrics/counter.go | 7 ++ .../circonus-labs/circonus-gometrics/gauge.go | 44 +++++++++++- .../circonus-labs/circonus-gometrics/util.go | 9 +-- vendor/vendor.json | 16 +++-- 8 files changed, 76 insertions(+), 89 deletions(-) delete mode 100644 vendor/github.com/circonus-labs/circonus-gometrics/.gitignore delete mode 100644 vendor/github.com/circonus-labs/circonus-gometrics/DEVINFO.md diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/.gitignore b/vendor/github.com/circonus-labs/circonus-gometrics/.gitignore deleted file mode 100644 index 510e65cd6c..0000000000 --- a/vendor/github.com/circonus-labs/circonus-gometrics/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.DS_Store -env.sh diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/DEVINFO.md b/vendor/github.com/circonus-labs/circonus-gometrics/DEVINFO.md deleted file mode 100644 index b41e8a04e6..0000000000 --- a/vendor/github.com/circonus-labs/circonus-gometrics/DEVINFO.md +++ /dev/null @@ -1,69 +0,0 @@ -# Setting up dev/test environment - -Get go installed and environment configured - -```sh - -cd $GOPATH -mkdir -pv src/github.com/{hashicorp,armon,circonus-labs} - -cd $GOPATH/src/github.com/hashicorp -git clone https://github.com/maier/consul.git - -cd $GOPATH/src/github.com/armon -git clone https://github.com/maier/go-metrics.git - -cd $GOPATH/src/github.com/circonus-labs -git clone https://github.com/maier/circonus-gometrics.git - - -cd $GOPATH/src/github.com/hashicorp/consul -make dev -``` - -In `$GOPATH/src/github.com/hashicorp/consul/bin` is the binary just created. - -Create a consul configuration file somewhere (e.g. ~/testconfig.json) and add any applicable configuration settings. As an example: - -```json -{ - "datacenter": "mcfl", - "server": true, - "log_level": "debug", - "telemetry": { - "statsd_address": "127.0.0.1:8125", - "circonus_api_token": "...", - "circonus_api_host": "..." - } -} -``` - -StatsD was used as a check to see what metrics consul was sending and what metrics circonus was receiving. So, it can safely be elided. - -Fill in appropriate cirocnus specific settings: - -* circonus_api_token - required -* circonus_api_app - optional, default is circonus-gometrics -* circonus_api_host - optional, default is api.circonus.com (for dev stuff yon can use "http://..." to circumvent ssl) -* circonus_submission_url - optional -* circonus_submission_interval - optional, seconds, defaults to 10 seconds -* circonus_check_id - optional -* circonus_broker_id - optional (unless you want to use the public one, then add it) - -The actual circonus-gometrics package has more configuraiton options, the above are exposed in the consul configuration. - -CirconusMetrics.InstanceId is derived from consul's config.NodeName and config.Datacenter -CirconusMetrics.SearchTag is hardcoded as 'service:consul' - -The defaults are taken for other options. - ---- - -To run after creating the config: - -`$GOPATH/src/github.com/hashicorp/consul/bin/consul agent -dev -config-file ` - -or, to add the ui (localhost:8500) - -`$GOPATH/src/github.com/hashicorp/consul/bin/consul agent -dev -ui -config-file ` - diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/README.md b/vendor/github.com/circonus-labs/circonus-gometrics/README.md index 3bc4f544f2..f0889037b3 100644 --- a/vendor/github.com/circonus-labs/circonus-gometrics/README.md +++ b/vendor/github.com/circonus-labs/circonus-gometrics/README.md @@ -142,8 +142,6 @@ func main() { } ``` -# untested - ### HTTP Handler wrapping ``` @@ -156,14 +154,20 @@ http.HandleFunc("/", metrics.TrackHTTPLatency("/", handler_func)) package main import ( + "os" "fmt" "net/http" - metrics "github.com/circonus-labs/circonus-gometrics" + cgm "github.com/circonus-labs/circonus-gometrics" ) func main() { - metrics.WithAuthToken("9fdd5432-5308-4691-acd1-6bf1f7a20f73") - metrics.WithCheckId(115010) + cmc := &cgm.Config{} + cmc.CheckManager.API.TokenKey = os.Getenv("CIRCONUS_API_TOKEN") + + metrics, err := cgm.NewCirconusMetrics(cmc) + if err != nil { + panic(err) + } metrics.Start() http.HandleFunc("/", metrics.TrackHTTPLatency("/", func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/circonus-gometrics.go b/vendor/github.com/circonus-labs/circonus-gometrics/circonus-gometrics.go index b27af52892..2fd6aad60f 100644 --- a/vendor/github.com/circonus-labs/circonus-gometrics/circonus-gometrics.go +++ b/vendor/github.com/circonus-labs/circonus-gometrics/circonus-gometrics.go @@ -68,7 +68,7 @@ type CirconusMetrics struct { counterFuncs map[string]func() uint64 cfm sync.Mutex - gauges map[string]int64 + gauges map[string]string gm sync.Mutex gaugeFuncs map[string]func() int64 @@ -94,7 +94,7 @@ func NewCirconusMetrics(cfg *Config) (*CirconusMetrics, error) { cm := &CirconusMetrics{ counters: make(map[string]uint64), counterFuncs: make(map[string]func() uint64), - gauges: make(map[string]int64), + gauges: make(map[string]string), gaugeFuncs: make(map[string]func() int64), histograms: make(map[string]*Histogram), text: make(map[string]string), diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/counter.go b/vendor/github.com/circonus-labs/circonus-gometrics/counter.go index a233b274eb..ef3a85c015 100644 --- a/vendor/github.com/circonus-labs/circonus-gometrics/counter.go +++ b/vendor/github.com/circonus-labs/circonus-gometrics/counter.go @@ -15,6 +15,13 @@ func (m *CirconusMetrics) IncrementByValue(metric string, val uint64) { m.Add(metric, val) } +// Set a counter to specific value +func (m *CirconusMetrics) Set(metric string, val uint64) { + m.cm.Lock() + defer m.cm.Unlock() + m.counters[metric] = val +} + // Add updates counter by supplied value func (m *CirconusMetrics) Add(metric string, val uint64) { m.cm.Lock() diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/gauge.go b/vendor/github.com/circonus-labs/circonus-gometrics/gauge.go index 3fdf7120b8..7573f655f8 100644 --- a/vendor/github.com/circonus-labs/circonus-gometrics/gauge.go +++ b/vendor/github.com/circonus-labs/circonus-gometrics/gauge.go @@ -5,16 +5,20 @@ package circonusgometrics // Use a gauge to track metrics which increase and decrease (e.g., amount of // free memory). +import ( + "fmt" +) + // Gauge sets a gauge to a value -func (m *CirconusMetrics) Gauge(metric string, val int64) { +func (m *CirconusMetrics) Gauge(metric string, val interface{}) { m.SetGauge(metric, val) } // SetGauge sets a gauge to a value -func (m *CirconusMetrics) SetGauge(metric string, val int64) { +func (m *CirconusMetrics) SetGauge(metric string, val interface{}) { m.gm.Lock() defer m.gm.Unlock() - m.gauges[metric] = val + m.gauges[metric] = m.gaugeValString(val) } // RemoveGauge removes a gauge @@ -37,3 +41,37 @@ func (m *CirconusMetrics) RemoveGaugeFunc(metric string) { defer m.gfm.Unlock() delete(m.gaugeFuncs, metric) } + +// gaugeValString converts an interface value (of a supported type) to a string +func (m *CirconusMetrics) gaugeValString(val interface{}) string { + vs := "" + switch v := val.(type) { + default: + // ignore it, unsupported type + case int: + vs = fmt.Sprintf("%d", v) + case int8: + vs = fmt.Sprintf("%d", v) + case int16: + vs = fmt.Sprintf("%d", v) + case int32: + vs = fmt.Sprintf("%d", v) + case int64: + vs = fmt.Sprintf("%d", v) + case uint: + vs = fmt.Sprintf("%d", v) + case uint8: + vs = fmt.Sprintf("%d", v) + case uint16: + vs = fmt.Sprintf("%d", v) + case uint32: + vs = fmt.Sprintf("%d", v) + case uint64: + vs = fmt.Sprintf("%d", v) + case float32: + vs = fmt.Sprintf("%f", v) + case float64: + vs = fmt.Sprintf("%f", v) + } + return vs +} diff --git a/vendor/github.com/circonus-labs/circonus-gometrics/util.go b/vendor/github.com/circonus-labs/circonus-gometrics/util.go index 8b84b3270b..b2b6984260 100644 --- a/vendor/github.com/circonus-labs/circonus-gometrics/util.go +++ b/vendor/github.com/circonus-labs/circonus-gometrics/util.go @@ -29,7 +29,7 @@ func (m *CirconusMetrics) Reset() { m.counters = make(map[string]uint64) m.counterFuncs = make(map[string]func() uint64) - m.gauges = make(map[string]int64) + m.gauges = make(map[string]string) m.gaugeFuncs = make(map[string]func() int64) m.histograms = make(map[string]*Histogram) m.text = make(map[string]string) @@ -37,7 +37,7 @@ func (m *CirconusMetrics) Reset() { } // snapshot returns a copy of the values of all registered counters and gauges. -func (m *CirconusMetrics) snapshot() (c map[string]uint64, g map[string]int64, h map[string]*circonusllhist.Histogram, t map[string]string) { +func (m *CirconusMetrics) snapshot() (c map[string]uint64, g map[string]string, h map[string]*circonusllhist.Histogram, t map[string]string) { m.cm.Lock() defer m.cm.Unlock() @@ -68,13 +68,14 @@ func (m *CirconusMetrics) snapshot() (c map[string]uint64, g map[string]int64, h c[n] = f() } - g = make(map[string]int64, len(m.gauges)+len(m.gaugeFuncs)) + //g = make(map[string]int64, len(m.gauges)+len(m.gaugeFuncs)) + g = make(map[string]string, len(m.gauges)+len(m.gaugeFuncs)) for n, v := range m.gauges { g[n] = v } for n, f := range m.gaugeFuncs { - g[n] = f() + g[n] = m.gaugeValString(f()) } h = make(map[string]*circonusllhist.Histogram, len(m.histograms)) diff --git a/vendor/vendor.json b/vendor/vendor.json index a6253d1c6d..e9d296000c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -60,20 +60,28 @@ "versionExact": "v1.2.1" }, { + "checksumSHA1": "b5zgHT9TxBAVh/KP9kQi7QVoz9w=", "path": "github.com/circonus-labs/circonus-gometrics", - "revision": "8e7296e1945cf2ac4adc0a08df3eb52419b227c3" + "revision": "a7c30e0dcc6e2341053132470dcedc12bc7705ef", + "revisionTime": "2016-07-22T17:27:10Z" }, { + "checksumSHA1": "IFiYTxu8jshL4A8BCttUaDhp1m4=", "path": "github.com/circonus-labs/circonus-gometrics/api", - "revision": "8e7296e1945cf2ac4adc0a08df3eb52419b227c3" + "revision": "a7c30e0dcc6e2341053132470dcedc12bc7705ef", + "revisionTime": "2016-07-22T17:27:10Z" }, { + "checksumSHA1": "+9vcRzlTdvEjH/Uf8fKC5MXdjNw=", "path": "github.com/circonus-labs/circonus-gometrics/checkmgr", - "revision": "8e7296e1945cf2ac4adc0a08df3eb52419b227c3" + "revision": "a7c30e0dcc6e2341053132470dcedc12bc7705ef", + "revisionTime": "2016-07-22T17:27:10Z" }, { + "checksumSHA1": "C4Z7+l5GOpOCW5DcvNYzheGvQRE=", "path": "github.com/circonus-labs/circonusllhist", - "revision": "d724266ae5270ae8b87a5d2e8081f04e307c3c18" + "revision": "d724266ae5270ae8b87a5d2e8081f04e307c3c18", + "revisionTime": "2016-05-26T04:38:13Z" }, { "path": "github.com/elazarl/go-bindata-assetfs",