Example #1
0
func (m *MetricsClient) print() {
	var bf = &bytes.Buffer{}
	shot := map[string]interface{}{
		"endpoint": m.endpoint,
		"service":  m.serviceName,
		"data":     m.r,
	}
	json.NewEncoder(bf).Encode(shot)
	log.Info("[metrics] " + bf.String())
}
Example #2
0
func (m *MetricsClient) report() {
	var bf = &bytes.Buffer{}
	shot := map[string]interface{}{
		"endpoint": m.endpoint,
		"service":  m.serviceName,
		"data":     m.d,
	}
	json.NewEncoder(bf).Encode(shot)
	log.Info("[metrics] QPS " + bf.String())

	results := snapShotMetricsSts(m.d)
	m.d.Each(func(k string, _ interface{}) {
		c := metrics.GetOrRegisterCounter(k, m.d)
		c.Clear()
	})

	// TODO
	// http should be async
	// file should be async-write, log should be refact
	bf.Reset()
	json.NewEncoder(bf).Encode(results)
	m.transport.Send(m.centerAddr, bf.Bytes())
}
Example #3
0
func (c *httpClient) Send(uri string, data []byte) (err error) {
	log.Info(string(data))
	req, err := http.NewRequest("POST", uri, bytes.NewReader(data))
	if err != nil {
		log.Warnf("new http request err: %v", err)
		return err
	}
	resp, err := c.cli.Do(req)
	if err != nil {
		log.Warnf("do http request err: %v", err)
		return err
	}
	defer resp.Body.Close()

	respData, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Warnf("do http request err: %v", err)
		return err
	}
	// TODO check
	_ = respData
	return
}
Example #4
0
func (l logger) Printf(format string, a ...interface{}) {
	log.Info("[zk] ", fmt.Sprintf(format, a...))
}
Example #5
0
func (l *kafkaLogger) Println(v ...interface{}) {
	args := []interface{}{"[sarama] "}
	args = append(args, v...)
	log.Info(args...)
}
Example #6
0
func (l *kafkaLogger) Printf(format string, v ...interface{}) {
	log.Info("[sarama] ", fmt.Sprintf(format, v...))
}