當前位置: 首頁>>代碼示例>>Golang>>正文


Golang metricsreporter.Counter類代碼示例

本文整理匯總了Golang中tools/benchmark/metricsreporter.Counter的典型用法代碼示例。如果您正苦於以下問題:Golang Counter類的具體用法?Golang Counter怎麽用?Golang Counter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Counter類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

import (
	"github.com/cloudfoundry/sonde-go/events"
	"tools/benchmark/messagegenerator"
	"tools/legacymetronbenchmark/legacyreader"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"tools/benchmark/metricsreporter"
)

var _ = Describe("LegacyReader", func() {
	Context("Read", func() {
		var (
			receivedCounter        *metricsreporter.Counter
			internalMetricsCounter *metricsreporter.Counter
			reader                 fakeReader
			legacyReader           *legacyreader.LegacyReader
		)

		BeforeEach(func() {
			receivedCounter = metricsreporter.NewCounter("received")
			internalMetricsCounter = metricsreporter.NewCounter("internal metrics")
			reader = fakeReader{}
			legacyReader = legacyreader.NewLegacyReader(receivedCounter, internalMetricsCounter, &reader)
		})

		It("should report legacy log messages", func() {
			reader.event = messagegenerator.BasicLogMessageEnvelope("legacy", "appID")

			legacyReader.Read()
開發者ID:Jonty,項目名稱:loggregator,代碼行數:30,代碼來源:legacy_reader_test.go

示例2:

	"tools/benchmark/messagegenerator"

	"github.com/cloudfoundry/sonde-go/events"

	"tools/benchmark/metricsreporter"
	"tools/metronbenchmark/valuemetricreader"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ValueMetricReader", func() {
	Context("Read", func() {
		var (
			receivedCounter   *metricsreporter.Counter
			reader            fakeReader
			valueMetricReader *valuemetricreader.ValueMetricReader
		)

		BeforeEach(func() {
			receivedCounter = metricsreporter.NewCounter("counter")
			reader = fakeReader{}
			valueMetricReader = valuemetricreader.NewValueMetricReader(receivedCounter, &reader)
		})

		It("should report value metrics", func() {
			reader.event = messagegenerator.BasicValueMetricEnvelope(valuemetricreader.TestOrigin)

			valueMetricReader.Read()

			Expect(receivedCounter.GetValue()).To(BeEquivalentTo(1))
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:31,代碼來源:value_metric_reader_test.go

示例3:

				reporter.ReceivedCounter().IncrementValue()

				Eventually(reporter.NumTicks, "20ms", "1ms").Should(BeEquivalentTo(1))
				rate := reporter.Rate()
				duration := reporter.Duration()
				reporter.Stop()

				Expect(reporter.NumTicks()).To(BeEquivalentTo(1), "The reporter is writing too quickly")

				Eventually(buffer).Should(gbytes.Say(fmt.Sprintf("%s, 1, 1, %.2f/s, 0.00%%", duration, rate)))
			})
		})

		Context("with additional counters", func() {
			var (
				counter1 *metricsreporter.Counter
				counter2 *metricsreporter.Counter
			)

			BeforeEach(func() {
				counter1 = metricsreporter.NewCounter("counter1")
				counter2 = metricsreporter.NewCounter("counter2")
				counters = []*metricsreporter.Counter{counter1, counter2}
			})

			It("reports the column names", func() {
				Eventually(buffer).Should(gbytes.Say("Runtime, Sent, Received, Rate, PercentLoss, counter1, counter2"))
			})

			It("reports additional counter values", func() {
				reporter.ReceivedCounter().IncrementValue()
				reporter.SentCounter().IncrementValue()
開發者ID:kei-yamazaki,項目名稱:loggregator,代碼行數:32,代碼來源:metricsreporter_test.go

示例4:

package messagewriter_test

import (
	"tools/benchmark/messagewriter"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"tools/benchmark/metricsreporter"
)

var _ = Describe("MessageWriter", func() {
	var (
		sentCounter *metricsreporter.Counter
	)
	BeforeEach(func() {
		sentCounter = metricsreporter.NewCounter("sent")
	})

	It("should keep track of the total sent messages", func() {
		msgWriter := messagewriter.NewMessageWriter("localhost", 51161, "", sentCounter)
		message := []byte{}
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)

		Expect(sentCounter.GetValue()).To(BeEquivalentTo(8))
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:31,代碼來源:message_writer_test.go

示例5:

package metricsreporter_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"tools/benchmark/metricsreporter"
)

var _ = Describe("Counter", func() {
	var counter *metricsreporter.Counter

	BeforeEach(func() {
		counter = metricsreporter.NewCounter("counter")
	})

	Context("GetName", func() {
		It("returns its name", func() {
			Expect(counter.GetName()).To(Equal("counter"))
		})
	})

	Context("GetValue", func() {
		It("returns its current value", func() {
			Expect(counter.GetValue()).To(BeEquivalentTo(0))
		})
	})

	Context("GetTotal", func() {
		It("returns its current total", func() {
			Expect(counter.GetTotal()).To(BeEquivalentTo(0))
		})
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:31,代碼來源:counter_test.go


注:本文中的tools/benchmark/metricsreporter.Counter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。