cf-abacus icon indicating copy to clipboard operation
cf-abacus copied to clipboard

Response Time Emitter for external plotting and health checks

Open ArchanPatel890 opened this issue 7 years ago • 3 comments

Currently the abacus-express module has the the ability to log the response time using a morgan middleware function but does not emit/ store the incoming and outgoing requests and responses.

const beforeLogger = () => {
  const morg = morgan(
    ':remote-addr - - :method :url HTTP/:http-version :status ' +
    ':res[content-length] :referrer :user-agent - :response-time ms', {
      immediate: true,
      stream: {
        write: (msg, encoding) => {
          debug('Received request %s', msg.replace(/\n/g, ''));
        }
      }
    });
  return (req, res, next) => {
    return debug.enabled() ? morg(req, res, next) : next();
  };
};

const afterLogger = () => {
  const morg = morgan(
    ':remote-addr - - :method :url HTTP/:http-version :status ' +
    ':res[content-length] :referrer :user-agent - :response-time ms', {
      stream: {
        write: (msg, encoding) => {
          debug('Processed request %s', msg.replace(/\n/g, ''));
        }
      }
    });
  return (req, res, next) => {
    return debug.enabled() ? morg(req, res, next) : next();
  };
};

I would like to have those events logged by an emitter so that I can add a module that can take that information and publish it to an external destination. This could allow for real time plotting of app response times, among other things.

ArchanPatel890 avatar Jul 11 '16 23:07 ArchanPatel890

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/126094943

The labels on this github issue will be updated when the story is started.

cf-gitbot avatar Jul 11 '16 23:07 cf-gitbot

Can you describe your use case in details? The morgan middleware is just a request logger. If you would like to have

real time plotting of app response times

We have the status emitted in the /hystrix.stream and you can use hystrix dashboard to see it real time.

If you would like to store the response stats such as the response time for any other purposes, you can get it from the /hystrix.stream and do some modification on the json structure to match your external app(like grafana).

HTH

KRuelY avatar Jul 16 '16 00:07 KRuelY

I was planning on logging the request/response and response time and send it to grafana, how can I use hystrix.stream to do that? Also would the stream also give access to request message, body, url...etc? From what I see the hystrix doesn't send the complete response and request object? I was planning on just added a simple response-time middleware that uses an even emitter triggered by a custom debug setting.

ArchanPatel890 avatar Jul 18 '16 23:07 ArchanPatel890