本文整理匯總了Golang中github.com/cloudfoundry/sonde-go/events.Envelope.GetEventType方法的典型用法代碼示例。如果您正苦於以下問題:Golang Envelope.GetEventType方法的具體用法?Golang Envelope.GetEventType怎麽用?Golang Envelope.GetEventType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/sonde-go/events.Envelope
的用法示例。
在下文中一共展示了Envelope.GetEventType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Write
func (m *MessageAggregator) Write(envelope *events.Envelope) {
// TODO: don't call for every message if throughput becomes a problem
m.cleanupOrphanedHTTPStart()
if envelope.EventType == nil {
m.outputWriter.Write(envelope)
return
}
switch envelope.GetEventType() {
case events.Envelope_HttpStart:
m.handleHTTPStart(envelope)
case events.Envelope_HttpStop:
startStopMessage := m.handleHTTPStop(envelope)
if startStopMessage != nil {
m.outputWriter.Write(startStopMessage)
}
case events.Envelope_CounterEvent:
counterEventMessage := m.handleCounter(envelope)
m.outputWriter.Write(counterEventMessage)
default:
m.incrementCounter(&m.uncategorizedEventCount)
m.logger.Debugf("passing through message %v", spew.Sprintf("%v", envelope))
m.outputWriter.Write(envelope)
}
}
示例2: Write
func (m *MessageAggregator) Write(envelope *events.Envelope) {
// TODO: don't call for every message if throughput becomes a problem
m.cleanupOrphanedHTTPStart()
if envelope.EventType == nil {
metrics.BatchIncrementCounter("MessageAggregator.uncategorizedEvents")
return
}
switch envelope.GetEventType() {
case events.Envelope_HttpStart:
m.handleHTTPStart(envelope)
case events.Envelope_HttpStop:
startStopMessage := m.handleHTTPStop(envelope)
if startStopMessage != nil {
m.outputWriter.Write(startStopMessage)
}
case events.Envelope_CounterEvent:
counterEventMessage := m.handleCounter(envelope)
m.outputWriter.Write(counterEventMessage)
default:
metrics.BatchIncrementCounter("MessageAggregator.uncategorizedEvents")
m.outputWriter.Write(envelope)
}
}
示例3: HttpStartStop
func HttpStartStop(msg *events.Envelope) Event {
httpStartStop := msg.GetHttpStartStop()
fields := logrus.Fields{
"origin": msg.GetOrigin(),
"cf_app_id": httpStartStop.GetApplicationId(),
"content_length": httpStartStop.GetContentLength(),
"instance_id": httpStartStop.GetInstanceId(),
"instance_index": httpStartStop.GetInstanceIndex(),
"method": httpStartStop.GetMethod(),
"parent_request_id": httpStartStop.GetParentRequestId(),
"peer_type": httpStartStop.GetPeerType(),
"remote_addr": httpStartStop.GetRemoteAddress(),
"request_id": httpStartStop.GetRequestId(),
"start_timestamp": httpStartStop.GetStartTimestamp(),
"status_code": httpStartStop.GetStatusCode(),
"stop_timestamp": httpStartStop.GetStopTimestamp(),
"uri": httpStartStop.GetUri(),
"user_agent": httpStartStop.GetUserAgent(),
"duration_ms": (((httpStartStop.GetStopTimestamp() - httpStartStop.GetStartTimestamp()) / 1000) / 1000),
}
return Event{
Fields: fields,
Msg: "",
Type: msg.GetEventType().String(),
}
}
示例4: dopplerReceivedMessageCount
func dopplerReceivedMessageCount(msg *events.Envelope) bool {
return msg.GetEventType() == events.Envelope_CounterEvent &&
(msg.CounterEvent.GetName() == "udpListener.receivedMessageCount" ||
msg.CounterEvent.GetName() == "tcpListener.receivedMessageCount" ||
msg.CounterEvent.GetName() == "tlsListener.receivedMessageCount") &&
msg.GetOrigin() == "DopplerServer"
}
示例5: processEnvelope
func (l *logCounter) processEnvelope(env *events.Envelope) {
if env.GetEventType() != events.Envelope_LogMessage {
return
}
logMsg := env.GetLogMessage()
msg := string(logMsg.GetMessage())
if strings.HasPrefix(msg, "mismatched prefix") {
return
}
if !strings.HasPrefix(msg, l.cfg.MessagePrefix) {
fmt.Printf("mismatched prefix: log message %s did not match prefix: %s\n", string(logMsg.GetMessage()), string(l.cfg.MessagePrefix))
return
}
if len(msg) < sepEnd {
fmt.Printf("Cannot parse message %s\n", msg)
return
}
id := Identity{
appID: logMsg.GetAppId(),
runID: msg[prefixEnd:guidEnd],
}
l.counterLock.Lock()
defer l.counterLock.Unlock()
counter, ok := l.counters[id]
if !ok {
counter = make(map[string]bool)
l.counters[id] = counter
}
counter[msg[sepEnd:]] = true
}
示例6: TranslateDropsondeToLegacyLogMessage
func TranslateDropsondeToLegacyLogMessage(message []byte) ([]byte, error) {
var receivedEnvelope events.Envelope
err := proto.Unmarshal(message, &receivedEnvelope)
if err != nil {
return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Unable to unmarshal bytes as Envelope: %v", err)
}
if receivedEnvelope.GetEventType() != events.Envelope_LogMessage {
return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Envelope contained %s instead of LogMessage", receivedEnvelope.GetEventType().String())
}
logMessage := receivedEnvelope.GetLogMessage()
if logMessage == nil {
return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Envelope's LogMessage was nil: %v", receivedEnvelope)
}
messageBytes, err := proto.Marshal(
&logmessage.LogMessage{
Message: logMessage.GetMessage(),
MessageType: (*logmessage.LogMessage_MessageType)(logMessage.MessageType),
Timestamp: proto.Int64(logMessage.GetTimestamp()),
AppId: proto.String(logMessage.GetAppId()),
SourceId: proto.String(logMessage.GetSourceInstance()),
SourceName: proto.String(logMessage.GetSourceType()),
},
)
if err != nil {
return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Failed marshalling converted dropsonde message: %v", err)
}
return messageBytes, nil
}
示例7: routeEvent
func routeEvent(msg *events.Envelope, extraFields map[string]string) {
eventType := msg.GetEventType()
if selectedEvents[eventType.String()] {
var event Event
switch eventType {
case events.Envelope_HttpStart:
event = HttpStart(msg)
case events.Envelope_HttpStop:
event = HttpStop(msg)
case events.Envelope_HttpStartStop:
event = HttpStartStop(msg)
case events.Envelope_LogMessage:
event = LogMessage(msg)
case events.Envelope_ValueMetric:
event = ValueMetric(msg)
case events.Envelope_CounterEvent:
event = CounterEvent(msg)
case events.Envelope_Error:
event = ErrorEvent(msg)
case events.Envelope_ContainerMetric:
event = ContainerMetric(msg)
}
event.AnnotateWithAppData()
event.AnnotateWithMetaData(extraFields)
event.ShipEvent()
mutex.Lock()
selectedEventsCount[eventType.String()]++
mutex.Unlock()
}
}
示例8: listenForLogs
func listenForLogs() {
for {
buffer := make([]byte, 1024)
n, _, err := udpConn.ReadFrom(buffer)
if err != nil {
return
}
if n == 0 {
panic("Received empty packet")
}
envelope := new(events.Envelope)
err = proto.Unmarshal(buffer[0:n], envelope)
if err != nil {
panic(err)
}
if envelope.GetEventType() == events.Envelope_LogMessage {
logLock.Lock()
logMessages = append(logMessages, envelope.GetLogMessage())
logLock.Unlock()
}
}
}
示例9: networkWrite
func (d *DopplerForwarder) networkWrite(message *events.Envelope) {
client, err := d.clientPool.RandomClient()
if err != nil {
d.logger.Errord(map[string]interface{}{
"error": err.Error(),
}, "DopplerForwarder: can't forward message")
return
}
messageBytes, err := proto.Marshal(message)
if err != nil {
d.logger.Errorf("DopplerForwarder: marshal error %v", err)
metrics.BatchIncrementCounter("dropsondeMarshaller.marshalErrors")
return
}
switch client.Scheme() {
case "udp":
signedMessage := signature.SignMessage(messageBytes, d.sharedSecret)
bytesWritten, err := client.Write(signedMessage)
if err != nil {
metrics.BatchIncrementCounter("udp.sendErrorCount")
d.logger.Debugd(map[string]interface{}{
"scheme": client.Scheme(),
"address": client.Address(),
}, "Error writing legacy message")
return
}
metrics.BatchIncrementCounter("udp.sentMessageCount")
metrics.BatchAddCounter("udp.sentByteCount", uint64(bytesWritten))
case "tls":
var bytesWritten int
err = binary.Write(client, binary.LittleEndian, uint32(len(messageBytes)))
if err == nil {
bytesWritten, err = client.Write(messageBytes)
}
if err != nil {
metrics.BatchIncrementCounter("tls.retryCount")
d.inputChan <- message
client.Close()
d.logger.Errord(map[string]interface{}{
"scheme": client.Scheme(),
"address": client.Address(),
"error": err.Error(),
}, "DopplerForwarder: streaming error")
return
}
metrics.BatchIncrementCounter("tls.sentMessageCount")
metrics.BatchAddCounter("tls.sentByteCount", uint64(bytesWritten+4))
default:
d.logger.Errorf("DopplerForwarder: unknown protocol, %s for %s", client.Scheme(), client.Address())
return
}
d.incrementMessageCount(message.GetEventType())
metrics.BatchIncrementCounter("DopplerForwarder.sentMessages")
}
示例10: getValue
func getValue(envelope *events.Envelope) float64 {
switch envelope.GetEventType() {
case events.Envelope_ValueMetric:
return envelope.GetValueMetric().GetValue()
case events.Envelope_CounterEvent:
return float64(envelope.GetCounterEvent().GetTotal())
default:
panic("Unknown event type")
}
}
示例11: getName
func getName(envelope *events.Envelope) string {
switch envelope.GetEventType() {
case events.Envelope_ValueMetric:
return envelope.GetOrigin() + "." + envelope.GetValueMetric().GetName()
case events.Envelope_CounterEvent:
return envelope.GetOrigin() + "." + envelope.GetCounterEvent().GetName()
default:
panic("Unknown event type")
}
}
示例12: processMetric
func (metrics *metrics) processMetric(metric *events.Envelope) {
switch metric.GetEventType() {
case events.Envelope_ValueMetric:
metrics.processValueMetric(metric)
case events.Envelope_CounterEvent:
metrics.processCounterEvent(metric)
case events.Envelope_HttpStartStop:
metrics.processHTTPStartStop(metric)
}
}
示例13: AnnotateWithEnveloppeData
func (e *Event) AnnotateWithEnveloppeData(msg *events.Envelope) {
e.Fields["origin"] = msg.GetOrigin()
e.Fields["deployment"] = msg.GetDeployment()
e.Fields["ip"] = msg.GetIp()
e.Fields["job"] = msg.GetJob()
e.Fields["index"] = msg.GetIndex()
//e.Fields["tags"] = msg.GetTags()
e.Type = msg.GetEventType().String()
}
示例14: checkValueMetric
func checkValueMetric(receivedEnvelope *events.Envelope, origin string, name string, value float64, unit string) {
Expect(receivedEnvelope.GetEventType()).To(Equal(events.Envelope_ValueMetric))
Expect(receivedEnvelope.GetOrigin()).To(Equal(origin))
vm := receivedEnvelope.GetValueMetric()
Expect(vm.GetName()).To(Equal(name))
Expect(vm.GetValue()).To(BeNumerically("==", value))
Expect(vm.GetUnit()).To(Equal(unit))
}
示例15: Write
func (f *fakeWriter) Write(message *events.Envelope) {
if message.GetEventType() == events.Envelope_ValueMetric {
switch message.GetValueMetric().GetName() {
case "Uptime":
atomic.StoreUint64(&f.lastUptime, uint64(message.GetValueMetric().GetValue()))
case "LinuxFileDescriptor":
atomic.StoreUint64(&f.openFileDescriptors, uint64(message.GetValueMetric().GetValue()))
}
}
}