當前位置: 首頁>>代碼示例>>Golang>>正文


Golang metrics.BatchAddCounter函數代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/dropsonde/metrics.BatchAddCounter函數的典型用法代碼示例。如果您正苦於以下問題:Golang BatchAddCounter函數的具體用法?Golang BatchAddCounter怎麽用?Golang BatchAddCounter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BatchAddCounter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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")
}
開發者ID:hpcloud,項目名稱:loggregator-1,代碼行數:59,代碼來源:doppler_forwarder.go

示例2: 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

示例3: AddToCounter

func (fms *FakeMetricSender) AddToCounter(name string, delta uint64) error {
	metrics.BatchAddCounter("bogus-counter", 1)
	if name == "count1" {
		close(*fms.done)
	}
	return nil
}
開發者ID:fraenkel,項目名稱:dropsonde,代碼行數:7,代碼來源:deadlock_test.go

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: notifyMessagesDropped

func (r *TruncatingBuffer) notifyMessagesDropped(outputChannel chan *events.Envelope, deltaDropped, totalDropped uint64, appId string) {
	metrics.BatchAddCounter("TruncatingBuffer.totalDroppedMessages", deltaDropped)
	if r.eventAllowed(events.Envelope_LogMessage) {
		r.emitMessage(outputChannel, generateLogMessage(deltaDropped, totalDropped, appId, r.context.Origin(), r.context.Destination()))
	}
	if r.eventAllowed(events.Envelope_CounterEvent) {
		r.emitMessage(outputChannel, generateCounterEvent(deltaDropped, totalDropped))
	}
}
開發者ID:kei-yamazaki,項目名稱:loggregator,代碼行數:9,代碼來源:truncating_buffer.go

示例9: NewSinkManagerMetrics

func NewSinkManagerMetrics(sinkDropUpdateChannel <-chan int64) *SinkManagerMetrics {
	m := SinkManagerMetrics{
		sinkDropUpdateChannel: sinkDropUpdateChannel,
	}

	go func() {
		for delta := range m.sinkDropUpdateChannel {
			metrics.BatchAddCounter("messageRouter.totalDroppedMessages", uint64(delta))
		}
	}()

	return &m
}
開發者ID:khj0651,項目名稱:loggregator,代碼行數:13,代碼來源:sink_manager_metrics.go

示例10: 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

示例11: Write

func (w *Wrapper) Write(client Client, message []byte, chainers ...metricbatcher.BatchCounterChainer) 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))
	for _, chainer := range chainers {
		chainer.SetTag("protocol", w.protocol).Increment()
	}

	return nil
}
開發者ID:kei-yamazaki,項目名稱:loggregator,代碼行數:17,代碼來源:wrapper.go

示例12: 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

示例13: handleConnection

func (t *TLSListener) handleConnection(conn net.Conn) {
	var n uint32
	var bytes []byte
	var err error

	for {
		err = binary.Read(conn, binary.LittleEndian, &n)
		if err != nil {
			break
		}

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

		_, err = io.ReadFull(conn, read)
		if err != nil {
			break
		}

		envelope, err := t.unmarshaller.UnmarshallMessage(read)
		if err != nil {
			continue
		}

		metrics.BatchIncrementCounter(t.messageCountMetricName)
		metrics.BatchAddCounter(t.receivedByteCountMetricName, uint64(n+4))

		t.logger.Debugf("Received envelope: %#v", envelope)
		select {
		case t.envelopeChan <- envelope:
		case <-t.stopped:
			return
		}
	}

	t.logger.Debugf("Error while decoding: %v", err)
	conn.Close()
	t.removeConnection(conn)
}
開發者ID:nagyistoce,項目名稱:cloudfoundry-loggregator,代碼行數:42,代碼來源:tls_listener.go

示例14: Start

func (nr *NetworkReader) Start() {
	receivedMessageCountName := nr.contextName + ".receivedMessageCount"
	receivedByteCountName := nr.contextName + ".receivedByteCount"

	readBuffer := make([]byte, 65535) //buffer with size = max theoretical UDP size
	for {
		readCount, senderAddr, err := nr.connection.ReadFrom(readBuffer)
		if err != nil {
			nr.logger.Errorf("Error while reading. %s", err)
			return
		}
		logging.Debugf(nr.logger, "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])

		metrics.BatchIncrementCounter(receivedMessageCountName)
		metrics.BatchAddCounter(receivedByteCountName, uint64(readCount))
		nr.writer.Write(readData)
	}
}
開發者ID:sunatthegilddotcom,項目名稱:loggregator,代碼行數:20,代碼來源:network_reader.go

示例15: flushWrite

func (w *Writer) flushWrite(bytes []byte) (int, error) {
	w.writerLock.Lock()
	defer w.writerLock.Unlock()

	toWrite := make([]byte, 0, w.msgBuffer.Len()+len(bytes))
	toWrite = append(toWrite, w.msgBuffer.Bytes()...)
	toWrite = append(toWrite, bytes...)

	bufferMessageCount := w.msgBuffer.messages
	if len(bytes) > 0 {
		bufferMessageCount++
	}
	sent, err := w.outWriter.Write(toWrite)
	if err != nil {
		w.logger.Warnf("Received error while trying to flush TCP bytes: %s", err)
		return 0, err
	}

	metrics.BatchAddCounter("DopplerForwarder.sentMessages", bufferMessageCount)
	atomic.StoreUint64(&w.droppedMessages, 0)
	w.msgBuffer.Reset()
	return sent, nil
}
開發者ID:yingkitw,項目名稱:loggregator,代碼行數:23,代碼來源:writer.go


注:本文中的github.com/cloudfoundry/dropsonde/metrics.BatchAddCounter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。