本文整理匯總了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()
示例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))
示例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()
示例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))
示例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))
})