how to check memory allocated to tomcat on linux server - linux

We are facing server responding slow issue for tomcat servers.
How to check memory allocated to tomcat on Linux server? I tried in shell
ps -aux| grep tomcat and netstat -tulpn | grep 8080
But no luck.

top -p <PID of your tomcat> command will give resource utilization of only tomcat's.

Related

Not able to find port number for tomcat process on Ubuntu

I am not able to find a port number for running Tomcat server on Ubuntu
i.e. netstart -anp | grep 'tomcat' but not getting any output.
You will want to grep for java and not tomcat, as the process binary is java and not Tomcat.
If you'd like to find the PID for the process to make things easier (e.g. if you have lots of Java processes on the server), you can do this:
ps aux | grep catalina
This will show you your various Tomcat processes. Each one will have a system property on the command-line like this:
-Dcatalina.base=/path/to/your/tomcat
Note that there is also catalina.home which may be different. If they are different, it is catalina.base which is the correct one, which contains your server's conf/server.xml which controls the server.
Once you have that PID, you can netstat -plan | grep [PID] to get your port number.
Or just look in /path/to/your/tomcat/conf/server.xml for any <Connector> elements, each of which should have a port specified.

Why HTTP ports stay open when using them by Nodejs servers?

I have a problem when launching a Nodejs script that listens in one of the HTTP ports. Sometimes, even if I stop the script, the used HTTP port stays "in use", making it impossible to use it another time. Today, i've set up NGINX in my linux and all the HTTP ports were "in use". I was obliged to restart my computer to solve the problem.
I wanted to know why is this happening ? What can i do to prevent it ? and in case an HTTP port stays "in use", how can i close it to be able to use again ?
Thanks for your help.
This is applicable only on Linux and MacOS, you can list all your used ports like that:
sudo lsof -i -P -n | grep LISTEN
Read more here about how to check if a port is in use: https://www.cyberciti.biz/faq/unix-linux-check-if-port-is-in-use-command/
You can also list the node processes:
top | grep node
or
ps -ef | grep node
Then you can kill the node processes like that:
killall node
Make sure that when you want to stop the server you are pressing CTRL + C

Figure out which port a local Apache Spark UI is on

To find out some info about a local spark process, launched locally via spark-shell command I can do:
jps -lm | grep -i spark
However, how do I find what TCP port the UI is published on?
I have tried:
lsof -p PID
but no luck.
If you list open ports, you can filter by greping the PID (My pid is 30688, but you can also grep by java or something just to narrow the results):
$ ss -l -p -n | grep -i 30688
And, unless you've reconfigured it to a dramatically different range, you should be able to see a 40* port (I replaced tabs with -- to save space):
tcp--LISTEN--0--50--*:4040--*:*--users:(("java",pid=30688,fd=275))
Seems you already have the PID. in that case you can run below, which should indicate what ports the process is listening on:
netstat -tunlp|grep LISTEN|grep PID
The spark driver process may be listening on more than one ports, so you may have to try http://host:port for the ports obtained.
Alternatively, if you are finding only one PIDs from your jps | grep, then you can be sure that the port is 4040(default spark web ui port), unless you find the args spark.webui.port. In the latter case, get the port from the args value.

Killing Stanford core nlp process

I launch Stanford Core NLP server using the following command (on Ubuntu 16.04):
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
I would like to kill this server once I am done using it. Simply closing terminal does not help. It does not release memory. Is there way to kill it and release memory without rebooting computer?
You can always CTRL-C in the terminal window to stop the server.
You could also ps aux | grep StanfordCoreNLPServer to find the pid and then kill the process manually.
When the server is started it should create a shutdown key and you can send that message to the server to close the server. This isn't working on my Macbook Pro (maybe a permission issue ??) but I've seen it work on other machines.
Here is the command:
wget "localhost:9000/shutdown?key=`cat /tmp/corenlp.shutdown`" -O -
Note the shutdown key is stored at /tmp/corenlp.shutdown
If you use the the -server_id server0 option the shutdown key will be stored at this path /tmp/corenlp.shutdown.server0
If you just want to kill the process. You can use lsof command.
#install lsof if missing
sudo apt install lsof
You can find the pid of CoreNLP using
lsof -i:9000
Replace 9000 with the port you used to run the server.
The output looks like
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 15867 XXXX XXX IPv6 XXXXXX 0t0 TCP *:9000 (LISTEN)
Use the pid from here and run.
kill 15867
PID of my server process is 15867.

Where is my Tomcat running?

I am using linux centos. I have installed tomcat in multiple folders. One of them is running.
When I use netstat -ntlp command, it says port 8080 is running, and I can access the URL http://localhost:8080
Now I want to know the path of tomcat folder where it's running?
Assume I closed all the terminals, I could not guess where I initiated..
Thanks in advance..
do a ps -ef grep for tomcat
the result will have the directory of tomcat
[user#edw-support-dev1 ~]$ ps -ef | grep tomcat
root 12898 1 0 May14 ? 00:30:38 /usr/local/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-7.0.41/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx2048m -XX:PermSize=2048m -XX:MaxPermSize=2048m -Djava.endorsed.dirs=/opt/apache-tomcat-7.0.41/endorsed -classpath /opt/apache-tomcat-7.0.41/bin/bootstrap.jar:/opt/apache-tomcat-7.0.41/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-7.0.41 -Dcatalina.home=/opt/apache-tomcat-7.0.41 -Djava.io.tmpdir=/opt/apache-tomcat-7.0.41/temp org.apache.catalina.startup.Bootstrap start
2064 21567 21544 0 21:28 pts/1 00:00:00 grep tomcat
ps aux | grep tomcat
And you will know the installation directory of tomcat.
You can also use "locate" command as "locate tomcat" this command will find out the files named tomcat which might give you a pointer where tomcat is residing on your disk. :)

Resources