Posted: Sat Nov 17, 2007 10:34 pm Post subject: Displays a self-refreshing web page displaying the SAP param
This perl displays a self-refreshing web page displaying the vital parameters of multiply SAP systems
Code:
#!/opt/perl5/bin/perl
#
# This perl script displays on a single, self-refreshing web page
# the most important parameters of multiply sap systems. By taking a
# look at this page, most of the problems can be noticed
# immediately. The displayed data:
# system status(up/down)
# user number per app. server
# session number per app. server
# average response time per app. server
# number of active locks
# number of update entries
# number of abap dumps (today)
# number of error messages in the system log (today)
#
# The web page gets refreshed once every three minutes.
# The perl script uses SAP's rfc2abap to submit
# the data collector abap (the source code: pr# 93b is in a
# unix text file) in the different systems. A cpic type user
# has to exist in those systems to run the abap.
# The script was used to monitor 14 SAP systems parallel.
#
print "Content-type:text/html\n\n";
use CGI;
print "<HTML><BODY style=\"font-size: small\">";
print "<META http-equiv=\"refresh\" content=\"180;URL=sysmon.cgi\">";
#
# Print out the time of the last screen refresh
#
$datum = `date`;
@f = split /\s/, $datum;
print "@f[3] @f[1] @f[2] @f[5]<BR><HR><BR>";
#
# Print a main header
#
print "<table border=\"1\" width=\"900\" height=\"28\" bgcolor=\"#0000FF\"";
print "cellspacing=\"0\"<tr>";
print "<td width=\"614\" align=\"center\"><strong><font color=\"#FFFFFF\">";
print "SYSTEM DEPENDENT DATA</font></strong></td>";
print "<td width=\"386\" align=\"center\"><strong><font color=\"#FFFFFF\">";
print "INSTANCE DEPENDENT DATA</font></strong></td>";
print "</tr></table>";
#
# Print the column headings
#
@h=("SYSTEM","STATUS","SYSLOG ERRORS TODAY","ABAPDUMPS TODAY","LOCKS","UPDATE EN
TRIES","INSTANCE","USERS","SESSIONS","AVERAGE D. RESPONSE TIME");
print "<table border=\"1\" width=\"900\" height=\"28\" cellspacing=\"0\"";
print "<tr>";
for ($x = 0; $x < @h; $x++) {
print "<td width=\"75\" bgcolor=\"#00FFFF\" align=\"center\">";
print "<small><small><small>@h[$x]</small></small></small></td>";
}
print "</tr>";
#
# List of the systems to be monitored(SID, client, host, system number)
# This portion of the script has to be customized
#
@s = (
["DEV", "090", "host1", "00"],
["PRD", "100", "host2", "01"],
["QAS", "110", "host3", "02"],
["EDU", "120", "host4", "03"]
);
#
# Loop on the SAP systems
#
for $k ( @s ) {
#
# Check, that the sysytem is available
#
$stat = `./sapinfo -3 -h@$k[2] -s@$k[3] -g@$k[2] -xsapgw@$k[3] 2>/dev/null`;
if ($stat =~ /SAP/) {
#
# Get the data from the SAP system
# Customize the username and password
#
$data = `./rfc2abap -d@$k[0] -uusername -ppassword -c@$k[1] -h@$k[2] -s@$k[3]
-g@$k[2] -xsapgw@$k[3] -f zpoplog|grep -v Connected`;
}
else {
#
# When the system is down:
#
$data = "Q AAA - - - - - - - - &";
}
$sid = @$k[0];
@d = split /\s/, $data;
for ($x = 0; $x < @d; $x++) {
if (@d[$x] eq "Q") {
# Begin of table row
print "<tr>";
}
elsif (@d[$x] eq "@") {
# Empty cell
print "<td width=\"100\"></td>";
}
# End of table row
elsif (@d[$x] eq "&") {
print "</tr>";
}
else {
if ($x eq 2) {
# Set the status cell's color and text
if (@d[1] eq $sid){
$stat = "UP";
$color = "#00FF00";
}
else {
$stat = "DOWN";
$color = "#FF0000";
}
# Print the status cell
print "<td width=\"100\" bgcolor=$color align=\"center\">";
print "<small><small><small>$stat</small></small></small></td>";
}
if ($x eq 1) {
$string = $sid;
}
else {
$string = @d[$x];
}
# Print a regular cell
print "<td width=\"100\" bgcolor=\"#FFFFFF\" align=\"center\">";
print "<small><small><small>$string</small></small></small></td>";
}
}
}
print "</table>";
print "</BODY></HTML>";
The abap part, that retrieves the data from the SAP systems
Code:
REPORT ZPOPLOG NO STANDARD PAGE HEADING.
******************************************************************
* This abap is run by the system monitoring perl script
* to retrtieve the following data from the different SAP
* systems:
* system status (up/down), appservers, user number per appserver,
* session number per appserver, abap dump number today,
* today's error message number from the system log,
* number of active lock entries, number of pending updates
******************************************************************
TABLES: SNAP, VBHDR.
DATA: I TYPE I, C(5), J TYPE I, K TYPE I, L TYPE I, SUBRC LIKE SY-SUBRC.
DATA: MINTA(72) VALUE
'a b c d e f g h i j k l m n o p q r s t u w z x y * | '.
DATA: R(5), HOSTID(8), flag type i.
DATA: BEGIN OF TABTAB OCCURS 10,
line(128),
END OF TABTAB.
DATA: BEGIN OF SUMMARY OCCURS 50.
INCLUDE STRUCTURE SAPWLSUMRY.
DATA: END OF SUMMARY.
DATA: BEGIN OF ENQ OCCURS 50.
INCLUDE STRUCTURE SEQG3.
DATA: END OF ENQ.
DATA: BEGIN OF TAB OCCURS 10.
INCLUDE STRUCTURE ABAPLIST.
DATA: END OF TAB.
DATA: BEGIN OF LISTASCI OCCURS 10,
L(999),
END OF LISTASCI.
DATA: BEGIN OF LIST OCCURS 10.
INCLUDE STRUCTURE MSXXLIST.
DATA: END OF LIST.
DATA: BEGIN OF USR_TBL OCCURS 10.
INCLUDE STRUCTURE BTCSYSLOG.
DATA: END OF USR_TBL.
* System name
tabtab-line = 'Q'.
TABTAB-LINE+2 = SY-SYSID.
* The number of abap dumps
SELECT COUNT(*) INTO I FROM SNAP WHERE SEQNO = '001'
AND DATUM = SY-DATUM.
TABTAB-LINE+7(6) = I.
* The number of active lock entries
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
GCLIENT = '*'
GUNAME = '*'
GNAME = '*'
GARG = '*'
IMPORTING
SUBRC = SUBRC
TABLES
ENQ = ENQ.
DESCRIBE TABLE ENQ LINES J.
TABTAB-LINE+14(6) = J.
* Update records
SELECT COUNT(*) INTO K FROM VBHDR.
TABTAB-LINE+20(6) = K.
* Today's error messages from the system log
SUBMIT RSLG0001 WITH TR_DAY EQ '0'
LINE-SIZE 255 EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = TAB.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
LISTASCI = LISTASCI
LISTOBJECT = TAB.
LOOP AT LISTASCI.
IF LISTASCI CS '|K|' OR LISTASCI CS '|T|'.
L = L + 1.
ENDIF.
ENDLOOP.
TABTAB-LINE+26(6) = L.
CONDENSE TABTAB.
*APPEND TABTAB.
* Number of active users and modes per app. server
CALL FUNCTION 'TH_SERVER_LIST'
TABLES
LIST = LIST.
flag = 0.
LOOP AT LIST.
flag = flag + 1.
* Find out the average response time
HOSTID = LIST-HOST.
CALL FUNCTION 'SAPWL_GET_SUMMARY_STATISTIC'
EXPORTING
PERIODTYPE = 'D'
HOSTID = HOSTID
STARTDATE = SY-DATUM
TABLES
SUMMARY = SUMMARY.
LOOP AT SUMMARY.
IF SUMMARY-TASKTYPE = 'DIALOG'.
R = SUMMARY-RESPTI / SUMMARY-COUNT.
EXIT.
ENDIF.
ENDLOOP.
* Count the users and sessions
CLEAR USR_TBL.
REFRESH USR_TBL.
CALL FUNCTION 'SXMI_XMB_USER_LIST_READ_INT' DESTINATION LIST-NAME
TABLES
USR_TBL = USR_TBL.
LOOP AT USR_TBL.
IF USR_TBL CS 'users logged on with'.
TRANSLATE USR_TBL USING MINTA.
CONDENSE USR_TBL.
if flag > 1.
tabtab = 'Q @ @ @ @ @ @'.
endif.
TABTAB+27 = LIST-NAME.
TABTAB+48 = USR_TBL.
TABTAB+68 = R.
TABTAB+80 = '&'.
CONDENSE TABTAB.
APPEND TABTAB.
ENDIF.
ENDLOOP.
ENDLOOP.
*
LOOP AT TABTAB.
WRITE: / TABTAB.
ENDLOOP.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.