• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang metrics.IncrementCounter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry/dropsonde/metrics.IncrementCounter函数的典型用法代码示例。如果您正苦于以下问题:Golang IncrementCounter函数的具体用法?Golang IncrementCounter怎么用?Golang IncrementCounter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IncrementCounter函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: subscribeToEvents

func (r *RouteFetcher) subscribeToEvents(token *schema.Token) error {
	r.client.SetToken(token.AccessToken)

	r.logger.Info("Subscribing-to-routing-api-event-stream")
	source, err := r.client.SubscribeToEventsWithMaxRetries(maxRetries)
	if err != nil {
		metrics.IncrementCounter(SubscribeEventsErrors)
		r.logger.Error("Failed-to-subscribe-to-routing-api-event-stream: ", err)
		return err
	}
	r.logger.Info("Successfully-subscribed-to-routing-api-event-stream")

	r.eventSource.Store(source)
	var event routing_api.Event

	for {
		event, err = source.Next()
		if err != nil {
			metrics.IncrementCounter(SubscribeEventsErrors)
			r.logger.Error("Failed to get next event: ", err)
			break
		}
		r.logger.Debug("received-event", lager.Data{"event": event})
		r.eventChannel <- event
	}
	return err
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:27,代码来源:route_fetcher.go


示例2: subscribeToEvents

func (r *RouteFetcher) subscribeToEvents(token *schema.Token) error {
	r.client.SetToken(token.AccessToken)
	source, err := r.client.SubscribeToEventsWithMaxRetries(maxRetries)
	if err != nil {
		metrics.IncrementCounter(SubscribeEventsErrors)
		r.logger.Error("Failed to subscribe to events: ", err)
		return err
	}

	r.logger.Info("Successfully subscribed to event stream.")

	r.eventSource.Store(source)

	for {
		event, err := source.Next()
		if err != nil {
			metrics.IncrementCounter(SubscribeEventsErrors)
			r.logger.Error("Failed to get next event: ", err)
			break
		}
		r.logger.Debug("Handling event: ", lager.Data{"event": event})
		r.eventChannel <- event
	}
	return err
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:25,代码来源:route_fetcher.go


示例3: startEventCycle

func (r *RouteFetcher) startEventCycle() {
	go func() {
		useCachedToken := true
		for {
			r.logger.Debug("fetching-token")
			token, err := r.UaaClient.FetchToken(useCachedToken)
			if err != nil {
				metrics.IncrementCounter(TokenFetchErrors)
				r.logger.Error("failed-to-fetch-token", err)
			} else {
				r.logger.Debug("token-fetched-successfully")
				if atomic.LoadInt32(&r.stopEventSource) == 1 {
					return
				}
				err = r.subscribeToEvents(token)
				if err != nil && err.Error() == "unauthorized" {
					useCachedToken = false
				} else {
					useCachedToken = true
				}
				if atomic.LoadInt32(&r.stopEventSource) == 1 {
					return
				}
				time.Sleep(time.Duration(r.SubscriptionRetryIntervalInSeconds) * time.Second)
			}
		}
	}()
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:28,代码来源:route_fetcher.go


示例4: FetchRoutes

func (r *RouteFetcher) FetchRoutes() error {
	r.logger.Debug("fetch-routes-started")
	defer r.logger.Debug("fetch-routes-completed")
	useCachedToken := true
	var err error
	var routes []db.Route
	for count := 0; count < 2; count++ {
		r.logger.Debug("fetching-token")
		token, tokenErr := r.UaaClient.FetchToken(useCachedToken)
		if tokenErr != nil {
			metrics.IncrementCounter(TokenFetchErrors)
			return tokenErr
		}
		r.client.SetToken(token.AccessToken)
		r.logger.Debug("fetching-routes")
		routes, err = r.client.Routes()
		if err != nil {
			if err.Error() == "unauthorized" {
				useCachedToken = false
			} else {
				return err
			}
		} else {
			break
		}
	}

	if err == nil {
		r.logger.Debug("refreshing-endpoints")
		r.refreshEndpoints(routes)
	}

	return err
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:34,代码来源:route_fetcher.go


示例5: fetchRoutesWithTokenRefresh

func (r *RouteFetcher) fetchRoutesWithTokenRefresh() ([]models.Route, error) {
	forceUpdate := false
	var err error
	var routes []models.Route
	for count := 0; count < 2; count++ {
		r.logger.Debug("syncer-fetching-token")
		token, tokenErr := r.UaaClient.FetchToken(forceUpdate)
		if tokenErr != nil {
			metrics.IncrementCounter(TokenFetchErrors)
			return []models.Route{}, tokenErr
		}
		r.client.SetToken(token.AccessToken)
		r.logger.Debug("syncer-fetching-routes")
		routes, err = r.client.Routes()
		if err != nil {
			if err.Error() == "unauthorized" {
				forceUpdate = true
			} else {
				return []models.Route{}, err
			}
		} else {
			break
		}
	}

	return routes, err
}
开发者ID:cloudfoundry,项目名称:gorouter,代码行数:27,代码来源:route_fetcher.go


示例6: FetchRoutes

func (r *RouteFetcher) FetchRoutes() error {
	useCachedToken := true
	var err error
	var routes []db.Route
	for count := 0; count < 2; count++ {
		token, tokenErr := r.TokenFetcher.FetchToken(useCachedToken)
		if tokenErr != nil {
			metrics.IncrementCounter(TokenFetchErrors)
			return tokenErr
		}
		r.client.SetToken(token.AccessToken)
		routes, err = r.client.Routes()
		if err != nil {
			if err.Error() == "unauthorized" {
				useCachedToken = false
			} else {
				return err
			}
		} else {
			break
		}
	}

	if err == nil {
		r.refreshEndpoints(routes)
	}

	return err
}
开发者ID:shashankmjain,项目名称:gorouter,代码行数:29,代码来源:route_fetcher.go


示例7: FetchRoutes

func (r *RouteFetcher) FetchRoutes() error {
	r.logger.Debug("syncer-fetch-routes-started")

	defer func() {
		r.logger.Debug("syncer-fetch-routes-completed")
		r.lock.Lock()
		r.applyCachedEvents()
		r.syncing = false
		r.cachedEvents = nil
		r.lock.Unlock()
	}()

	r.lock.Lock()
	r.syncing = true
	r.cachedEvents = []routing_api.Event{}
	r.lock.Unlock()

	forceUpdate := false
	var err error
	var routes []models.Route
	for count := 0; count < 2; count++ {
		r.logger.Debug("syncer-fetching-token")
		token, tokenErr := r.UaaClient.FetchToken(forceUpdate)
		if tokenErr != nil {
			metrics.IncrementCounter(TokenFetchErrors)
			return tokenErr
		}
		r.client.SetToken(token.AccessToken)
		r.logger.Debug("syncer-fetching-routes")
		routes, err = r.client.Routes()
		if err != nil {
			if err.Error() == "unauthorized" {
				forceUpdate = true
			} else {
				return err
			}
		} else {
			break
		}
	}

	if err == nil {
		r.logger.Debug("syncer-refreshing-endpoints")
		r.refreshEndpoints(routes)
	}

	return err
}
开发者ID:yingkitw,项目名称:gorouter,代码行数:48,代码来源:route_fetcher.go


示例8:

						receivedEvents[eventId] = true
					}()
				}
			}()

			httpListener, err := net.Listen("tcp", "localhost:0")
			Expect(err).ToNot(HaveOccurred())
			defer httpListener.Close()
			httpHandler := dropsonde.InstrumentedHandler(FakeHandler{})
			go http.Serve(httpListener, httpHandler)

			_, err = http.Get("http://" + httpListener.Addr().String())
			Expect(err).ToNot(HaveOccurred())

			metrics.SendValue("TestMetric", 0, "")
			metrics.IncrementCounter("TestIncrementCounter")

			expectedEventTypes := []string{"HttpStartClient", "HttpStartServer", "HttpStopServer", "HttpStopClient", "ValueMetricnumCPUS", "ValueMetricTestMetric", "CounterEventTestIncrementCounter"}

			for _, eventType := range expectedEventTypes {
				Eventually(func() bool {
					lock.RLock()
					defer lock.RUnlock()
					_, ok := receivedEvents[eventType]
					return ok
				}).Should(BeTrue(), fmt.Sprintf("missing %s", eventType))
			}

			heartbeatUuid := heartbeatRequest.GetIdentifier().String()
			Eventually(heartbeatUuidsChan).Should(Receive(Equal(heartbeatUuid)))
开发者ID:jungle0755,项目名称:gorouter,代码行数:30,代码来源:dropsonde_end_to_end_test.go


示例9: Increment

func (c Counter) Increment() {
	metrics.IncrementCounter(string(c))
}
开发者ID:cfibmers,项目名称:runtime-schema,代码行数:3,代码来源:metric.go


示例10: main

func main() {
	flag.Parse()
	config, logger := parseConfig(*debug, *configFile, *logFilePath)

	dropsonde.Initialize(config.MetronAddress, "syslog_drain_binder")

	workPool, err := workpool.NewWorkPool(config.EtcdMaxConcurrentRequests)
	if err != nil {
		panic(err)
	}

	adapter := etcdstoreadapter.NewETCDStoreAdapter(config.EtcdUrls, workPool)

	updateInterval := time.Duration(config.UpdateIntervalSeconds) * time.Second
	politician := elector.NewElector(config.InstanceName, adapter, updateInterval, logger)

	drainTTL := time.Duration(config.DrainUrlTtlSeconds) * time.Second
	store := etcd_syslog_drain_store.NewEtcdSyslogDrainStore(adapter, drainTTL, logger)

	ticker := time.NewTicker(updateInterval)
	for {
		select {
		case <-cfcomponent.RegisterGoRoutineDumpSignalChannel():
			cfcomponent.DumpGoRoutine()
		case <-ticker.C:
			if politician.IsLeader() {
				err = politician.StayAsLeader()
				if err != nil {
					logger.Errorf("Error when staying leader: %s", err.Error())
					politician.Vacate()
					continue
				}
			} else {
				err = politician.RunForElection()

				if err != nil {
					logger.Errorf("Error when running for leader: %s", err.Error())
					politician.Vacate()
					continue
				}
			}

			logger.Debugf("Polling %s for updates", config.CloudControllerAddress)
			drainUrls, err := Poll(config.CloudControllerAddress, config.BulkApiUsername, config.BulkApiPassword, config.PollingBatchSize, config.SkipCertVerify)
			if err != nil {
				logger.Errorf("Error when polling cloud controller: %s", err.Error())
				politician.Vacate()
				continue
			}

			metrics.IncrementCounter("pollCount")

			var totalDrains int
			for _, drainList := range drainUrls {
				totalDrains += len(drainList)
			}

			metrics.SendValue("totalDrains", float64(totalDrains), "drains")

			logger.Debugf("Updating drain URLs for %d application(s)", len(drainUrls))
			err = store.UpdateDrains(drainUrls)
			if err != nil {
				logger.Errorf("Error when updating ETCD: %s", err.Error())
				politician.Vacate()
				continue
			}
		}
	}
}
开发者ID:rakutentech,项目名称:loggregator,代码行数:69,代码来源:main.go


示例11: CaptureRegistryMessage

func (c *MetricsReporter) CaptureRegistryMessage(msg reporter.ComponentTagged) {
	dropsondeMetrics.IncrementCounter("registry_message." + msg.Component())
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:3,代码来源:metrics_reporter.go


示例12:

	BeforeEach(func() {
		fakeMetricSender = fake.NewFakeMetricSender()
		metricBatcher := metricbatcher.New(fakeMetricSender, time.Millisecond)
		metrics.Initialize(fakeMetricSender, metricBatcher)
	})

	It("delegates SendValue", func() {
		metrics.SendValue("metric", 42.42, "answers")

		Expect(fakeMetricSender.GetValue("metric").Value).To(Equal(42.42))
		Expect(fakeMetricSender.GetValue("metric").Unit).To(Equal("answers"))
	})

	It("delegates IncrementCounter", func() {
		metrics.IncrementCounter("count")

		Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(1))

		metrics.IncrementCounter("count")

		Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(2))
	})

	It("delegates BatchIncrementCounter", func() {
		metrics.BatchIncrementCounter("count")
		time.Sleep(2 * time.Millisecond)
		Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(1))

		metrics.BatchIncrementCounter("count")
		time.Sleep(2 * time.Millisecond)
开发者ID:benlaplanche,项目名称:emitter,代码行数:30,代码来源:metrics_test.go



注:本文中的github.com/cloudfoundry/dropsonde/metrics.IncrementCounter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang metrics.Initialize函数代码示例发布时间:2022-05-23
下一篇:
Golang metrics.BatchIncrementCounter函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap