Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the ports of all running pm2 apps?

Tags:

I have a server with PM2 installed and 10 running node apps. Every App should run with a different port number. When I install a new App on the server I need the information about the used ports. With 'pm2 list' I get much info about the apps but not the port.

pm2 list  App name       │ id │ version │ mode │ pid   │ status │ restart │ uptime │ cpu  │ mem        │ user │ watching example_name   │ 1  │ 0.0.0   │ fork │ 25651 │ online │ 0       │ 37D    │ 0%   │ 386.3 MB   │ root │ disabled 

I can not find a overview of all used ports and I can't believe that this important information is not given by PM2. Does anyone have any idea where I see a list with all used ports in PM2?

like image 504
Schmidko Avatar asked Nov 16 '18 10:11

Schmidko


People also ask

Which port is pm2 running on?

Starting from PM2 3.2, we changed the networking connection by using a direct Websocket connection to our server on the port 443, so you only need OUTBOUND on port 443 TCP open.

How do I check pm2 details?

To get an overview of the processes currently managed by PM2, you can print out a comprehensive list using the command line utility. The output shows basic information about the running processes like app name and id, the mode ( fork or cluster ), status, uptime, memory footprint, etc.


2 Answers

Yeah this is a bit of a failing with pm2 IMHO. Only when you have more than one instance (site) running on the server. I use:

ss -tnlp | grep "node /"

You can then eyeball the pid from pm2 and the port, or in my case you get just a snippet of the directory it's running from. UPDATE: you can use this monstrosity:

ss -ntlp | grep $(pm2 ls | grep "SITENAME" | awk '{print $10}') | awk '{print $4}' 

Which dumps the port out.

The OP added a comment saying he added the port number into the name of the running node app, which could get messy, but is a good idea.

like image 195
wuxmedia Avatar answered Sep 22 '22 11:09

wuxmedia


Hi Schmidko even i tried the same but i also did not found such option in pm2 so i am currently getting the pid from pm2 l and then using the below command to get port on my linux os

sudo netstat -ano -p tcp | grep <PID> 

so i get output like this : tcp6 0 0 :::1111 :::* LISTEN 2111/app.js off (0.00/0/0)

where 2111/app.js is PID & :::1111 is the port

(posting a comment here as i dont have right to comment)

like image 25
Danny Galiyara Avatar answered Sep 18 '22 11:09

Danny Galiyara