func (met *Metrics) New(name string) {
	met.new(name)
}
New creates a new metric under the given name with a value of 0
package tgo
import (
	"encoding/json"
	"fmt"
	"math"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
	"time"
	"github.com/trivago/tgo/tcontainer"
	"github.com/trivago/tgo/tmath"
)
const (
	MetricProcessStart = "ProcessStart"
	MetricGoRoutines = "GoRoutines"
	MetricGoVersion = "GoVersion"
	MetricMemoryAllocated = "GoMemoryAllocated"
	MetricMemoryNumObjects = "GoMemoryNumObjects"
	MetricMemoryGCEnabled = "GoMemoryGCEnabled"
)
var ProcessStartTime time.Time
var Metric = (*Metrics)(nil)
type Metrics struct {
	store      map[string]*int64
	rates      map[string]*rate
	storeGuard *sync.RWMutex
	rateGuard  *sync.RWMutex
}
type rate struct {
	metric     string
	samples    tcontainer.Int64Slice
	ticker     *time.Ticker
	lastSample int64
	value      int64
	index      uint64
	numMedians int
	relative   bool
}
func init() {
	ProcessStartTime = time.Now()
}
func EnableGlobalMetrics() {
	if Metric == nil {
		Metric = NewMetrics()
	}
}
func NewMetrics() *Metrics {
	return &Metrics{
		store:      make(map[string]*int64),
		rates:      make(map[string]*rate),
		storeGuard: new(sync.RWMutex),
		rateGuard:  new(sync.RWMutex),
	}
}
func (met *Metrics) InitSystemMetrics() {
	met.New(MetricProcessStart)
	met.New(MetricGoRoutines)
	met.New(MetricGoVersion)
	met.New(MetricMemoryAllocated)
	met.New(MetricMemoryNumObjects)
	met.New(MetricMemoryGCEnabled)
	met.Set(MetricProcessStart, ProcessStartTime.Unix())
	version := runtime.Version()
	if version[0] == 'g' && version[1] == 'o' {
		parts := strings.Split(version[2:], ".")
		numericVersion := make([]uint64, tmath.MaxI(3, len(parts)))
		for i, p := range parts {
			numericVersion[i], _ = strconv.ParseUint(p, 10, 64)
		}
		met.SetI(MetricGoVersion, int(numericVersion[0]*10000+numericVersion[1]*100+numericVersion[2]))
	}
	met.UpdateSystemMetrics()
}
func (met *Metrics) Close() {
	for _, r := range met.rates {
		r.ticker.Stop()
	}
}