コード例 #1
0
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")
	}
}
コード例 #2
0
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")
	}
}
コード例 #3
0
ファイル: msgLoss.go プロジェクト: wfernandes/firehose-stats
func (m *MsgLossChart) ProcessEvent(evt *events.Envelope) {
	switch evt.GetCounterEvent().GetName() {
	case "DopplerForwarder.sentMessages":
		m.totalSent = update(m.sentByIP, evt)
	case "tlsListener.receivedMessageCount", "dropsondeListener.receivedMessageCount":
		m.totalReceived = update(m.receivedByIP, evt)
	}
	percent := 100 * ((m.totalSent - m.totalReceived) / m.totalSent)

	m.graph.Percent = int(percent)
}
コード例 #4
0
ファイル: msgLoss.go プロジェクト: wfernandes/firehose-stats
func update(values map[string]int64, event *events.Envelope) int64 {

	values[event.GetIp()] = int64(event.GetCounterEvent().GetTotal())

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

	return sum
}
コード例 #5
0
ファイル: msgLoss.go プロジェクト: wfernandes/firehose-stats
func (m *MsgLossChart) ForChart(event *events.Envelope) bool {
	if event.GetEventType() != events.Envelope_CounterEvent {
		return false
	}
	if !contains(event.GetOrigin(), m.validOrigins) {
		return false
	}
	if !contains(event.GetCounterEvent().GetName(), m.validMetricNames) {
		return false
	}
	return true
}
コード例 #6
0
func CounterEvent(msg *events.Envelope) Event {
	counterEvent := msg.GetCounterEvent()

	fields := logrus.Fields{
		"name":  counterEvent.GetName(),
		"delta": counterEvent.GetDelta(),
		"total": counterEvent.GetTotal(),
	}

	return Event{
		Fields: fields,
		Msg:    "",
	}
}
コード例 #7
0
func CounterEvent(msg *events.Envelope) Event {
	counterEvent := msg.GetCounterEvent()

	fields := logrus.Fields{
		"origin": msg.GetOrigin(),
		"name":   counterEvent.GetName(),
		"delta":  counterEvent.GetDelta(),
		"total":  counterEvent.GetTotal(),
	}

	return Event{
		Fields: fields,
		Msg:    "",
		Type:   msg.GetEventType().String(),
	}
}
コード例 #8
0
ファイル: sinkType.go プロジェクト: wfernandes/firehose-stats
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 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)
		}()
	}
}
コード例 #10
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
}
コード例 #11
0
func (m *MessageAggregator) handleCounter(envelope *events.Envelope) *events.Envelope {
	metrics.BatchIncrementCounter("MessageAggregator.counterEventReceived")

	countID := counterID{
		name:   envelope.GetCounterEvent().GetName(),
		origin: envelope.GetOrigin(),
	}

	newVal := m.counterTotals[countID] + envelope.GetCounterEvent().GetDelta()
	m.counterTotals[countID] = newVal

	envelope.GetCounterEvent().Total = &newVal
	return envelope
}
コード例 #12
0
				return t
			}

			tracksDroppedMessagesAnd := func(itMsg string, delta, total int) {
				It(itMsg, func() {
					var logMessageNotification *events.Envelope
					Eventually(buffer.GetOutputChannel).Should(Receive(&logMessageNotification))
					Expect(logMessageNotification.GetEventType()).To(Equal(events.Envelope_LogMessage))
					Expect(logMessageNotification.GetLogMessage().GetAppId()).To(Equal("fake-app-id"))
					Expect(logMessageNotification.GetLogMessage().GetMessage()).To(ContainSubstring(fmt.Sprintf("Log message output is too high. %d messages dropped (Total %d messages dropped) from doppler to test-sink-name.", delta, total)))

					var counterEventNotification *events.Envelope
					Eventually(buffer.GetOutputChannel).Should(Receive(&counterEventNotification))
					Expect(counterEventNotification.GetEventType()).To(Equal(events.Envelope_CounterEvent))
					counterEvent := counterEventNotification.GetCounterEvent()
					Expect(counterEvent.GetName()).To(Equal("TruncatingBuffer.DroppedMessages"))
					Expect(counterEvent.GetDelta()).To(BeEquivalentTo(delta))
					Expect(counterEvent.GetTotal()).To(BeEquivalentTo(total))

					Eventually(func() uint64 { return receiveDroppedMessages() }).Should(BeEquivalentTo(total))
				})

			}

			BeforeEach(func() {
				fakeEventEmitter = fake.NewFakeEventEmitter("doppler")
				sender := metric_sender.NewMetricSender(fakeEventEmitter)
				batcher := metricbatcher.New(sender, time.Millisecond)

				metrics.Initialize(sender, batcher)
コード例 #13
0
func expectCorrectCounterNameDeltaAndTotal(outputMessage *events.Envelope, name string, delta uint64, total uint64) {
	Expect(outputMessage.GetCounterEvent().GetName()).To(Equal(name))
	Expect(outputMessage.GetCounterEvent().GetDelta()).To(Equal(delta))
	Expect(outputMessage.GetCounterEvent().GetTotal()).To(Equal(total))
}
コード例 #14
0
					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)
					}()
				}
コード例 #15
0
ファイル: metrics.go プロジェクト: khj0651/loggregator
func (metrics *metrics) processCounterEvent(metric *events.Envelope) {
	eventName := metric.GetCounterEvent().GetName()
	count := metrics.metricsByName[eventName]
	metrics.metricsByName[eventName] = count + float64(metric.GetCounterEvent().GetDelta())
}
コード例 #16
0
				fakeEventEmitter.Reset()
			})

			tracksDroppedMessages := func(itMsg string, delta, total int) {
				It(itMsg, func() {
					var logMessageNotification *events.Envelope

					Eventually(buffer.GetOutputChannel).Should(Receive(&logMessageNotification))
					Expect(logMessageNotification.GetEventType()).To(Equal(events.Envelope_LogMessage))
					Expect(logMessageNotification.GetLogMessage().GetAppId()).To(Equal("fake-app-id"))
					Expect(logMessageNotification.GetLogMessage().GetMessage()).To(ContainSubstring(fmt.Sprintf("Log message output is too high. %d messages dropped (Total %d messages dropped) from doppler to test-sink-name.", delta, total)))

					var counterEventNotification *events.Envelope
					Eventually(buffer.GetOutputChannel).Should(Receive(&counterEventNotification))
					Expect(counterEventNotification.GetEventType()).To(Equal(events.Envelope_CounterEvent))
					counterEvent := counterEventNotification.GetCounterEvent()
					Expect(counterEvent.GetName()).To(Equal("TruncatingBuffer.DroppedMessages"))
					Expect(counterEvent.GetDelta()).To(BeEquivalentTo(delta))
					Expect(counterEvent.GetTotal()).To(BeEquivalentTo(total))
				})

				It("keeps track of dropped messages", func() {
					Eventually(fakeEventEmitter.GetMessages).Should(HaveLen(1))
					Expect(fakeEventEmitter.GetMessages()[0].Event.(*events.CounterEvent)).To(Equal(&events.CounterEvent{
						Name:  proto.String("TruncatingBuffer.totalDroppedMessages"),
						Delta: proto.Uint64(uint64(total)),
					}))
				})
			}

			Context("when the buffer fills once", func() {
コード例 #17
0
				})
			}, 2).Should(BeTrue())

			expected = events.Envelope{
				Origin:    proto.String("MetronAgent"),
				EventType: events.Envelope_CounterEvent.Enum(),
				CounterEvent: &events.CounterEvent{
					Name:  proto.String("MessageAggregator.counterEventReceived"),
					Delta: proto.Uint64(1),
					Total: proto.Uint64(3),
				},
			}

			Consistently(func() bool {
				return drainAndEval(testDoppler.MessageChan, func(env *events.Envelope) bool {
					return env.EventType == expected.EventType && env.GetCounterEvent().Name == expected.GetCounterEvent().Name
				})
			}, 2).Should(BeFalse())
		})
	})

	Describe("for Dropsonde unmarshaller", func() {
		It("counts errors", func() {
			metronInput.Write([]byte{1, 2, 3})

			expected := events.Envelope{
				Origin:    proto.String("MetronAgent"),
				EventType: events.Envelope_CounterEvent.Enum(),
				CounterEvent: &events.CounterEvent{
					Name:  proto.String("dropsondeUnmarshaller.unmarshalErrors"),
					Delta: proto.Uint64(1),
コード例 #18
0
func matchCounter(expected, actual *events.Envelope) bool {
	return expected.GetOrigin() == actual.GetOrigin() &&
		expected.GetEventType() == actual.GetEventType() &&
		expected.GetCounterEvent().GetName() == actual.GetCounterEvent().GetName() &&
		actual.GetCounterEvent().GetTotal() > 0
}