pmx icon indicating copy to clipboard operation
pmx copied to clipboard

Metrics not being reported by pm2 show x

Open camway opened this issue 7 years ago • 4 comments

I feel as though I'm just misusing this package somehow, but I can't figure out what I'm doing wrong.

I've setup 4 different trackers for my app that is run on pm2, but only one of them appears to be reporting any data. 3 of them are meters and 1 of them is a counter. Only 1 of the meters is reporting anything, and I question whether it's correct.

I've tried multiple variations, but this is the current state (obfuscated):

const probe = require('pmx').init({ http: true, errors: true, custom_probes: true, network: true, ports: true }).probe()

probe.counter({ name: "a" })
probe.meter({ name: "b", samples: 60 })
probe.meter({ name: "c", samples: 60 })
probe.meter({ name: "d", samples: 60 })

The meters I've also tried passing agg_type: 'sum' and timeframe: 60 * 60 * 60 (as well as several combinations of these and the above)

I also considered that the probe() function may have to be called before each instance is created, so I tried this refactor:

const pmx = require('pmx').init({ http: true, errors: true, custom_probes: true, network: true, ports: true })

pmx.probe().counter({ name: "a" })
pmx.probe().meter({ name: "b", samples: 60 })
pmx.probe().meter({ name: "c", samples: 60 })
pmx.probe().meter({ name: "d", samples: 60 })

I'm unsure if it matters, but I'm importing the pmx package in a require, and then exporting 4 objects that are each meter/counter instance. Those are then imported in various areas of the project where they are actually incremented/marked.

Is there some kind of pitfall that I'm hitting here? Or is this a bug?

camway avatar Jun 13 '18 21:06 camway

Hi @camway

I think your syntax is ok. But here is the way we used to instantiate metric :

const pmx = require('pmx')
const probe = pmx.probe()

const meter = probe.meter({name: 'foo'})
....
meter.set(10)

Could you try to launch your app in debug mode and tell us if you see any pmx errors/warnings ? DEBUG=true node ......

wallet77 avatar Jun 14 '18 12:06 wallet77

@wallet77 Thank you for the quick response.

I tried to refactor to your setup, but I get an error something.set is not a function.

I removed the set line and enabled debug mode. Other than logs I setup, its completely quiet.

Just in case it comes up, my package.json shows "pmx": "^1.6.4"

camway avatar Jun 14 '18 16:06 camway

@camway

Sorry, maybe a too quick answer :) .set() is only for metric.

You can use :

myMeter.mark()  // for meter
myCounter.inc()  // to increment counter
myCounter.dec()  // to decrement counter

wallet77 avatar Jun 15 '18 09:06 wallet77

@wallet77 So I'm still not sure what I'm doing wrong. The only way I've been able to get anything to report to pm2, was by spinning up a new project that did nothing but send trash data to the various trackers. This does tell me though that there has to be something in my project that's causing it not to work, or it wouldn't have worked in the new project.

If I figure out what is going wrong, I'll try to post it back on here in case anyone else runs into it

camway avatar Jun 19 '18 22:06 camway