当前位置: 首页>>代码示例>>Golang>>正文


Golang factories.NewContainerMetric函数代码示例

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


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

示例1: createEnvelope

func createEnvelope(eventType events.Envelope_EventType) *events.Envelope {
	envelope := &events.Envelope{Origin: proto.String("origin"), EventType: &eventType, Timestamp: proto.Int64(time.Now().UnixNano())}

	switch eventType {
	case events.Envelope_HttpStartStop:
		req, _ := http.NewRequest("GET", "http://www.example.com", nil)
		req.RemoteAddr = "www.example.com"
		req.Header.Add("User-Agent", "user-agent")
		uuid, _ := uuid.NewV4()
		envelope.HttpStartStop = factories.NewHttpStartStop(req, http.StatusOK, 128, events.PeerType_Client, uuid)
	case events.Envelope_ValueMetric:
		envelope.ValueMetric = factories.NewValueMetric("some-value-metric", 123, "km")
	case events.Envelope_CounterEvent:
		envelope.CounterEvent = factories.NewCounterEvent("some-counter-event", 123)
	case events.Envelope_LogMessage:
		envelope.LogMessage = factories.NewLogMessage(events.LogMessage_OUT, "some message", "appId", "source")
	case events.Envelope_ContainerMetric:
		envelope.ContainerMetric = factories.NewContainerMetric("appID", 123, 1, 5, 5)
	case events.Envelope_Error:
		envelope.Error = factories.NewError("source", 123, "message")
	default:
		panic(fmt.Sprintf("Unknown event %v\n", eventType))
	}

	return envelope
}
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:26,代码来源:tcp_listener_test.go

示例2:

	})

	It("dumps buffer data to the websocket client with /recentlogs", func(done Done) {
		lm, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, "my message", appId, "App"), "origin")
		sinkManager.SendTo(appId, lm)

		AddWSSink(wsReceivedChan, fmt.Sprintf("ws://%s/apps/%s/recentlogs", apiEndpoint, appId))

		rlm, err := receiveEnvelope(wsReceivedChan)
		Expect(err).NotTo(HaveOccurred())
		Expect(rlm.GetLogMessage().GetMessage()).To(Equal(lm.GetLogMessage().GetMessage()))
		close(done)
	})

	It("dumps container metric data to the websocket client with /containermetrics", func(done Done) {
		cm := factories.NewContainerMetric(appId, 0, 42.42, 1234, 123412341234)
		envelope, _ := emitter.Wrap(cm, "origin")
		sinkManager.SendTo(appId, envelope)

		AddWSSink(wsReceivedChan, fmt.Sprintf("ws://%s/apps/%s/containermetrics", apiEndpoint, appId))

		rcm, err := receiveEnvelope(wsReceivedChan)
		Expect(err).NotTo(HaveOccurred())
		Expect(rcm.GetContainerMetric()).To(Equal(cm))
		close(done)
	})

	It("sends data to the websocket client with /stream", func(done Done) {
		stopKeepAlive, _ := AddWSSink(wsReceivedChan, fmt.Sprintf("ws://%s/apps/%s/stream", apiEndpoint, appId))
		lm, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, "my message", appId, "App"), "origin")
		sinkManager.SendTo(appId, lm)
开发者ID:JimmyMa,项目名称:loggregator,代码行数:31,代码来源:websocket_server_test.go

示例3:

				},
			}

			message, err := proto.Marshal(logMessage)
			Expect(err).ToNot(HaveOccurred())
			_, err = unmarshaller.UnmarshallMessage(message)
			Expect(err).ToNot(HaveOccurred())
			Eventually(func() uint64 { return fakeSender.GetCounter("dropsondeUnmarshaller.logMessageTotal") }).Should(BeEquivalentTo(1))
		})

		Describe("emits counters for", func() {
			It("container metrics", func() {
				containerMetric := &events.Envelope{
					Origin:          proto.String("origin"),
					EventType:       events.Envelope_ContainerMetric.Enum(),
					ContainerMetric: factories.NewContainerMetric("appId", 0, 3.0, 23, 23),
				}
				message, err := proto.Marshal(containerMetric)
				Expect(err).ToNot(HaveOccurred())
				_, err = unmarshaller.UnmarshallMessage(message)
				Expect(err).ToNot(HaveOccurred())
				Eventually(func() uint64 { return fakeSender.GetCounter("dropsondeUnmarshaller.containerMetricReceived") }).Should(BeEquivalentTo(1))

			})

			It("HTTP start event", func() {
				uuid, _ := uuid.NewV4()
				request, _ := http.NewRequest("GET", "https://example.com", nil)
				httpStart := &events.Envelope{
					Origin:    proto.String("origin"),
					EventType: events.Envelope_HttpStart.Enum(),
开发者ID:Jonty,项目名称:loggregator,代码行数:31,代码来源:event_unmarshaller_test.go

示例4:

	. "integration_tests/doppler/helpers"

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

var _ = Describe("Container Metrics", func() {
	var receivedChan chan []byte
	var inputConnection net.Conn
	var appID string

	itDoesContainerMetrics := func(send func(events.Event, net.Conn) error) {
		It("returns container metrics for an app", func() {
			containerMetric := factories.NewContainerMetric(appID, 0, 1, 2, 3)

			send(containerMetric, inputConnection)

			Eventually(dopplerSession).Should(gbytes.Say(`Done sending`))

			receivedChan = make(chan []byte)
			ws, _ := AddWSSink(receivedChan, "4567", "/apps/"+appID+"/containermetrics")
			defer ws.Close()

			var receivedMessageBytes []byte
			Eventually(receivedChan).Should(Receive(&receivedMessageBytes))

			receivedEnvelope := UnmarshalMessage(receivedMessageBytes)

			Expect(receivedEnvelope.GetEventType()).To(Equal(events.Envelope_ContainerMetric))
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:30,代码来源:container_metrics_test.go

示例5:

		Expect(err).NotTo(HaveOccurred())

		err = SendAppLog("otherAppId", "message 2", inputConnection)
		Expect(err).NotTo(HaveOccurred())

		receivedMessageBytes := []byte{}
		Eventually(receivedChan).Should(Receive(&receivedMessageBytes))
		receivedMessage := DecodeProtoBufLogMessage(receivedMessageBytes)

		Expect(receivedMessage.GetAppId()).To(Equal(appID))
		Expect(string(receivedMessage.GetMessage())).To(Equal("message 1"))
		Expect(receivedChan).To(BeEmpty())
	})

	It("does not recieve non-log messages", func() {
		metricEvent := factories.NewContainerMetric(appID, 0, 10, 10, 10)
		SendEvent(metricEvent, inputConnection)

		Expect(receivedChan).To(BeEmpty())
	})

	It("drops invalid log envelopes", func() {
		unmarshalledLogMessage := factories.NewLogMessage(events.LogMessage_OUT, "Some Data", appID, "App")
		expectedMessage := MarshalEvent(unmarshalledLogMessage, "invalid")

		_, err := inputConnection.Write(expectedMessage)
		Expect(err).To(BeNil())
		Expect(receivedChan).To(BeEmpty())
	})
})
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:30,代码来源:websocket_streaming_log_test.go

示例6:

					case <-done:
						return
					}
				}
			}()

			var receivedMessageBytes []byte
			Eventually(receiveChan).Should(Receive(&receivedMessageBytes))
			close(done)

			Expect(DecodeProtoBufEnvelope(receivedMessageBytes).GetEventType()).To(Equal(events.Envelope_LogMessage))
		})

		It("receives container metrics", func() {
			done := make(chan struct{})
			containerMetric := factories.NewContainerMetric(appID, 0, 10, 2, 3)
			go func() {
				for {
					SendEvent(containerMetric, inputConnection)
					select {
					case <-time.After(500 * time.Millisecond):
					case <-done:
						return
					}
				}
			}()

			var receivedMessageBytes []byte
			Eventually(receiveChan).Should(Receive(&receivedMessageBytes))
			close(done)
			Expect(DecodeProtoBufEnvelope(receivedMessageBytes).GetEventType()).To(Equal(events.Envelope_ContainerMetric))
开发者ID:lyuyun,项目名称:loggregator,代码行数:31,代码来源:firehose_test.go

示例7:

				AppId:       proto.String("app-id"),
				MessageType: events.LogMessage_OUT.Enum(),
				SourceType:  proto.String("App"),
			}

			logEvent := factories.NewLogMessage(events.LogMessage_OUT, "hello", "app-id", "App")

			Expect(logEvent.GetTimestamp()).ToNot(BeZero())
			logEvent.Timestamp = nil

			Expect(logEvent).To(Equal(expectedLogEvent))
		})
	})

	Describe("NewContainerMetric", func() {
		It("should set the appropriate fields", func() {
			expectedContainerMetric := &events.ContainerMetric{
				ApplicationId: proto.String("some_app_id"),
				InstanceIndex: proto.Int32(7),
				CpuPercentage: proto.Float64(42.24),
				MemoryBytes:   proto.Uint64(1234),
				DiskBytes:     proto.Uint64(13231231),
			}

			containerMetric := factories.NewContainerMetric("some_app_id", 7, 42.24, 1234, 13231231)

			Expect(containerMetric).To(Equal(expectedContainerMetric))
		})
	})
})
开发者ID:jungle0755,项目名称:gorouter,代码行数:30,代码来源:factories_test.go

示例8:

	It("returns correct path for firehose", func() {
		dopplerEndpoint := doppler_endpoint.NewDopplerEndpoint("firehose", "subscription-123", true)
		Expect(dopplerEndpoint.GetPath()).To(Equal("/firehose/subscription-123"))
	})

	It("returns correct path for recentlogs", func() {
		dopplerEndpoint := doppler_endpoint.NewDopplerEndpoint("recentlogs", "abc123", true)
		Expect(dopplerEndpoint.GetPath()).To(Equal("/apps/abc123/recentlogs"))
	})
})

var _ = Describe("ContainerMetricsHandler", func() {
	It("removes duplicate app container metrics", func() {
		messagesChan := make(chan []byte, 2)

		env1, _ := emitter.Wrap(factories.NewContainerMetric("1", 1, 123, 123, 123), "origin")
		env1.Timestamp = proto.Int64(10000)

		env2, _ := emitter.Wrap(factories.NewContainerMetric("1", 1, 123, 123, 123), "origin")
		env2.Timestamp = proto.Int64(20000)

		bytes1, _ := proto.Marshal(env1)
		bytes2, _ := proto.Marshal(env2)

		messagesChan <- bytes2
		messagesChan <- bytes1
		close(messagesChan)

		outputChan := doppler_endpoint.DeDupe(messagesChan)

		Expect(outputChan).To(HaveLen(1))
开发者ID:lyuyun,项目名称:loggregator,代码行数:31,代码来源:doppler_endpoint_test.go


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