Skip to content

Instantly share code, notes, and snippets.

@corvax19
Last active July 28, 2023 15:13
Show Gist options
  • Save corvax19/158023ce55a0ca375c1c to your computer and use it in GitHub Desktop.
Save corvax19/158023ce55a0ca375c1c to your computer and use it in GitHub Desktop.
[/siebel] All things #siebel
#!/bin/bash
# Extracts login records from archived (.tar.gz) Siebel logs.
SERVER=server
DIR=/app/siebel/siebsrvr/enterprises/ENTPR
FILTER="*eCommunicationsObjMgr_sve*"
for FILE in `ssh siebel@$SERVER "find $DIR -name \"archive*.tar.gz\"|grep -E \"archive_201212(17|18|19|20|21)\""`
do ssh siebel@$SERVER "cat $FILE"|gunzip -c -|tar xOpf - --include "$FILTER" 2>/dev/null|grep 'Authentication name'|grep -v -E '(APPUSER|MON_CSR)'|awk '{print $5" "$6" "$10}'
done
#!awk -f
function help() {
print "Usage: siebCompMemUse [options]"
print
print "Script calculates memory consumption (RSZ and VSZ seperately) for Siebel components,"
print "currently running on machine. Ignores ServerMgr processes."
print
print "Options:"
print " trace trace execution"
print " no-header exclude header line from output"
print " no-total exclude totals line from output"
print " delimeter overdrive delimeter symbol"
print " logfile explicitly specify siebel enterprise log filename"
print
print "20140821 [email protected]"
exit 0
}
function getCLIArgument(name, argv, def) {
for (a in argv) {
if (argv[a] == name) return 1
if (argv[a] ~ (name "=.*")) {
split(argv[a], value, "=")
return value[2]
}
}
return def
}
BEGIN {
if (getCLIArgument("help", ARGV, 0)) help()
trace = getCLIArgument("trace", ARGV, 0)
show_header = !(getCLIArgument("no-header", ARGV, 0))
show_totals = !(getCLIArgument("no-total", ARGV, 0))
delimeter = getCLIArgument("delimeter", ARGV, "|")
logFile = getCLIArgument("logfile", ARGV, "0")
enterprise = 0
sz_pagesize = 4096 # TODO: implement smart-check
vsz_pagesize = 1024 # TODO: implement smart-check
LSOF = "lsof" # TODO: availability check
PS = "ps" # TODO: availability check
# find target user
"whoami" | getline user
if (trace > 0) printf "trace| user: '%s'\n", user
# finding root Siebel process
rootPID = 0
cmd = sprintf("UNIX95=1 %s -eo pid,comm,args", PS)
#TODO: implement root proc counter and check for #==1
while(cmd | getline) {
if ($0 ~ /.*siebsvc.*siebsrvr.*/) {
split($0, ps_split)
for (f in ps_split) {
if (ps_split[f] == "-e") {
enterprise = ps_split[f+1]
if (trace) printf("trace| Siebel enterprise name: %s\n", enterprise)
}
}
rootPID = $1
if (trace) printf "trace| Siebel application server root proc PID:%d\n", rootPID
}
}
if (!rootPID) {
print "ERROR: Root process of Siebel application server is not found!"
exit 1
}
if (!enterprise) {
print "ERROR: Siebel enterprise name is not found!"
exit 10
}
# finding enterprise log file
if (!logfile) {
while (sprintf("%s -p %d -F", LSOF, rootPID) | getline l) {
if (l ~ /.*\.log$/) {
logfile = substr(l, 2)
if (trace > 0) printf "trace| enterprise log file: %s\n", logfile
}
}
}
if (logfile == 0) {
print "ERROR: Enterprise log file is not found! You have to explicitly specify it via logfile=<file> option"
exit 2
}
# finding memory use of all siebel processes, among with their PIDs
if (trace > 0) print "trace| finding siebel processes memory usage.."
cmd = sprintf("UNIX95=1 ps -u %s -o pid,ppid,sz,vsz", user)
while (cmd | getline) {
if ($1 == rootPID || $2 == rootPID) {
pid = $1
proc[count++] = pid
sz[pid] = $3 * sz_pagesize
vsz[pid] = $4 * vsz_pagesize
if (trace > 0) printf "trace| ps PID:%d, SZ:%.0f, VSZ:%.0f\n", pid, sz[pid], vsz[pid]
}
}
# reading PIDs from logfile
if (trace > 0) print "trace| scanning enterprise logfile for component's PIDs.."
while (getline l < logfile) {
if (l ~ /ProcessCreate/ && l !~ /ServerMgr/) {
n = split(l, lsplit)
comp = lsplit[n]; comp = substr(comp, 0, length(comp)-1)
pid = lsplit[n-3]
pid_comp[pid] = comp
if (trace > 0) printf "trace| log PID:%d, COMP:%s\n", pid, comp
}
}
# iterate over live processes, correlate proc PID with
# component's name from the enterprise log,
# aggregate memory usage by component
if (trace > 0) print "trace| mapping running processes to Siebel component names.."
for (pid in proc) {
pid = proc[pid]
comp = pid_comp[pid]
if (comp != "") {
comp_sz[comp] += sz[pid]
comp_vsz[comp] += vsz[pid]
components[comp]++
if (trace > 0) printf "trace| map PID:%d, COMP:%s, SZ:%.0f, VSZ:%.0f\n",
pid, comp, sz[pid], vsz[pid]
}
}
# output result
if (trace > 0) print "trace| output.."
while ("date +\"%s\"" | getline ts)
while ("uname -n" | getline host)
ent = "TEST"
if (show_header) {
header = "|ts|host|enterprise|component|PROC_COUNT|SZ_BYTES|VSZ_BYTES"
if (delimeter != "|") gsub("|", delimeter, header)
print(header)
}
for (comp in components) {
line = "%.0f|%s|%s|%s|%d|%.0f|%.0f\n"
if (delimeter != "|") gsub("|", delimeter, line)
printf(line, ts, host, enterprise, comp, components[comp], comp_sz[comp], comp_vsz[comp])
if (show_totals) {
tproc += components[comp]
tsz += comp_sz[comp]
tvsz += comp_vsz[comp]
}
}
if (show_totals) {
totals = "%.0f|%s|%s|%s|%d|%.0f|%.0f\n"
if (delimeter != "|") gsub("|", delimeter, totals)
printf(totals, ts, host, enterprise, "TOTAL_ALL_COMP", tproc, tsz, tvsz)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment