#!/bin/bash

# This is a small script to log the vmsize of the EPICS gateway used for the LCLS archiver.
# Jingchen asked Murali to add this for a couple of days (Feb/14/2014).
# This should be removed after we move the LCLS archiver in production


CURRENT_DATE_TIME=`date`
LCLSARCH0_GATEWAY_PID=`ps -fade | grep gwLCLSARCH0 | grep -v grep |  tail -1 | tr --squeeze-repeats " " , | cut -d "," -f 2`
VMSIZE0=`cat /proc/${LCLSARCH0_GATEWAY_PID}/status | grep "VmSize:" | tr --squeeze-repeats " " "," | cut -d "," -f 2  | xargs printf "scale=2;%ld/(1024*1024)\n" | bc`
LCLSARCH1_GATEWAY_PID=`ps -fade | grep gwLCLSARCH1 | grep -v grep |  tail -1 | tr --squeeze-repeats " " , | cut -d "," -f 2`
VMSIZE1=`cat /proc/${LCLSARCH1_GATEWAY_PID}/status | grep "VmSize:" | tr --squeeze-repeats " " "," | cut -d "," -f 2  | xargs printf "scale=2;%ld/(1024*1024)\n" | bc`
LCLSARCH2_GATEWAY_PID=`ps -fade | grep gwLCLSARCH2 | grep -v grep |  tail -1 | tr --squeeze-repeats " " , | cut -d "," -f 2`
VMSIZE2=`cat /proc/${LCLSARCH2_GATEWAY_PID}/status | grep "VmSize:" | tr --squeeze-repeats " " "," | cut -d "," -f 2  | xargs printf "scale=2;%ld/(1024*1024)\n" | bc`
echo "${CURRENT_DATE_TIME},${VMSIZE0},${LCLSARCH0_GATEWAY_PID},${VMSIZE1},${LCLSARCH1_GATEWAY_PID},${VMSIZE2},${LCLSARCH2_GATEWAY_PID}"

