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")
	}
}
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")
	}
}
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))

}
예제 #4
0
func (s *UAAChart) ProcessEvent(event *events.Envelope) {
	switch event.GetValueMetric().GetName() {
	case "audit_service.user_authentication_count":
		s.data[0] = updateAndReturnValue(s.dataByIp[0], event)
	case "audit_service.user_authentication_failure_count":
		s.data[1] = updateAndReturnValue(s.dataByIp[1], event)
	case "audit_service.principal_authentication_failure_count":
		s.data[2] = updateAndReturnValue(s.dataByIp[2], event)
	case "audit_service.user_password_failures":
		s.data[3] = updateAndReturnValue(s.dataByIp[3], event)
	}
}
예제 #5
0
func (s *SinkTypeChart) ProcessEvent(event *events.Envelope) {
	switch event.GetValueMetric().GetName() {
	case "messageRouter.numberOfContainerMetricSinks":
		s.data[0] = updateAndReturnValue(s.dataByIp[0], event)
	case "messageRouter.numberOfSyslogSinks":
		s.data[1] = updateAndReturnValue(s.dataByIp[1], event)
	case "messageRouter.numberOfDumpSinks":
		s.data[2] = updateAndReturnValue(s.dataByIp[2], event)
	case "messageRouter.numberOfWebsocketSinks":
		s.data[3] = updateAndReturnValue(s.dataByIp[3], event)
	case "messageRouter.numberOfFirehoseSinks":
		s.data[4] = updateAndReturnValue(s.dataByIp[4], event)
	}
}
예제 #6
0
func (s *SinkTypeChart) ForChart(event *events.Envelope) bool {
	if event.GetEventType() != events.Envelope_ValueMetric {
		return false
	}
	if !contains(event.GetOrigin(), s.validOrigins) {
		return false
	}
	if !contains(event.GetValueMetric().GetName(), s.validMetricNames) {
		return false
	}

	//	s.cfUI.Say("%f ", event.GetValueMetric().GetValue())
	return true
}
예제 #7
0
func ValueMetric(msg *events.Envelope) Event {
	valMetric := msg.GetValueMetric()

	fields := logrus.Fields{
		"name":  valMetric.GetName(),
		"unit":  valMetric.GetUnit(),
		"value": valMetric.GetValue(),
	}

	return Event{
		Fields: fields,
		Msg:    "",
	}
}
예제 #8
0
func updateAndReturnValue(values map[string]int, event *events.Envelope) int {

	switch event.GetEventType() {
	case events.Envelope_CounterEvent:
		values[event.GetIp()] = int(event.GetCounterEvent().GetTotal())
	case events.Envelope_ValueMetric:
		values[event.GetIp()] = int(event.GetValueMetric().GetValue())
	}

	sum := 0
	for _, v := range values {
		sum += v
	}

	return sum
}
예제 #9
0
func ValueMetric(msg *events.Envelope) Event {
	valMetric := msg.GetValueMetric()

	fields := logrus.Fields{
		"origin": msg.GetOrigin(),
		"name":   valMetric.GetName(),
		"unit":   valMetric.GetUnit(),
		"value":  valMetric.GetValue(),
	}

	return Event{
		Fields: fields,
		Msg:    "",
		Type:   msg.GetEventType().String(),
	}
}
func listenForEvents(origin []string) {
	for {
		buffer := make([]byte, 1024)
		n, _, err := udpListener.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)
		}

		var eventId = envelope.GetEventType().String()

		tracker := eventTracker{eventType: eventId}

		switch envelope.GetEventType() {
		case events.Envelope_HttpStart:
			tracker.name = envelope.GetHttpStart().GetPeerType().String()
		case events.Envelope_HttpStop:
			tracker.name = envelope.GetHttpStop().GetPeerType().String()
		case events.Envelope_ValueMetric:
			tracker.name = envelope.GetValueMetric().GetName()
		case events.Envelope_CounterEvent:
			tracker.name = envelope.GetCounterEvent().GetName()
		default:
			panic("Unexpected message type")

		}

		if envelope.GetOrigin() != strings.Join(origin, "/") {
			panic("origin not as expected")
		}

		func() {
			lock.Lock()
			defer lock.Unlock()
			receivedEvents = append(receivedEvents, tracker)
		}()
	}
}
예제 #11
0
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
}
예제 #12
0
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()))
		}
	}
}
예제 #13
0
func (f *fakeWriter) Write(message *events.Envelope) {
	if message.GetEventType() == events.Envelope_ValueMetric && message.GetValueMetric().GetName() == "Uptime" {
		atomic.StoreUint64(&f.lastUptime, uint64(message.GetValueMetric().GetValue()))
	}
}
예제 #14
0
func (metrics *metrics) processValueMetric(metric *events.Envelope) {
	metrics.metricsByName[metric.GetValueMetric().GetName()] = metric.GetValueMetric().GetValue()
}
						panic(err)
					}

					var eventId = envelope.GetEventType().String()

					tracker := eventTracker{eventType: eventId}

					switch envelope.GetEventType() {
					case events.Envelope_HttpStart:
						tracker.name = envelope.GetHttpStart().GetPeerType().String()
					case events.Envelope_HttpStop:
						tracker.name = envelope.GetHttpStop().GetPeerType().String()
					case events.Envelope_Heartbeat:
						tracker.name = envelope.GetHeartbeat().GetControlMessageIdentifier().String()
					case events.Envelope_ValueMetric:
						tracker.name = envelope.GetValueMetric().GetName()
					case events.Envelope_CounterEvent:
						tracker.name = envelope.GetCounterEvent().GetName()
					default:
						panic("Unexpected message type")

					}

					if envelope.GetOrigin() != strings.Join(origin, "/") {
						panic("origin not as expected")
					}

					func() {
						lock.Lock()
						defer lock.Unlock()
						receivedEvents = append(receivedEvents, tracker)