O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple metrics

Setting a PM2 metric value is just a matter of initializing a probe and setting a value in it. We can create a simple metric with the following steps. You can follow the source in chapter 9/simple_metric:

  1. Copy our first microservice skeleton from Chapter 2, Gearing up for the Journey. We will add our changes here. Install pm2 and pmx modules as a dependency:
npm install pm2 pmx -save
  1. In HelloWorld.ts, initialize pmx with the following code. We will add a simple metric name 'Simple Custom metric' along with variable initializations:
constructor(){this.pmxVar=pmx.init({http:true,errors:true, custom_probes:true,network:true,ports:true});this.probe=this.pmxVar.probe();this.metric=this.probe.metric({ name:'Simple custom metric' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required