func startMetrics(appName, graphiteServer string) { if graphiteServer == "" { glog.Warningf("No metrics server specified.") return } addr, err := net.ResolveTCPAddr("tcp", graphiteServer) if err != nil { glog.Fatalf("Unable to resolve metrics server address: %s", err) } // Get the hostname and create the app-prefix. hostName, err := os.Hostname() if err != nil { glog.Fatalf("Unable to retrieve hostname: %s", err) } appPrefix := fmt.Sprintf("%s.%s", appName, strings.Replace(hostName, ".", "-", -1)) // Runtime metrics. metrics.RegisterRuntimeMemStats(metrics.DefaultRegistry) go metrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, SAMPLE_PERIOD) go graphite.Graphite(metrics.DefaultRegistry, SAMPLE_PERIOD, appPrefix, addr) // Uptime. uptimeGuage := metrics.GetOrRegisterGaugeFloat64("uptime", metrics.DefaultRegistry) go func() { startTime := time.Now() uptimeGuage.Update(0) for _ = range time.Tick(SAMPLE_PERIOD) { uptimeGuage.Update(time.Since(startTime).Seconds()) } }() }
func newMemoryMetricaDataSource(pollInterval int) goMetricaDataSource { r := metrics.NewRegistry() metrics.RegisterRuntimeMemStats(r) metrics.CaptureRuntimeMemStatsOnce(r) go metrics.CaptureRuntimeMemStats(r, time.Duration(pollInterval)*time.Second) return goMetricaDataSource{r} }
func newStandardBucket(name string) standardBucket { registry := gometrics.NewRegistry() gometrics.RegisterRuntimeMemStats(registry) go gometrics.CaptureRuntimeMemStats(registry, RuntimeMemStatsSampleInterval) return standardBucket{ name: name, registry: registry, timers: make(map[string]Timer), gauges: make(map[string]Gauge), } }
func NewPointInPolygonMetrics() *WOFPointInPolygonMetrics { registry := metrics.NewRegistry() cnt_lookups := metrics.NewCounter() cnt_unmarshal := metrics.NewCounter() cnt_cache_hit := metrics.NewCounter() cnt_cache_miss := metrics.NewCounter() cnt_cache_set := metrics.NewCounter() tm_unmarshal := metrics.NewTimer() tm_intersect := metrics.NewTimer() tm_inflate := metrics.NewTimer() tm_contain := metrics.NewTimer() tm_process := metrics.NewTimer() registry.Register("pip.reversegeo.lookups", cnt_lookups) registry.Register("pip.geojson.unmarshaled", cnt_unmarshal) registry.Register("pip.cache.hit", cnt_cache_hit) registry.Register("pip.cache.miss", cnt_cache_miss) registry.Register("pip.cache.set", cnt_cache_set) registry.Register("pip.timer.reversegeo", tm_process) registry.Register("pip.timer.unmarshal", tm_unmarshal) // registry.Register("time-to-intersect", tm_intersect) // registry.Register("time-to-inflate", tm_inflate) registry.Register("pip.timer.containment", tm_contain) m := WOFPointInPolygonMetrics{ Registry: ®istry, CountLookups: &cnt_lookups, CountUnmarshal: &cnt_unmarshal, CountCacheHit: &cnt_cache_hit, CountCacheMiss: &cnt_cache_miss, CountCacheSet: &cnt_cache_set, TimeToUnmarshal: &tm_unmarshal, TimeToIntersect: &tm_intersect, TimeToInflate: &tm_inflate, TimeToContain: &tm_contain, TimeToProcess: &tm_process, } metrics.RegisterRuntimeMemStats(registry) go metrics.CaptureRuntimeMemStats(registry, 10e9) return &m }
func (s *stats) start() { // Register GC stats. registerGCStats(s.registry) go captureGCStats(s.registry, recordInterval) // Register rusage stats. registerRusageStats(s.registry) go captureRusageStats(s.registry, recordInterval) // Register debug stats. metrics.RegisterDebugGCStats(s.registry) go metrics.CaptureDebugGCStats(s.registry, recordInterval) // Register runtime stats. metrics.RegisterRuntimeMemStats(s.registry) go metrics.CaptureRuntimeMemStats(s.registry, recordInterval) // Start monitoring go s.monitor() }
func setupMetrics(s *options.Settings) { gometrics.RegisterRuntimeMemStats(gometrics.DefaultRegistry) go gometrics.CaptureRuntimeMemStats(gometrics.DefaultRegistry, 60*time.Second) http.Handle("/metrics", metrics.Default) go http.ListenAndServe(s.MetricsListenAddress, nil) }