How can I collect total ArcGIS Server memory usage?

1029
7
Jump to solution
02-13-2017 08:31 AM
ChrisMathers1
Occasional Contributor II

I want to include AGS memory use in System Monitor but the way each service spins up its own thread makes measuring it a bit tricky since the memory load is spread out. Currently on AGS 10.2.2 but will shortly be updating to 10.5 if that makes a difference.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JonathanQuinn
Esri Frequent Contributor

You can run a .bat file that runs the TASKLIST command and provide a filter to find all ArcSOC.exe processes as well as javaw.exe processes:

Ex of ArcSOC.exe

TASKLIST /M /FI "Imagename eq ArcSOC.exe"

You can probably parse the output through the command prompt, or write the response to disk and parse it there.

View solution in original post

7 Replies
JonathanQuinn
Esri Frequent Contributor

You can run a .bat file that runs the TASKLIST command and provide a filter to find all ArcSOC.exe processes as well as javaw.exe processes:

Ex of ArcSOC.exe

TASKLIST /M /FI "Imagename eq ArcSOC.exe"

You can probably parse the output through the command prompt, or write the response to disk and parse it there.

RebeccaStrauch__GISP
MVP Esteemed Contributor

JQuinn-esristaff , if I used the /M (or /m) it only returned the Image Name, Pid, and Modules (which showed N/A for all).  If I left the /M off, it showed me memory used.  Any simple way to tie this back to the service, as I assume Chris is asking?  My apology that is not what is being asked...not trying hijack this thread, but this would be handy for me too.  Any other admin tools for this??

0 Kudos
ChrisMathers1
Occasional Contributor II

I just finished writing a small script that lets me add the metric. I took the System Monitor help doc advice and instead of setting up a collector for this I'm grabbing the value with a python script and putting it into a table in a database which is queried like anything else from a database in SM. I made a table that isnt part of the geodatabase in our production environment and then execute the tasklist for ArcSOC and javaw on the two servers in our publication environment. That is returned as text so I broke it down to an integer to stick in the database. The table in the database is called SERVERMONITORMETRICS and has two columns, COUNTER and VALUE. pypyodbc updates the corresponding rows in the database and SM grabs those values. Windows Task Scheduler has the script run every 5 minutes. Might be an easier way to do it but this works for me.

import pypyodbc, subprocess

PUBAGSMEMORY = sum([int(i.split(' ')[-2].replace(',','')) for i in subprocess.check_output('TASKLIST /s xx.xx.xx.xx /FO LIST /FI "Imagename eq ArcSOC.exe"').split('\n') if 'Mem Usage:' in i]) + sum([int(i.split(' ')[-2].replace(',','')) for i in subprocess.check_output('TASKLIST /s xx.xx.xx.xx /FO LIST /FI "Imagename eq javaw.exe"').split('\n') if 'Mem Usage:' in i])
FOAGSMEMORY = sum([int(i.split(' ')[-2].replace(',','')) for i in subprocess.check_output('TASKLIST /s xx.xx.xx.xx /FO LIST /FI "Imagename eq ArcSOC.exe"').split('\n') if 'Mem Usage:' in i]) + sum([int(i.split(' ')[-2].replace(',','')) for i in subprocess.check_output('TASKLIST /s xx.xx.xx.xx /FO LIST /FI "Imagename eq javaw.exe"').split('\n') if 'Mem Usage:' in i])

db = pypyodbc.connect('Driver={SQL Server}; Server=bay-arcgis-pro; Database=sde; Uid=*****; Pwd=*****;')
cursor = db.cursor()
query = '''
UPDATE sde.SERVERMONITORMETRICS
SET VALUE = %s
WHERE COUNTER = 'PUB AGS MEMORY'

UPDATE sde.SERVERMONITORMETRICS
SET VALUE = %s
WHERE COUNTER = 'FO AGS MEMORY'
'''%(PUBAGSMEMORY, FOAGSMEMORY)

cursor.execute(query)
cursor.commit()
del cursor, db
JonathanQuinn
Esri Frequent Contributor

Nice sample, Chris!

0 Kudos
JonathanQuinn
Esri Frequent Contributor

That command appears to require elevevated privileges to return information you need:

Non-admin

Admin (not a great screenshot given the amount of stuff returned, but the idea is that it requires Admin privileges)

RebeccaStrauch__GISP
MVP Esteemed Contributor

ahh yes, I should have guessed.  I ran into that on another command when trying to find file locks.  Once I opened the command window as admin, I can now seethe addition info.

0 Kudos
ChrisMathers1
Occasional Contributor II

Ive actually found an even better way of doing this though some googling. Once I had "tasklist" the searching was a bit easier. The code below should be run in a BAT. All the addition is done in the commands and sent to the SQL Server using the sqlcmd command. Because sqlcmd is needed this has to be run in a place where there is SQL Server installed. For us it works out because we have SQL and AGS on the same machine. If they are separate you can add the /s flag to tasklist and give it the IP for the machine with AGS. By removing python from the mix and thus not having to do any imports the speed is up dramatically. Run as a schedualed task same as before but use the BAT instead of the PY. Dont know if Oracle and other DBMSs have a similar command line function but I would imagine they do.

EDIT: I should note that in the query that SM does for this I convert it to GB so its a little less crazy to look at since the is reported in KB. It goes on a graph with the Total Server Memory (KB) metric that SQL Server keeps which is how much memory its currently using.

@Echo Off
Set "sum=0"
For /F "Tokens=6-7 Delims=., " %%a In (
    'TaskList /NH /FI "ImageName Eq ArcSOC.exe"') Do Set/A sum+=%%a%%b
For /F "Tokens=6-7 Delims=., " %%a In (
    'TaskList /NH /FI "ImageName Eq javaw.exe"') Do Set/A sum+=%%a%%b

set "query="UPDATE sde.SERVERMONITORMETRICS SET VALUE = %sum% WHERE COUNTER = 'FO AGS MEMORY'""
sqlcmd -S bay-arcgis-pro -d sde -Q %query%‍‍‍‍‍‍‍‍‍
0 Kudos