Wolfgang
Wolfgang

Reputation: 3540

How can I identify different services when they're all named 'server.js'?

Following a common convention, I generally name the main file in a project server.js. However, this leads to situations like this:

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
21049 root      20   0 2347568 1.133g      0 D  0.0 14.5   0:32.70 node ./server.js
28201 root      20   0 1261740  69332      8 S  0.0  0.8   4:04.46 node src/server.js
26652 root      20   0  776664   9324      8 S  0.0  0.1   0:00.09 node server.js

One of these services has a serious memory problem--but how do I figure out what it is?

Some possible solutions that come to mind:

Are there best practices for this sort of thing? It seems like it would be a common problem with microservices, but I can't find anything about how other people have solved it.

Upvotes: 1

Views: 63

Answers (1)

odino
odino

Reputation: 1069

You can simply process.title = process.env.PROCESS_TITLE, or use something like process-title which relies on the name in the package.json.

I think this is the most straightforward approach one can think of. With Docker I wouldn't bother looking at single processes within the host (ps) but instead use the abstraction docker provides you (docker ps) if you really need to.

(in general microservices push things one level up so that you don't have to worry too much about the low-level drama, where orchestrators like k8s or openshift take care of process monitoring and so on)

Upvotes: 1

Related Questions