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


Golang metrics.BatchIncrementCounter函数代码示例

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


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

示例1: Start

func (udp *udpListener) Start() {
	connection, err := net.ListenPacket("udp", udp.host)
	if err != nil {
		udp.Fatalf("Failed to listen on port. %s", err)
	}

	udp.Infof("Listening on port %s", udp.host)
	udp.Lock()
	udp.connection = connection
	udp.Unlock()

	messageCountMetricName := udp.contextName + ".receivedMessageCount"
	listenerTotalMetricName := "listeners.totalReceivedMessageCount"
	receivedByteCountMetricName := udp.contextName + ".receivedByteCount"

	readBuffer := make([]byte, 65535) //buffer with size = max theoretical UDP size
	defer close(udp.dataChannel)
	for {
		readCount, senderAddr, err := connection.ReadFrom(readBuffer)
		if err != nil {
			udp.Debugf("Error while reading: %s", err)
			return
		}
		udp.Debugf("AgentListener: Read %d bytes from address %s", readCount, senderAddr)

		readData := make([]byte, readCount) //pass on buffer in size only of read data
		copy(readData, readBuffer[:readCount])

		metrics.BatchIncrementCounter(messageCountMetricName)
		metrics.BatchIncrementCounter(listenerTotalMetricName)
		metrics.BatchAddCounter(receivedByteCountMetricName, uint64(readCount))

		udp.dataChannel <- readData
	}
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:35,代码来源:udp_listener.go

示例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)
	}
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:25,代码来源:message_aggregator.go

示例3: handleConnection

func (t *TCPListener) handleConnection(conn net.Conn) {
	defer conn.Close()
	defer t.removeConnection(conn)

	if tlsConn, ok := conn.(*tls.Conn); ok {
		if err := tlsConn.Handshake(); err != nil {
			t.logger.Warnd(map[string]interface{}{
				"error":   err.Error(),
				"address": conn.RemoteAddr().String(),
			}, "TLS handshake error")
			metrics.BatchIncrementCounter(t.receiveErrorCountMetricName)
			return
		}
	}

	var (
		n     uint32
		bytes []byte
		err   error
	)

	for {
		err = binary.Read(conn, binary.LittleEndian, &n)
		if err != nil {
			if err != io.EOF {
				metrics.BatchIncrementCounter(t.receiveErrorCountMetricName)
				t.logger.Errorf("Error while decoding: %v", err)
			}
			break
		}

		read := bytes
		if cap(bytes) < int(n) {
			bytes = make([]byte, int(n))
		}
		read = bytes[:n]

		_, err = io.ReadFull(conn, read)
		if err != nil {
			metrics.BatchIncrementCounter(t.receiveErrorCountMetricName)
			t.logger.Errorf("Error during i/o read: %v", err)
			break
		}

		envelope, err := t.unmarshaller.UnmarshallMessage(read)
		if err != nil {
			continue
		}
		metrics.BatchIncrementCounter(t.listenerTotalMetricName)
		metrics.BatchIncrementCounter(t.receivedMessageCountMetricName)
		metrics.BatchAddCounter(t.receivedByteCountMetricName, uint64(n+4))

		select {
		case t.envelopeChan <- envelope:
		case <-t.stopped:
			return
		}
	}
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:59,代码来源:tcp_listener.go

示例4: CaptureRoutingRequest

func (m *MetricsReporter) CaptureRoutingRequest(b *route.Endpoint, req *http.Request) {
	dropsondeMetrics.BatchIncrementCounter("total_requests")

	componentName, ok := b.Tags["component"]
	if ok && len(componentName) > 0 {
		dropsondeMetrics.BatchIncrementCounter(fmt.Sprintf("requests.%s", componentName))
		if strings.HasPrefix(componentName, "dea-") {
			dropsondeMetrics.BatchIncrementCounter("routed_app_requests")
		}
	}
}
开发者ID:idouba,项目名称:gorouter,代码行数:11,代码来源:metrics_reporter.go

示例5: handleHTTPStop

func (m *MessageAggregator) handleHTTPStop(envelope *events.Envelope) *events.Envelope {
	if m.emitMetrics {
		metrics.BatchIncrementCounter("MessageAggregator.httpStopReceived")
	}
	atomic.AddUint64(&m.httpStopReceivedCount, 1)

	m.logger.Debugf("handling HTTP stop message %v", spew.Sprintf("%v", envelope))
	stopEvent := envelope.GetHttpStop()

	requestID := stopEvent.RequestId.String()
	event := eventID{requestID: requestID, peerType: stopEvent.GetPeerType()}

	startEventEntry, ok := m.startEventsByEventID[event]
	if !ok {
		m.logger.Warnf("no matching HTTP start message found for %v", event)
		if m.emitMetrics {
			metrics.BatchIncrementCounter("MessageAggregator.httpUnmatchedStopReceived")
		}
		atomic.AddUint64(&m.httpUnmatchedStopReceivedCount, 1)
		return nil
	}

	if m.emitMetrics {
		metrics.BatchIncrementCounter("MessageAggregator.httpStartStopEmitted")
	}
	atomic.AddUint64(&m.httpStartStopEmittedCount, 1)

	delete(m.startEventsByEventID, event)
	startEvent := startEventEntry.startEvent

	return &events.Envelope{
		Origin:    envelope.Origin,
		Timestamp: stopEvent.Timestamp,
		EventType: events.Envelope_HttpStartStop.Enum(),
		HttpStartStop: &events.HttpStartStop{
			StartTimestamp:  startEvent.Timestamp,
			StopTimestamp:   stopEvent.Timestamp,
			RequestId:       startEvent.RequestId,
			PeerType:        startEvent.PeerType,
			Method:          startEvent.Method,
			Uri:             startEvent.Uri,
			RemoteAddress:   startEvent.RemoteAddress,
			UserAgent:       startEvent.UserAgent,
			StatusCode:      stopEvent.StatusCode,
			ContentLength:   stopEvent.ContentLength,
			ParentRequestId: startEvent.ParentRequestId,
			ApplicationId:   stopEvent.ApplicationId,
			InstanceIndex:   startEvent.InstanceIndex,
			InstanceId:      startEvent.InstanceId,
		},
	}
}
开发者ID:srhrkrishna,项目名称:loggregator,代码行数:52,代码来源:message_aggregator.go

示例6: CaptureRoutingResponse

func (m *MetricsReporter) CaptureRoutingResponse(b *route.Endpoint, res *http.Response, t time.Time, d time.Duration) {
	dropsondeMetrics.BatchIncrementCounter(getResponseCounterName(res))
	dropsondeMetrics.BatchIncrementCounter("responses")

	latency := float64(d / time.Millisecond)
	unit := "ms"
	dropsondeMetrics.SendValue("latency", latency, unit)

	componentName, ok := b.Tags["component"]
	if ok && len(componentName) > 0 {
		dropsondeMetrics.SendValue(fmt.Sprintf("latency.%s", componentName), latency, unit)
	}
}
开发者ID:idouba,项目名称:gorouter,代码行数:13,代码来源:metrics_reporter.go

示例7: Write

func (d *DopplerForwarder) Write(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)

		if _, err := client.Write(signedMessage); err != nil {
			d.logger.Debugd(map[string]interface{}{
				"scheme":  client.Scheme(),
				"address": client.Address(),
			}, "Error writing legacy message")
			return
		}
	case "tls":
		err = binary.Write(client, binary.LittleEndian, uint32(len(messageBytes)))
		if err == nil {
			_, err = client.Write(messageBytes)
		}
		if err != nil {
			client.Close()

			d.logger.Errord(map[string]interface{}{
				"scheme":  client.Scheme(),
				"address": client.Address(),
				"error":   err.Error(),
			}, "DopplerForwarder: streaming error")
			return
		}
	default:
		d.logger.Errorf("DopplerForwarder: unknown protocol, %s for %s", client.Scheme(), client.Address())
		return
	}

	d.incrementMessageCount(message.GetEventType())
	metrics.BatchIncrementCounter("DopplerForwarder.sentMessages")
}
开发者ID:nagyistoce,项目名称:cloudfoundry-loggregator,代码行数:50,代码来源:doppler_forwarder.go

示例8: Write

func (w *Wrapper) Write(client Client, message []byte) error {
	sentBytes, err := client.Write(message)

	if err != nil {
		w.logger.Errorf("Error writing to %s client %v\n", w.protocol, err)
		metrics.BatchIncrementCounter(w.protocol + ".sendErrorCount")
		client.Close()
		return err
	}

	metrics.BatchAddCounter(w.protocol+".sentByteCount", uint64(sentBytes))
	metrics.BatchIncrementCounter(w.protocol + ".sentMessageCount")

	return nil
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:15,代码来源:wrapper.go

示例9: incrementMessageCount

func (m *EventMarshaller) incrementMessageCount(eventType events.Envelope_EventType) {
	incrementCount(m.messageCounts[eventType])
	modifiedEventName := []rune(eventType.String())
	modifiedEventName[0] = unicode.ToLower(modifiedEventName[0])
	metricName := string(modifiedEventName) + "Marshalled"
	metrics.BatchIncrementCounter("dropsondeMarshaller." + metricName)
}
开发者ID:rakutentech,项目名称:loggregator,代码行数:7,代码来源:event_marshaller.go

示例10: 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:
		atomic.AddUint64(&m.uncategorizedEventCount, 1)
		if m.emitMetrics {
			metrics.BatchIncrementCounter("MessageAggregator.uncategorizedEvents")
		}
		m.logger.Debugf("passing through message %v", spew.Sprintf("%v", envelope))
		m.outputWriter.Write(envelope)
	}
}
开发者ID:srhrkrishna,项目名称:loggregator,代码行数:28,代码来源:message_aggregator.go

示例11: Start

func (agentListener *agentListener) Start() {
	connection, err := net.ListenPacket("udp", agentListener.host)
	if err != nil {
		agentListener.Fatalf("Failed to listen on port. %s", err)
	}

	agentListener.Infof("Listening on port %s", agentListener.host)
	agentListener.Lock()
	agentListener.connection = connection
	agentListener.Unlock()

	readBuffer := make([]byte, 65535) //buffer with size = max theoretical UDP size
	defer close(agentListener.dataChannel)
	for {
		readCount, senderAddr, err := connection.ReadFrom(readBuffer)
		if err != nil {
			agentListener.Debugf("Error while reading. %s", err)
			return
		}
		agentListener.Debugf("AgentListener: Read %d bytes from address %s", readCount, senderAddr)

		readData := make([]byte, readCount) //pass on buffer in size only of read data
		copy(readData, readBuffer[:readCount])

		metrics.BatchIncrementCounter(agentListener.contextName + ".receivedMessageCount")
		metrics.BatchAddCounter(agentListener.contextName+".receivedByteCount", uint64(readCount))

		agentListener.dataChannel <- readData
	}

}
开发者ID:pkdevbox,项目名称:loggregatorlib,代码行数:31,代码来源:agent_listener.go

示例12: Write

func (w *Writer) Write(msgBytes []byte) (int, error) {
	w.msgBufferLock.Lock()
	defer w.msgBufferLock.Unlock()

	prefixedBytes, err := w.prefixMessage(msgBytes)
	if err != nil {
		w.logger.Errorf("Error encoding message length: %v\n", err)
		metrics.BatchIncrementCounter("tls.sendErrorCount")
		return 0, err
	}
	switch {
	case w.msgBuffer.Len()+len(prefixedBytes) > w.msgBuffer.Cap():
		_, err := w.retryWrites(prefixedBytes)
		if err != nil {
			dropped := w.msgBuffer.messages + 1
			atomic.AddUint64(&w.droppedMessages, dropped)
			metrics.BatchAddCounter("MessageBuffer.droppedMessageCount", dropped)
			w.msgBuffer.Reset()

			w.msgBuffer.writeNonMessage(w.droppedLogMessage())
			w.timer.Reset(w.flushDuration)
			return 0, err
		}
		return len(msgBytes), nil
	default:
		if w.msgBuffer.Len() == 0 {
			w.timer.Reset(w.flushDuration)
		}
		_, err := w.msgBuffer.Write(prefixedBytes)
		return len(msgBytes), err
	}
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:32,代码来源:writer.go

示例13: Start

func (nr *NetworkReader) Start() {
	connection, err := net.ListenPacket("udp4", nr.host)
	if err != nil {
		nr.logger.Fatalf("Failed to listen on port. %s", err)
	}
	nr.logger.Infof("Listening on port %s", nr.host)
	nr.lock.Lock()
	nr.connection = connection
	nr.lock.Unlock()

	readBuffer := make([]byte, 65535) //buffer with size = max theoretical UDP size
	for {
		readCount, senderAddr, err := connection.ReadFrom(readBuffer)
		if err != nil {
			nr.logger.Debugf("Error while reading. %s", err)
			return
		}
		nr.logger.Debugf("NetworkReader: Read %d bytes from address %s", readCount, senderAddr)
		readData := make([]byte, readCount) //pass on buffer in size only of read data
		copy(readData, readBuffer[:readCount])

		atomic.AddUint64(&nr.receivedMessageCount, 1)
		atomic.AddUint64(&nr.receivedByteCount, uint64(readCount))
		metrics.BatchIncrementCounter(nr.contextName + ".receivedMessageCount")
		metrics.BatchAddCounter(nr.contextName+".receivedByteCount", uint64(readCount))
		nr.writer.Write(readData)
	}
}
开发者ID:rakutentech,项目名称:loggregator,代码行数:28,代码来源:network_reader.go

示例14: Write

func (u *UDPWrapper) Write(client Client, message []byte) error {
	signedMessage := signature.SignMessage(message, u.sharedSecret)

	sentLength, err := client.Write(signedMessage)
	if err != nil {
		u.logger.Errorf("Error writing to UDP client %v\n", err)
		metrics.BatchIncrementCounter("udp.sendErrorCount")
		return err
	}
	metrics.BatchIncrementCounter("udp.sentMessageCount")
	metrics.BatchAddCounter("udp.sentByteCount", uint64(sentLength))

	// The TLS side writes this metric in the batch.Writer.  For UDP,
	// it needs to be done here.
	metrics.BatchIncrementCounter("DopplerForwarder.sentMessages")
	return nil
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:17,代码来源:udp_wrapper.go

示例15: Write

func (m *EventMarshaller) Write(envelope *events.Envelope) {
	writer := m.writer()
	if writer == nil {
		m.logger.Warn("EventMarshaller: Write called while byteWriter is nil")
		metrics.BatchIncrementCounter("dropsondeMarshaller.nilByteWriterWrites")
		return
	}

	envelopeBytes, err := proto.Marshal(envelope)
	if err != nil {
		m.logger.Errorf("marshalling error: %v", err)
		metrics.BatchIncrementCounter("dropsondeMarshaller.marshalErrors")
		return
	}

	writer.Write(envelopeBytes)
}
开发者ID:yingkitw,项目名称:loggregator,代码行数:17,代码来源:event_marshaller.go


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