func GetAppId(envelope *events.Envelope) string { if envelope.GetEventType() == events.Envelope_LogMessage { return envelope.GetLogMessage().GetAppId() } if envelope.GetEventType() == events.Envelope_ContainerMetric { return envelope.GetContainerMetric().GetApplicationId() } var event hasAppId switch envelope.GetEventType() { case events.Envelope_HttpStart: event = envelope.GetHttpStart() case events.Envelope_HttpStop: event = envelope.GetHttpStop() case events.Envelope_HttpStartStop: event = envelope.GetHttpStartStop() default: return SystemAppId } uuid := event.GetApplicationId() if uuid != nil { return formatUUID(uuid) } return SystemAppId }
func (sink *ContainerMetricSink) updateMetric(event *events.Envelope) { sink.lock.Lock() defer sink.lock.Unlock() instance := event.GetContainerMetric().GetInstanceIndex() oldMetric, ok := sink.metrics[instance] if !ok || oldMetric.GetTimestamp() < event.GetTimestamp() { sink.metrics[instance] = event } }
func ContainerMetric(msg *events.Envelope) Event { containerMetric := msg.GetContainerMetric() fields := logrus.Fields{ "cf_app_id": containerMetric.GetApplicationId(), "cpu_percentage": containerMetric.GetCpuPercentage(), "disk_bytes": containerMetric.GetDiskBytes(), "instance_index": containerMetric.GetInstanceIndex(), "memory_bytes": containerMetric.GetMemoryBytes(), } return Event{ Fields: fields, Msg: "", } }
func valid(env *events.Envelope) bool { switch env.GetEventType() { case events.Envelope_HttpStartStop: return env.GetHttpStartStop() != nil case events.Envelope_LogMessage: return env.GetLogMessage() != nil case events.Envelope_ValueMetric: return env.GetValueMetric() != nil case events.Envelope_CounterEvent: return env.GetCounterEvent() != nil case events.Envelope_Error: return env.GetError() != nil case events.Envelope_ContainerMetric: return env.GetContainerMetric() != nil } return true }
func DeDupe(input <-chan []byte) <-chan []byte { messages := make(map[int32]*events.Envelope) for message := range input { var envelope events.Envelope proto.Unmarshal(message, &envelope) cm := envelope.GetContainerMetric() oldEnvelope, ok := messages[cm.GetInstanceIndex()] if !ok || oldEnvelope.GetTimestamp() < envelope.GetTimestamp() { messages[cm.GetInstanceIndex()] = &envelope } } output := make(chan []byte, len(messages)) for _, envelope := range messages { bytes, _ := proto.Marshal(envelope) output <- bytes } close(output) return output }