func NewVarzMessage(name string, instrumentables []Instrumentable) (*VarzMessage, error) { contexts := make([]Context, len(instrumentables)) for i, instrumentable := range instrumentables { contexts[i] = instrumentable.Emit() } memStats := new(runtime.MemStats) runtime.ReadMemStats(memStats) ip, err := localip.LocalIP() if err != nil { return &VarzMessage{}, err } tags := map[string]string{ "ip": ip, } return &VarzMessage{name, runtime.NumCPU(), runtime.NumGoroutine(), mapMemStats(memStats), tags, contexts}, nil }
func Fetch() { for { t := time.Now() ip, err := localip.LocalIP() if err != nil { panic(err) } url := "http://*****:*****@" + ip + ":7879/varz" resp, err := http.Get(url) if err != nil { panic(err) } if verbose { fmt.Printf("FETCHING METRICS TOOK: %s\n", time.Since(t)) } resp.Body.Close() time.Sleep(collectorFetchInterval * time.Second) } }
) var _ = Describe("Serving Metrics", func() { var ( a appfixture.AppFixture ip string ) BeforeEach(func() { a = appfixture.NewAppFixture() simulator.SetDesiredState(a.DesiredState(2)) simulator.SetCurrentHeartbeats(a.Heartbeat(1)) var err error ip, err = localip.LocalIP() Ω(err).ShouldNot(HaveOccurred()) }) AfterEach(func() { cliRunner.StopMetricsServer() }) It("should register with the collector", func(done Done) { cliRunner.StartMetricsServer(simulator.currentTimestamp) guid := models.Guid() coordinator.MessageBus.Subscribe(guid, func(message *yagnats.Message) { Ω(string(message.Payload)).Should(ContainSubstring("%s:%d", ip, coordinator.MetricsServerPort)) Ω(string(message.Payload)).Should(ContainSubstring(`"bob","password"`)) close(done)