<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7759727955556242416</id><updated>2024-08-31T05:48:11.705-07:00</updated><title type='text'>Middleware WEB</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tomcat-apache.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7759727955556242416/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://tomcat-apache.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Inf</name><uri>http://www.blogger.com/profile/05096025638590122622</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7759727955556242416.post-6669747078763068539</id><published>2014-08-05T03:02:00.000-07:00</published><updated>2014-08-05T03:03:39.754-07:00</updated><title type='text'>error 0xword</title><content type='html'>Justo que iba a comprar un libro, zaasss&lt;br /&gt;
&lt;br /&gt;
Link to database cannot be established: SQLSTATE[28000] [1045] Access denied for user &#39;utibrq9a_admin2&#39;@&#39;localhost&#39; (using password: YES)</content><link rel='replies' type='application/atom+xml' href='http://tomcat-apache.blogspot.com/feeds/6669747078763068539/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://tomcat-apache.blogspot.com/2014/08/eeror-0xword.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7759727955556242416/posts/default/6669747078763068539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7759727955556242416/posts/default/6669747078763068539'/><link rel='alternate' type='text/html' href='http://tomcat-apache.blogspot.com/2014/08/eeror-0xword.html' title='error 0xword'/><author><name>Inf</name><uri>http://www.blogger.com/profile/05096025638590122622</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7759727955556242416.post-5227253860671555766</id><published>2012-08-23T01:59:00.000-07:00</published><updated>2012-08-23T02:28:33.152-07:00</updated><title type='text'>SABER CONSUMO DE MEMORIA DE PROCESOS UNIX</title><content type='html'>Cuantas veces tenéis la tarea de saber cuanto consume de memoria el apache o tomcat u otro aplicativo. Pues bien a continuación mostraré lo forma de sacarlo de un forma fácil e intuitiva.&lt;br /&gt;
A continuación voy a mostrar dos formas de hacerlo, uno mediante comando y de forma fácil y otro utilizando Phyton.&lt;br /&gt;
&lt;b&gt;&amp;nbsp;FORMA COMANDO&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;#&lt;b&gt;ps -ylC httpd --sort:rss&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;S   UID   PID  PPID  C PRI  NI   &lt;b&gt;RSS &lt;/b&gt;   SZ WCHAN  TTY          TIME CMD&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S  8001  9983  9924  0  76   0  5812  &lt;b&gt;9577 &lt;/b&gt;futex_ ?        00:03:40 httpd&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S  8001  9994  9924  0  75   0  6440 &lt;b&gt;14660 &lt;/b&gt;fcntl_ ?        00:00:00 httpd&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S  8001 10001  9924  0  75   0  6444 &lt;b&gt;14660 &lt;/b&gt;fcntl_ ?        00:00:00 httpd&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S  8001 10004  9924  0  76   0  6444 &lt;b&gt;14660 &lt;/b&gt;fcntl_ ?        00:00:00 httpd&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S  8001 10010  9924  0  76   0  6444 &lt;b&gt;14660 &lt;/b&gt;fcntl_ ?        00:00:00 httpd&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S  8001 10013  9924  0  75   0  6444 &lt;b&gt;14660 &lt;/b&gt;fcntl_ ?        00:00:00 httpd&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;[...]&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
Lo que esta en negrita es rss (Resident Set Size) y lo muestra en KB, por lo que hay que dividirlo entre 1024 si lo quieres en Mb.&lt;br /&gt;
&amp;nbsp;9577  Kb / 1024 = 9.35 Mb&lt;br /&gt;
&amp;nbsp;&lt;b&gt;FROMA SCRIPT&lt;/b&gt;, lo guardas en un fichero y ejecutas python fichero.py&lt;br /&gt;
###############################&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
import sys, os, string&lt;br /&gt;
&lt;br /&gt;
if os.geteuid() != 0:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; sys.stderr.write(&quot;Sorry, root permission required.\n&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
PAGESIZE=os.sysconf(&quot;SC_PAGE_SIZE&quot;)/1024 #KiB&lt;br /&gt;
our_pid=os.getpid()&lt;br /&gt;
&lt;br /&gt;
#(major,minor,release)&lt;br /&gt;
def kernel_ver():&lt;br /&gt;
&amp;nbsp; &amp;nbsp; kv=open(&quot;/proc/sys/kernel/osrelease&quot;).readline().split(&quot;.&quot;)[:3]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for char in &quot;-_&quot;:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; kv[2]=kv[2].split(char)[0]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return (int(kv[0]), int(kv[1]), int(kv[2]))&lt;br /&gt;
&lt;br /&gt;
kv=kernel_ver()&lt;br /&gt;
&lt;br /&gt;
def getShared(pid):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if os.path.exists(&quot;/proc/&quot;+str(pid)+&quot;/smaps&quot;):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; shared_lines=[line&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for line in open(&quot;/proc/&quot;+str(pid)+&quot;/smaps&quot;).readlines()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if line.find(&quot;Shared&quot;)!=-1]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return sum([int(line.split()[1]) for line in shared_lines])&lt;br /&gt;
&amp;nbsp; &amp;nbsp; elif (2,6,1) &amp;lt;= kv &amp;lt;= (2,6,9):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0 #lots of overestimation, but what can we do?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return int(open(&quot;/proc/&quot;+str(pid)+&quot;/statm&quot;).readline().split()[2])*PAGESIZE&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
cmds={}&lt;/div&gt;
&lt;div&gt;
shareds={}&lt;/div&gt;
&lt;div&gt;
count={}&lt;/div&gt;
&lt;div&gt;
for line in os.popen(&quot;ps -e -o rss=,pid=,comm=&quot;).readlines():&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; size, pid, cmd = map(string.strip,line.strip().split(None,2))&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; if int(pid) == our_pid:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue #no point counting this process&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; try:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; shared=getShared(pid)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; except:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue #ps gone away&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; if shareds.get(cmd):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if shareds[cmd] &amp;lt; shared:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; shareds[cmd]=shared&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; else:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; shareds[cmd]=shared&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; #Note shared is always a subset of rss (trs is not always)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cmds[cmd]=cmds.setdefault(cmd,0)+int(size)-shared&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; if count.has_key(cmd):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; count[cmd] += 1&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; else:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; count[cmd] = 1&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
#Add max shared mem for each program&lt;/div&gt;
&lt;div&gt;
for cmd in cmds.keys():&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cmds[cmd]=cmds[cmd]+shareds[cmd]&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
sort_list = cmds.items()&lt;/div&gt;
&lt;div&gt;
sort_list.sort(lambda x,y:cmp(x[1],y[1]))&lt;/div&gt;
&lt;div&gt;
sort_list=filter(lambda x:x[1],sort_list) #get rid of zero sized processes (kernel threads)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
#The following matches &quot;du -h&quot; output&lt;/div&gt;
&lt;div&gt;
#see also human.py&lt;/div&gt;
&lt;div&gt;
def human(num, power=&quot;Ki&quot;):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; powers=[&quot;Ki&quot;,&quot;Mi&quot;,&quot;Gi&quot;,&quot;Ti&quot;]&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; while num &amp;gt;= 1000: #4 digits&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num /= 1024.0&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; power=powers[powers.index(power)+1]&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; return &quot;%.1f %s&quot; % (num,power)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
def cmd_with_count(cmd, count):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; if count&amp;gt;1:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; return &quot;%s (%u)&quot; % (cmd, count)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; else:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; return cmd&lt;/div&gt;
&lt;div&gt;
print &quot; Private &amp;nbsp;+ &amp;nbsp;Shared &amp;nbsp;= &amp;nbsp;RAM used\tProgram \n&quot;&lt;/div&gt;
&lt;div&gt;
for cmd in sort_list:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; print &quot;%8sB + %8sB = %8sB\t%s&quot; % (human(cmd[1]-shareds[cmd[0]]), human(shareds[cmd[0]]), human(cmd[1]),&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cmd_with_count(cmd[0], count[cmd[0]]))&lt;/div&gt;
&lt;div&gt;
print &quot;\n Private &amp;nbsp;+ &amp;nbsp;Shared &amp;nbsp;= &amp;nbsp;RAM used\tProgram \n&quot;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
#Warn of possible inaccuracies&lt;/div&gt;
&lt;div&gt;
#1 = accurate&lt;/div&gt;
&lt;div&gt;
#0 = some shared mem not reported&lt;/div&gt;
&lt;div&gt;
#-1= all shared mem not reported&lt;/div&gt;
&lt;div&gt;
def shared_val_accurate():&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &quot;&quot;&quot;http://wiki.apache.org/spamassassin/TopSharedMemoryBug&quot;&quot;&quot;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; if kv[:2] == (2,4):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if open(&quot;/proc/meminfo&quot;).read().find(&quot;Inact_&quot;) == -1:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; elif kv[:2] == (2,6):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if os.path.exists(&quot;/proc/&quot;+str(os.getpid())+&quot;/smaps&quot;):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (2,6,1) &amp;lt;= kv &amp;lt;= (2,6,9):&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return -1&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; else:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
vm_accuracy = shared_val_accurate()&lt;/div&gt;
&lt;div&gt;
if vm_accuracy == -1:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; sys.stderr.write(&quot;Warning: Shared memory is not reported by this system.\n&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; sys.stderr.write(&quot;Values reported will be too large.\n&quot;)&lt;/div&gt;
&lt;div&gt;
elif vm_accuracy == 0:&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; sys.stderr.write(&quot;Warning: Shared memory is not reported accurately by this system.\n&quot;)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; sys.stderr.write(&quot;Values reported could be too large.\n&quot;)&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
#####################&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;
&lt;/i&gt;

Espero que os sea útil.
Saludos</content><link rel='replies' type='application/atom+xml' href='http://tomcat-apache.blogspot.com/feeds/5227253860671555766/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://tomcat-apache.blogspot.com/2012/08/saber-consumo-de-memoria-de-procesos.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7759727955556242416/posts/default/5227253860671555766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7759727955556242416/posts/default/5227253860671555766'/><link rel='alternate' type='text/html' href='http://tomcat-apache.blogspot.com/2012/08/saber-consumo-de-memoria-de-procesos.html' title='SABER CONSUMO DE MEMORIA DE PROCESOS UNIX'/><author><name>Inf</name><uri>http://www.blogger.com/profile/05096025638590122622</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>