Example #1
0
func (this *push) sendStats(stats map[string]*protoStat.ProtoStat) (err error) {
	var s []*protoStat.ProtoStat
	// fmt.Println(stats)
	pStats := new(protoStat.ProtoStats)
	for _, v := range stats {
		s = append(s, v)
	}
	// fmt.Println(s)
	pStats.Stats = s
	now := time.Now().UTC().UnixNano()
	pStats.TimeNano = &now

	fmt.Println(pStats)
	bytes, err := pStats.Marshal()
	if nil != err {
		return
	}
	_, err = this.socket.Send(bytes, 0) //blocking
	return
}
Example #2
0
	gi.It("End to End integration test with stats", func() {
		pull, err := nano.NewPullSocket()
		gom.Expect(err).Should(gom.BeNil())
		pull.SetRecvTimeout(6 * time.Second)
		pull.SetRecvBuffer(1000)
		pull.Bind("ipc:///tmp/goreportertest.ipc")
		key := "key"
		rep.RegisterStat(key)
		rep.RegisterStatWIndex(key, "index")
		rep.AddStat(key, 2)
		rep.AddStat(key, 2)
		rep.AddStatWIndex(key, 2, "index")
		rep.AddStatWIndex(key, 2, "index")
		msg, err := pull.Recv(0)
		gom.Expect(err).Should(gom.BeNil())
		stats := new(protoStat.ProtoStats)
		stats.Unmarshal(msg)
		gom.Expect(len(stats.Stats)).Should(gom.Equal(2))
		for _, stat := range stats.Stats {
			gom.Expect(stat.GetValue()).Should(gom.Equal(float64(4)))

		}
	})

	gi.It("Reset Stats to zero", func() {
		stats := make(map[string]*protoStat.ProtoStat)
		key := "key"
		indexKey := "index"
		b := true
		value := float64(200)