How to measure action response times in molecular.js

42 views Asked by At

I have a backend written in molecular.js and I have multiple services. Now, I want to measure the action response times so I can know and optimize actions before going live. Any suggestions/comment will work. Maybe there is a npm package out there or should I code it in the app itself.

I tried to find some good package but found nothing.

1

There are 1 answers

0
Icebob On BEST ANSWER

If you use Moleculer 0.14, there is built-in metrics and tracing. Both can be useful to measure the execution time of action calls.

Metrics https://moleculer.services/docs/0.14/metrics You can configure the Console reporter, or Prometheus reporter and see the measured metrics in Grafana

For the Console reporter, you can use includes to filter the metrics:

// moleculer.config.js
module.exports = {
    metrics: {
        enabled: true,
        reporter: [
            {
                type: "Console",
                options: {
                    includes: ["moleculer.request.time"]
                }
            }
        ]
    }
};

Tracing https://moleculer.services/docs/0.14/tracing

The tracing collect spans of action calls. You can use the Console exporter which prints the whole action call tracing spans to the console:

// moleculer.config.js
module.exports = {
    tracing: {
        enabled: true,
        exporter: {
            type: "Console",
            options: {
                // Custom logger
                logger: null,
                // Using colors
                colors: true,
                // Width of row
                width: 100,
                // Gauge width in the row
                gaugeWidth: 40
            }
        }
    }
};

enter image description here