appsody / stacks

Appsody application stacks. This repo will be archived soon.
https://appsody.dev
Apache License 2.0
90 stars 120 forks source link

nodejs-express: appsody build provides limited metrics #725

Closed Kamran64 closed 4 years ago

Kamran64 commented 4 years ago

Describe the bug As we are now using npm install --production in the final image build, the metrics shown in the /metrics endpoint seem to be limited:

# HELP os_cpu_used_ratio The ratio of the systems CPU that is currently used (values are 0-1)
# TYPE os_cpu_used_ratio gauge
os_cpu_used_ratio 0.0309476
# HELP process_cpu_used_ratio The ratio of the process CPU that is currently used (values are 0-1)
# TYPE process_cpu_used_ratio gauge
process_cpu_used_ratio 0.000952232
# HELP os_resident_memory_bytes OS memory size in bytes.
# TYPE os_resident_memory_bytes gauge
os_resident_memory_bytes 4169146368
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 50262016
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 1291042816

It looks like this is because appmetrics is being loaded too late. This isn't a problem during appsody run as it gets loaded by appmetrics-dash whereas in prod mode this happens later. (line 13 of server.js):

if (!PRODUCTION) {
  require('appmetrics-dash').monitor({server, app});
}

To Reproduce Steps to reproduce the behavior:

  1. Initialise a nodejs-express project
  2. appsody build and run the built app
  3. See the lack of metrics at the /metrics endpoint
  4. Compare with appsody run /metrics endpoint to see the difference

Environment Details (please complete the following information):

If applicable please specify: