// Test of the ETM monitor. func TestEtmMonitor(t *testing.T) { assert := audit.NewTestingAssertion(t, true) // Generate measurings. for i := 0; i < 500; i++ { n := rand.Intn(10) id := fmt.Sprintf("mp:task:%d", n) m := monitoring.BeginMeasuring(id) work(n * 5000) m.EndMeasuring() } // Need some time to let that backend catch up queued mesurings. time.Sleep(time.Millisecond) // Asserts. mp, err := monitoring.ReadMeasuringPoint("foo") assert.ErrorMatch(err, `.* measuring point "foo" does not exist`) mp, err = monitoring.ReadMeasuringPoint("mp:task:5") assert.Nil(err, "No error expected.") assert.Equal(mp.Id, "mp:task:5", "should get the right one") assert.True(mp.Count > 0, "should be measured several times") assert.Match(mp.String(), `Measuring Point "mp:task:5" \(.*\)`, "string representation should look fine") monitoring.MeasuringPointsDo(func(mp *monitoring.MeasuringPoint) { assert.Match(mp.Id, "mp:task:[0-9]", "id has to match the pattern") assert.True(mp.MinDuration <= mp.AvgDuration && mp.AvgDuration <= mp.MaxDuration, "avg should be somewhere between min and max") }) }
// Do executes one Redis command and returns // the result as result set. func (conn *Connection) Do(cmd string, args ...interface{}) (*ResultSet, error) { cmd = strings.ToLower(cmd) if strings.Contains(cmd, "subscribe") { return nil, errors.New(ErrUseSubscription, errorMessages) } err := conn.ensureProtocol() if err != nil { return nil, err } if conn.database.monitoring { m := monitoring.BeginMeasuring(identifier.Identifier("redis", "command", cmd)) defer m.EndMeasuring() } err = conn.resp.sendCommand(cmd, args...) logCommand(cmd, args, err, conn.database.logging) if err != nil { return nil, err } result, err := conn.resp.receiveResultSet() return result, err }
// Do executes one Redis command and returns // the result as result set. func (ppl *Pipeline) Do(cmd string, args ...interface{}) error { cmd = strings.ToLower(cmd) if strings.Contains(cmd, "subscribe") { return errors.New(ErrUseSubscription, errorMessages) } err := ppl.ensureProtocol() if err != nil { return err } if ppl.database.monitoring { m := monitoring.BeginMeasuring(identifier.Identifier("redis", "command", cmd)) defer m.EndMeasuring() } err = ppl.resp.sendCommand(cmd, args...) logCommand(cmd, args, err, ppl.database.logging) if err != nil { return err } ppl.counter++ return err }
// ServeHTTP is specified on the http.Handler interface. func (mux *multiplexer) ServeHTTP(w http.ResponseWriter, r *http.Request) { mux.mutex.RLock() defer mux.mutex.RUnlock() ctx, err := newContext(mux, r, w) if err != nil { mux.internalServerError("error preparing request", ctx, err) return } if mux.sceneManager != nil { scene, err := mux.sceneManager.Scene(ctx) if err != nil { mux.internalServerError("error retrieving scene for request", ctx, err) return } ctx.scene = scene } measuring := monitoring.BeginMeasuring(ctx.String()) defer measuring.EndMeasuring() err = mux.mapping.handle(ctx) if err != nil { mux.internalServerError("error handling request", ctx, err) } }
// backendLoop is the backend for the processing of messages. func (c *cell) backendLoop(l loop.Loop) error { totalCellsID := identifier.Identifier("cells", c.env.ID(), "total-cells") monitoring.IncrVariable(totalCellsID) defer monitoring.DecrVariable(totalCellsID) for { select { case <-l.ShallStop(): return c.behavior.Terminate() case event := <-c.eventc: if event == nil { panic("received illegal nil event!") } measuring := monitoring.BeginMeasuring(c.measuringID) err := c.behavior.ProcessEvent(event) measuring.EndMeasuring() if err != nil { logger.Errorf("cell %q processed event %q with error: %v", c.id, event.Topic(), err) return err } } } }
// backendLoop is the backend for the processing of messages. func (c *cell) backendLoop(l loop.Loop) error { monitoring.IncrVariable(identifier.Identifier("cells", c.env.ID(), "total-cells")) defer monitoring.DecrVariable(identifier.Identifier("cells", c.env.ID(), "total-cells")) for { select { case <-l.ShallStop(): return c.behavior.Terminate() case subscribers := <-c.subscriberc: c.subscribers = subscribers case event := <-c.eventc: if event == nil { panic("received illegal nil event!") } measuring := monitoring.BeginMeasuring(c.measuringID) err := c.behavior.ProcessEvent(event) if err != nil { c.loop.Kill(err) continue } measuring.EndMeasuring() } } }
// BeginMeasuring implements Monitoring. func (m *standardMonitoring) BeginMeasuring(id string) MonitoringMeasuring { return &standardMonitoringMeasuring{ measuring: monitoring.BeginMeasuring(id), } }