예제 #1
0
파일: main.go 프로젝트: Reejoshi/cli
func main() {
	err := dropsonde.Initialize(metronAddr, "METRIC-TEST", "z1", "0")
	if err != nil {
		println(err.Error())
	}

	for i := uint64(0); ; i++ {
		println("emitting metric at counter: ", i)
		metrics.SendContainerMetric(appId, 0, 42.42, 1234, i)
		metrics.SendContainerMetric(appId, 1, 11.41, 1234, i)
		metrics.SendContainerMetric(appId, 2, 11.41, 1234, i)
		metrics.SendContainerMetric("donotseethis", 2, 11.41, 1234, i)
		time.Sleep(1 * time.Second)
	}
}
func main() {
	err := dropsonde.Initialize("localhost:3457", "METRIC-TEST", "z1", "0")
	if err != nil {
		println(err.Error())
	}

	var i uint64
	i = 0
	for {
		println("emitting metric at counter: ", i)
		metrics.SendContainerMetric(appID, 0, 42.42, 1234, i)
		metrics.SendContainerMetric(appID, 1, 11.41, 1234, i)
		metrics.SendContainerMetric(appID, 2, 11.41, 1234, i)
		metrics.SendContainerMetric("donotseethis", 2, 11.41, 1234, i)
		i++
		time.Sleep(1 * time.Second)
	}
}
예제 #3
0
func (reporter *StatsReporter) calculateAndSendMetrics(
	logger lager.Logger,
	metricsConfig *executor.MetricsConfig,
	containerMetrics *executor.ContainerMetrics,
	previousInfo *cpuInfo,
	now time.Time,
) *cpuInfo {
	if metricsConfig.Guid == "" {
		return nil
	}

	currentInfo := cpuInfo{
		timeSpentInCPU: containerMetrics.TimeSpentInCPU,
		timeOfSample:   now,
	}

	var cpuPercent float64
	if previousInfo == nil {
		cpuPercent = 0.0
	} else {
		cpuPercent = computeCPUPercent(
			previousInfo.timeSpentInCPU,
			currentInfo.timeSpentInCPU,
			previousInfo.timeOfSample,
			currentInfo.timeOfSample,
		)
	}

	err := metrics.SendContainerMetric(metricsConfig.Guid, int32(metricsConfig.Index), cpuPercent, containerMetrics.MemoryUsageInBytes, containerMetrics.DiskUsageInBytes)
	if err != nil {
		logger.Error("failed-to-send-container-metrics", err, lager.Data{
			"metrics_guid":  metricsConfig.Guid,
			"metrics_index": metricsConfig.Index,
		})
	}

	return &currentInfo
}
예제 #4
0
		Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(15))
	})

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

		metrics.BatchAddCounter("count", 7)
		time.Sleep(2 * time.Millisecond)
		Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(10))
	})

	It("delegates SendContainerMetric", func() {
		appGuid := "some_app_guid"
		metrics.SendContainerMetric(appGuid, 7, 42.42, 1234, 123412341234)

		Expect(fakeMetricSender.GetContainerMetric(appGuid).ApplicationId).To(Equal(appGuid))
		Expect(fakeMetricSender.GetContainerMetric(appGuid).InstanceIndex).To(BeEquivalentTo(7))
		Expect(fakeMetricSender.GetContainerMetric(appGuid).CpuPercentage).To(BeEquivalentTo(42.42))
		Expect(fakeMetricSender.GetContainerMetric(appGuid).MemoryBytes).To(BeEquivalentTo(1234))
		Expect(fakeMetricSender.GetContainerMetric(appGuid).DiskBytes).To(BeEquivalentTo(123412341234))
	})

	Context("when Metric Sender is not initialized", func() {

		BeforeEach(func() {
			metrics.Initialize(nil, nil)
		})

		It("SendValue is a no-op", func() {