Updates circonus-labs/circonus-gometrics and circonus-labs/circonusllhist.

This commit is contained in:
James Phillips 2016-08-09 16:34:48 -07:00
parent e59161ff8c
commit 6cb32b9f1f
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
8 changed files with 76 additions and 89 deletions

View File

@ -1,2 +0,0 @@
.DS_Store
env.sh

View File

@ -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 <config file>`
or, to add the ui (localhost:8500)
`$GOPATH/src/github.com/hashicorp/consul/bin/consul agent -dev -ui -config-file <config file>`

View File

@ -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) {

View File

@ -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),

View File

@ -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()

View File

@ -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
}

View File

@ -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))

16
vendor/vendor.json vendored
View File

@ -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",