/*****************************************************************************/ /* HyperSpi.c This application generates VMS System Performance Information HTML documents. Coupled with 'HyperSpi$agent.c', the data-collection application, it can profile, complete with graphics, fundamental system performance indicators as CPU usage, memory usage, IO values. It operates in two distinct modes, text and graphic. In text mode it returns an HTML stream to the browser comprising a hypertext page, with selection menu, node performance presentation page, data listing or dump page. In graphic mode it returns a GIF image to the browser, first processing the specified data into an in-memory bitmap graph, then sending this image to the client via an internal GIF processor. A node preformance presentation page may have one or more HTML tags within it. Each of these tags will separately cause the browser to invoke the application to generate a graphic from the data specified in the SRC= URL. If the /NODES= qualifier specifies a comma-separated list of node names these are used in the menus for listing the available nodes. If this is not supplied the data directory is searched for current-day data files, those found have the respective node name extacted and these are used to list the nodes. The /STYLE= qualifier provide for a URL to a site-local style file. This allows the internal styles to be over-loaded. Button labels are customizable (potentially to non-English language). They comprise a label, equate symbol and URL-style path suitable for creating a link. Multiple buttons are separated using the semicolon. Note that any such button customization must provide escaped HTML-forbidden characters in the button label and URI-forbidden characters in the path! See DEFAULT_BUTTONS. Here is an example of changing the button labels: /BUTTON="Selector$Help=/hyperspi/-/hyperspi.html" Always have the equivalent of "Close" for the first button! Additional buttons may be created by adding "label=path;" elements to the button string. In this way an additional information page could be referenced as follows: /BUTTON="↶Back=javascript:parent.history.go(-1)$" + "Selector$^Help=/hyperspi/-/hyperspi.html$^Other VMS=/vms/" DIFFICULTY FITTING ALL THESE QUALIFIERS INTO A COMMAND LINE OR LOGICAL? Use an existing, or create a new, DCL wrapper procedure for the script (same name and directory) and build up a DCL symbol to provide the information. Up to 1024 characters can be included in this way. For example: $ HYPERSPI$PARAM = "/BUTTON=""Select$Help=/hyperspi/-/hyperspihelp.html""" $ HYPERSPI$PARAM = HYPERSPI$PARAM + "/STYLE=""/hyperspi/-/local.css""" $ RUN HT_EXE:HYPERSPI OSU ENVIRONMENT --------------- Script responses are returned in OSU "raw" mode; the script taking care of the full response header and correctly carriage-controlled data stream, text or binary!! Uses the CGILIB.C to engage in the dialog phase generating, storing and then making available the equivalent of CGI variables. "VANILLA" CGI ENVIRONMENT ------------------------- Primarily for the likes of Netscape FastTrack. This environment can accomodate CGI variables that are not prefixed with "WWW_" and do not supply "KEY_xxxxx" or "FORM_xxxxx" (which must be derived from "QUERY_STRING"). Full HTTP stream (non-parsed header) is assumed as not supported so all output occurs with a CGI-compliant header line (e.g. "Status: 200 Success") and record-oriented output. CGI VARIABLES ------------- FORM_BUFFERED_IO if non-null then buffered IO requested FORM_CPU if non-null then cpu usage requested FORM_DO what to do(!): "DUMP", "GRAPH", "LIST", "PAGE", "MENU" FORM_DAY the (first) day of the data file(s) FORM_DIRECT_IO if non-null then direct IO requested FORM_EXTRACT if non-null provide a link to allow graph extraction FORM_HOUR the (first) hour of the data FORM_INCLUDE additional category: PEAK, TOTAL (only with "user-mode-cpu"), HARD-FAULTS (only with "faults") FORM_LIST_NODE name of node to process data (see also FORM_NODE) FORM_MINUTE the (first) minute of the data FORM_MONTH the (first) month of the data file(s) FORM_MSCP_IO if non-null then MSCP IO requested FORM_NET_INT network interface traffic FORM_NODE name of node to process data (used before FORM_LIST_NODE) FORM_PERIOD standard period (e.g. "until" now, "business", "today", "yesterday", or since a number of days) FORM_REFRESH integer number of minutes between summary refreshes FORM_TODAY the last day of the data file(s) FORM_TOMINUTE the last minute of the data FORM_TOHOUR the last hour of the data FORM_TOMONTH the last month of the data file(s) FORM_TOYEAR the last year of the data file(s) FORM_USER_MODE_CPU if non-null then user-mode-cpu usage requested FORM_WHAT any data category can be placed in this comma-separated list FORM_XMAG number of times X axis should be enlarged FORM_YEAR the (first) year of the data file(s) FORM_YMAG number of times Y axis should be enlarged QUALIFIERS ---------- /BUTTONS= string containing button labels/paths /CHARSET= "Content-Type: text/html; charset=...", empty suppresses charset /DBUG turns on all "if (Debug)" statements /DIRECTORY= directory containing any node description HTML files /HELP= help HTML file URL /NODES= comma-separated list of node names collecting SPI data /SHUTDOWN causes the HYPERSPI$AGENT image/process to exit LOGICAL NAMES ------------- HYPERSPI$DATA locates the data files HYPERSPI$PARAM equivalent to (overrides) the command line parameters/qualifiers (define as a system-wide logical) BUILD DETAILS ------------- See BUILD_HYPERSPI.COM procedure. COPYRIGHT --------- Copyright (C) 1995-2021 Mark G.Daniel Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. VERSION HISTORY (update SOFTWAREVN as well!) --------------- 14-OCT-2014 MGD v2.1.0, a nod to the twenty-first century 21-MAY-2011 MGD v2.0.0, add network interface data data format version 3 (shared with HyperSPI++) (There is a lot of work that *could* be done to this older piece of code but I've spent the minimal time necessary just to make it work on modern platforms.) plus a few tweaks (couldn't resist :-) 10-MAY-2005 MGD v1.8.4, SWS 2.0 ignore query string components supplied as command-line parameters differently to CSWS 1.2/3 23-DEC-2003 MGD v1.8.3, minor conditional mods to support IA64 12-APR-2003 MGD v1.8.2, link colour changed to 0000cc 16-AUG-2002 MGD v1.8.1, some accomodations for CSWS v1.2 09-SEP-2001 MGD v1.8.0, provide /SHUTDOWN for the agent via $FORCEX 01-JUL-2001 MGD v1.7.1, add 'SkipParameters' for direct OSU support 28-OCT-2000 MGD v1.7.0, use CGILIB object module 12-APR-2000 MGD v1.6.1, minor changes for CGILIB 1.4 07-AUG-1999 MGD v1.6.0, use more of the CGILIB functionality 24-APR-1999 MGD v1.5.0, use CGILIB.C, standard CGI environment (Netscape FastTrack), modify to use CgiVar() 02-OCT-1998 MGD v1.4.0, provide content-type "; charset=..." 13-AUG-1998 MGD v1.3.0, accomodations for OSU bugfix; IncludeFile() file name length 13-AUG-1998 MGD NOTE: this application is not Y2K compliant (in the sense data is stored in files named with a 2 digit year!) 06-MAY-1998 MGD v1.2.0, general maintenance, cosmetic changes 11-SEP-1997 MGD v1.1.1, upped MAX_NODE_COUNT_BEFORE_SELECT to 20 01-AUG-1997 MGD v1.1.0, added /BODY= qualifier, remove extraneous '/' from , general maintenance 19-SEP-1995 MGD v1.0.1, replace carriage-control single newline, still acceptable for HTTP, slightly more efficient 20-JUN-1995 MGD v1.0.0, initial development */ /*****************************************************************************/ #define SOFTWAREVN "2.1.0" #define SOFTWARENM "HYPERSPI" #define SOFTWARECR "Copyright (C) 1996-2020 Mark G.Daniel" #ifdef __ALPHA # define SOFTWAREID SOFTWARENM " AXP-" SOFTWAREVN #endif #ifdef __ia64 # define SOFTWAREID SOFTWARENM " IA64-" SOFTWAREVN #endif #ifdef __VAX # define SOFTWAREID SOFTWARENM " VAX-" SOFTWAREVN #endif #ifdef __x86_64 # define SOFTWAREID SOFTWARENM " X86-" SOFTWAREVN #endif /* standard C header files */ #include #include #include #include #include #include #include #include #include /* VMS related header files */ #include #include #include #include #include #include #include #include #include /* application header file */ #include "HyperSpi.h" #include #ifndef __VAX # pragma nomember_alignment #endif #define boolean int #define true 1 #define false 0 #define VMSok(x) ((x) & STS$M_SUCCESS) #define VMSnok(x) !(((x) & STS$M_SUCCESS)) #define FI_LI __FILE__, __LINE__ /* for use by functions in PlotSpi.c */ #define PLOT_ON 0 #define PLOT_OFF 1 #define PLOT_XOR 2 #define MAX_SAMPLE_PERIOD_DAYS 31 #define MAX_NODE_COUNT_BEFORE_SELECT 20 #define DEFAULT_BUTTONS "\ ↶Back=javascript:parent.history.go(-1)$Selector$\ ^Help=/hyperspi/-/hyperspi.html\ " #define DEFAULT_STYLE "\ body { margin:0.5em; background-color:white; color:black; \ font-family:sans-serif; }\n\ a { text-decoration:none; color:black; \ border:1px solid slategray; border-radius:3px; padding:1px 5px 2px 5px; }\n\ .header { padding:0.5em 0.5em 0.5em 1em; background-color: gainsboro; \ border:1px solid lightslategray; border-radius:1px; \ font-size: 140%; font-weight: bold; word-spacing:0.2em; }\n\ .buttonbar { padding:0.7em 1em 0.7em 1em; \ border:1px solid lightslategray; border-radius:1px; \ background-color: gainsboro; min-height:1.3em; }\n\ .buttonbar a { text-decoration:none; color:inherit; \ border:1px solid slategray; border-radius:3px; padding:1px 5px 2px 5px; }\n\ .hyperSPI { display:table-cell; \ font-family: futura, \"Tw Cen MT\", helvetica, arial, sans; \ font-weight:normal; font-size:125%; letter-spacing:-2px; }\n\ .heading { display:table-cell; width:95%; text-align:center; \ font-size:110%; }\n\ .datetime { display:table-cell; white-space:nowrap; font-size:80%; \ word-spacing:0px; }\n\ .content { margin:1.5em; }\n\ .precis { margin:0.5em 1em 0.5em 2em; }\n\ .precis th { text-align:right; }\n\ .precis td { text-align:left; }\n\ .graph { margin:0.5em; }\n\ .graphtitle { margin:1em 0.5em 0.5em 0.5em; font-size:120%; font-weight:bold; \ text-decoration:underline; }\n\ .graphdata { margin:1em 1em 1em 2em; }\n\ .fileday { margin-bottom:1em; font-size:120%; font-weight:bold; }\n\ .filename { font-family:monospace; font-size:120%; }\n\ .extrbtn { margin-left:2em; background-color:whitesmoke; font-size:80%; }\n\ " char Utility [] = "HYPERSPI"; char *DayName [] = { "", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", }; char *MonthName [] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; boolean Debug, DoDump, DoGraph, DoList, DoComprehensiveMenu, DoShutdownAgent, DoSummaryMenu, DoPresentSummaryPage, ErrorReported, ExtractGraph, GifTransparentBackground = true, HttpHasBeenOutput, IncludePeak, IncludeTotal, ProvidePercentCPU, ProvidePercentUserModeCPU, ProvideBufferedIO, ProvidePeakBufferedIO, ProvideDirectIO, ProvidePeakDirectIO, ProvideMemory, ProvideMscpIO, ProvidePeakMscpIO, ProvideNetInt, ProvidePeakNetInt, ProvidePageFaults, ProvidePeakPageFaults, ProvideHardPageFaults, ProvidePeakHardPageFaults, ProvideProcesses, OsuEnvironment, StdCgiEnvironment; int AvePercentCPU, AvePercentUserModeCPU, AveBufferedIO, AveDirectIO, AveLck, AveLckIn, AveLckOut, AveLckLoc, AveMscpIO, AveNetIntRxTx, AveNumberOfCom, AvePageFaults, AveHardPageFaults, AveNumberOfProcesses, AveSystemMemoryPercentInUse, AvePageSpacePercentInUse, CurrentJulianDate, CurrentMinuteFromStartOfPeriod, DataFileNameLength, DataFileSpecLength, DataFilesFoundCount, DataFilesProcessedCount, DataRecordsReadCount, DataRecordsProcessedCount, DataMinute, DataHour, DataDay, DataMonth, DataYear, FromJulianDate, FromDay, FromHour, FromMinute, FromMonth, FromYear, HaveDataY, MaxAveBufferedIO, MaxAveDirectIO, MaxAveMscpIO, MaxAveNetIntRxTx, MaxAvePageFaults, MaxAveHardPageFaults, MaxNumberOfCom, MaxNumberOfProcesses, MaxPageSpacePercentInUse, MaxSystemMemoryPercentInUse, NodeCount, NumberOfCPUs, NumberOfDays, NumberOfDaysIntoData, NumberOfHours, NumberOfMinutesIntoData, NumberOfProcesses, PageSpaceMBytes, PageSpacePercentInUse, PeakPercentUserModeCPU, PeakBufferedIO, PeakDirectIO, PeakMscpIO, PeakPageFaults, PeakNetIntRxTx, PeakPercentCPU, PeakHardPageFaults, PercentCPU, PercentUserModeCPU, RecordSampleRate, RefreshSeconds = 0, SizeOfMarginX = 10, SizeOfMarginY = 20, SizeOfPlotX, SizeOfPlotY, StartMinuteOnFirstDay, StartMinuteOfData, SystemMemoryMBytes, SystemMemoryPercentInUse, ToJulianDate, ToMinute, ToHour, ToDay, ToMonth, ToYear, XMag, YMag; #ifndef __VAX unsigned __int64 NetIntRxTx; #else unsigned int NetIntRxTx; #endif unsigned int AvePercentModeCPU[HYPERSPI_CPU_MODE_COUNT]; float ScalingFactorY; char DataFileName [256], DataFileSpec [256], DataNode [32], DateString [32], DefaultButtons [] = DEFAULT_BUTTONS, FileSpecification [256], HyperSpiUrl [256], SoftwareID [48], ToDateString [32], UnixDateTime [64]; char *ButtonsPtr = DefaultButtons, *CgiEnvironmentPtr, *CgiFormDoPtr, *CgiFormIncludePtr, *CgiFormNodePtr, *CgiFormPeriodPtr, *CgiFormRefreshPtr, *CgiFormWhatPtr, *CgiRequestMethodPtr, *CgiPathInfoPtr, *CgiPathTranslatedPtr, *CgiScriptNamePtr, *CgiServerNamePtr, *CgiServerSoftwarePtr, *CliCharsetPtr, *DefaultStyle = DEFAULT_STYLE, *HyperSpiDirectoryPtr = "HYPERSPI$DATA:", *SelectorPtr, *SoftwareCopy = SOFTWARECR, *StyleSheetPtr = ""; char SpiNodeNames [16][16] = { "" }; unsigned long CurrentBinTime [2]; unsigned short CurrentNumTime [7]; /* this structure is declared in HyperSpi.h */ struct HyperSpiData SpiRecord; /* external storage (declared in PlotSpi.c) */ extern boolean DoPlotDiagnostic; extern int PixelPlotOperation, PlotScaleY; /* function prototypes for graphing (from PlotSpi.c) */ int PlotAllocate (int XSize, int YSize); int PlotAxes (int Operation); int PlotPixel (int Operation, int AtX, int AtY, int XOrigin, int YOrigin); int PlotLineX (int Operation, int FromX, int ToX, int AtY, int XOrigin, int YOrigin); int PlotLineY (int Operation, int FromY, int ToY, int AtX, int XOrigin, int YOrigin); /* required function prototypes */ char* ButtonBarButton (char*, char*); void DumpData(); void DumpRecord(); void ListProcessedRecord(); int GraphImageLink (int, char*, char*, ...); int GraphRecordCPU(); int GraphRecordMemory(); int GraphRecordProcesses(); int GraphRecordRange(); int ProvideScaling (); void SetScaling (int); int SelectNodeNameByDataFileName(); void SummarizeRecord(); char* SystemNodeName (); char* UniqueNumber(); /*****************************************************************************/ /* 'argc/argv' are only required to support OSU, in particular CgiLibOsuInit(). */ main ( int argc, char *argv[] ) { int status; unsigned long UnixTime; struct tm *UnixTmPtr; /*********/ /* begin */ /*********/ sprintf (SoftwareID, "%s (%s)", SOFTWAREID, CgiLibEnvironmentVersion()); if (getenv ("HYPERSPI$DBUG") != NULL) { Debug = true; fputs ("Content-Type: text/plain\n\n", stdout); CgiLibEnvironmentSetDebug (Debug); } CgiLibEnvironmentInit (argc, argv, false); CgiEnvironmentPtr = CgiLibEnvironmentName (); GetParameters (); if (DoShutdownAgent) exit (ShutdownAgent()); CgiLibResponseSetCharset (CliCharsetPtr); CgiLibResponseSetSoftwareID (SoftwareID); CgiLibResponseSetErrorMessage ("Reported by HyperSPI"); if (StyleSheetPtr[0]) { char *cptr = calloc (1, 64+strlen(StyleSheetPtr)); sprintf (cptr, "\n", StyleSheetPtr); StyleSheetPtr = cptr; } CgiServerSoftwarePtr = CgiVar ("WWW_SERVER_SOFTWARE"); CgiRequestMethodPtr = CgiVar ("WWW_REQUEST_METHOD"); if (strcmp (CgiRequestMethodPtr, "GET")) { CgiLibResponseHeader (501, "text/html"); fprintf (stdout, "Not implemented!\n"); return; } CgiScriptNamePtr = CgiVar ("WWW_SCRIPT_NAME"); CgiServerNamePtr = CgiVar ("WWW_SERVER_NAME"); sys$gettim (&CurrentBinTime); sys$numtim (&CurrentNumTime, &CurrentBinTime); time (&UnixTime); UnixTmPtr = localtime (&UnixTime); if (!strftime (UnixDateTime, sizeof(UnixDateTime), "%a, %d %b %Y %T", UnixTmPtr)) strcpy (UnixDateTime, "[error]"); if (Debug) fprintf (stdout, "UnixDateTime |%s|\n", UnixDateTime); GetRequest (); ValidateRequest (); if (DoSummaryMenu || DoComprehensiveMenu) { SummaryMenu (); exit (SS$_NORMAL); } /* create file specification for processing data */ DataFileSpecLength = sprintf (DataFileSpec, "%sHYPERSPI_%s_%s_%%%%%%%%%%%%.DAT", HYPERSPI_DATA_DIRECTORY, HYPERSPI_DATA_VERSION, CgiFormNodePtr); if (Debug) fprintf (stdout, "DataFileSpec |%s|\n", DataFileSpec); if (DoPresentSummaryPage) PresentSummaryPage (); else if (DoDump) DumpData (); else if (DoGraph) GraphData (); else if (DoList) ListProcessedData (); exit (SS$_NORMAL); } /*****************************************************************************/ /* Get "command-line" parameters, whether from the command-line or from a configuration symbol or logical containing the equivalent. OSU scripts have the 'method', 'url' and 'protocol' supplied as P1, P2, P3 (these being detected and used by CGILIB), and are of no interest to this function. */ GetParameters () { static char CommandLine [256]; static unsigned long Flags = 0; int idx, status, SkipParameters; unsigned short Length; char ch; char *aptr, *cptr, *clptr, *sptr; $DESCRIPTOR (CommandLineDsc, CommandLine); /*********/ /* begin */ /*********/ if ((clptr = getenv ("HYPERSPI$PARAM")) == NULL) { /* get the entire command line following the verb */ if (VMSnok (status = lib$get_foreign (&CommandLineDsc, 0, &Length, &Flags))) exit (status); (clptr = CommandLine)[Length] = '\0'; } /* if [C]SWS (VMS Apache) */ if (CgiLibEnvironmentIsApache()) { /* CSWS 1.2/3 look for something non-space outside of quotes */ for (cptr = clptr; *cptr; cptr++) { if (isspace(*cptr)) continue; if (*cptr != '\"') break; cptr++; while (*cptr && *cptr != '\"') cptr++; if (*cptr) cptr++; } /* CSWS 1.2/3 if nothing outside of quotes then ignore command line */ if (!*cptr) return; /* SWS 2.0 doesn't begin with /APACHE from DCL procedure wrapper */ if (!strsame (cptr, "/APACHE", 7)) return; } /* if OSU environment then skip P1, P2, P3 */ if (CgiLibEnvironmentIsOsu()) SkipParameters = 3; else SkipParameters = 0; aptr = NULL; ch = *clptr; for (;;) { if (aptr != NULL) *aptr = '\0'; if (!ch) break; *clptr = ch; if (Debug) fprintf (stdout, "clptr |%s|\n", clptr); while (*clptr && isspace(*clptr)) *clptr++ = '\0'; aptr = clptr; if (*clptr == '/') clptr++; while (*clptr && !isspace (*clptr) && *clptr != '/') { if (*clptr != '\"') { clptr++; continue; } cptr = clptr; clptr++; while (*clptr) { if (*clptr == '\"') if (*(clptr+1) == '\"') clptr++; else break; *cptr++ = *clptr++; } *cptr = '\0'; if (*clptr) clptr++; } ch = *clptr; if (*clptr) *clptr = '\0'; if (Debug) fprintf (stdout, "aptr |%s|\n", aptr); if (!*aptr) continue; if (SkipParameters) { SkipParameters--; continue; } if (strsame (aptr, "/APACHE", 4)) { /* just skip this marker for command-line parameters under SWS 2.0 */ continue; } if (strsame (aptr, "/BUTTONS=", 4)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; ButtonsPtr = cptr; continue; } if (strsame (aptr, "/CHARSET=", 4)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; CliCharsetPtr = cptr; continue; } if (strsame (aptr, "/DBUG", -1)) { Debug = true; continue; } if (strsame (aptr, "/DIRECTORY=", 3)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; HyperSpiDirectoryPtr = cptr; continue; } if (strsame (aptr, "/NODES=", 3)) { for (cptr = aptr; *cptr && *cptr != '='; cptr++); if (*cptr) cptr++; /* quick and nasty, no checks on array bounds (caveat emptor) */ idx = 0; while (*cptr) { sptr = SpiNodeNames[idx++]; while (*cptr && *cptr != ',') *sptr++ = toupper(*cptr++); *sptr = '\0'; if (*cptr) cptr++; } SpiNodeNames[idx][0] = '\0'; continue; } if (strsame (aptr, "/SHUTDOWN", 3)) { DoShutdownAgent = true; continue; } if (*aptr != '/') { fprintf (stdout, "%%%s-E-MAXPARM, too many parameters\n \\%s\\\n", Utility, aptr); exit (STS$K_ERROR | STS$M_INHIB_MSG); } else { fprintf (stdout, "%%%s-E-IVQUAL, unrecognized qualifier\n \\%s\\\n", Utility, aptr+1); exit (STS$K_ERROR | STS$M_INHIB_MSG); } } } /*****************************************************************************/ /* Create the navigation buttons. */ ButtonBar (int Top1Bottom2) { int idx; char *cptr, *sptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ButtonBar()\n"); fprintf (stdout, "
\n", Top1Bottom2 == 1 ? " butbartop" : ""); cptr = ButtonsPtr; /* back */ cptr = ButtonBarButton (cptr, NULL); /* calendar request form */ cptr = ButtonBarButton (cptr, CgiScriptNamePtr); /* any further buttons */ while (*cptr) cptr = ButtonBarButton (cptr, NULL); fprintf (stdout, "
\n"); } /*****************************************************************************/ /* Generate a single "button" inside the context created by ButtonBar(). */ char* ButtonBarButton ( char *ButtonLabel, char *ButtonPath ) { char *cptr, *sptr, *tptr, *uptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ButtonBarButton() |%s|\n", ButtonLabel); if (!*ButtonLabel) for (cptr = ButtonLabel = "*ERROR*"; *cptr; cptr++); else for (cptr = ButtonLabel; *cptr && *cptr != '=' && *cptr != '$'; cptr++); if (*ButtonLabel == '^') { ButtonLabel++; tptr = " target=\"_blank\""; } else tptr = ""; if (*cptr == '=') for (sptr = uptr = cptr+1; *sptr && *sptr != '$'; sptr++); else if (ButtonPath) sptr = (uptr = ButtonPath) + strlen(ButtonPath); else sptr = (uptr = "*ERROR*") + 8; if (!memcmp(uptr,"javascript:", 11)) fprintf (stdout, "\n", tptr, sptr-uptr, sptr-uptr, uptr, cptr-ButtonLabel, cptr-ButtonLabel, ButtonLabel); else fprintf (stdout, "%*.*s\n", tptr, sptr-uptr, sptr-uptr, uptr, cptr-ButtonLabel, cptr-ButtonLabel, ButtonLabel); while (*cptr && *cptr != '$') cptr++; while (*cptr && *cptr == '$') cptr++; return (cptr); } /*****************************************************************************/ /* Get the request CGI variables. */ GetRequest () { char *cptr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "GetRequest()\n"); /* determine what has been requested */ CgiFormWhatPtr = CgiVar ("WWW_FORM_WHAT"); for (cptr = CgiFormWhatPtr; *cptr; cptr++) *cptr = toupper(*cptr); CgiFormRefreshPtr = CgiVar ("WWW_FORM_REFRESH"); RefreshSeconds = atoi(CgiFormRefreshPtr) * 60; if (RefreshSeconds < 0 || RefreshSeconds > 3600) RefreshSeconds = 0; if (strsame (CgiFormWhatPtr, "CPU", -1)) ProvidePercentCPU = true; if (strstr (CgiFormWhatPtr, ",CPU") != NULL) ProvidePercentCPU = true; cptr = CgiVar ("WWW_FORM_CPU"); if (cptr[0]) ProvidePercentCPU = true; if (strstr (CgiFormWhatPtr, "USER_MODE") != NULL) ProvidePercentUserModeCPU= true; cptr = CgiVar ("WWW_FORM_USER_MODE_CPU"); if (cptr[0]) ProvidePercentUserModeCPU = true; if (strstr (CgiFormWhatPtr, "BUFFERED") != NULL) ProvideBufferedIO = true; cptr = CgiVar ("WWW_FORM_BUFFERED_IO"); if (cptr[0]) ProvideBufferedIO = true; if (strstr (CgiFormWhatPtr, "PEAK_BUFFERED") != NULL) ProvidePeakBufferedIO = true; cptr = CgiVar ("WWW_FORM_PEAK_BUFFERED_IO"); if (cptr[0]) ProvidePeakBufferedIO = true; if (strstr (CgiFormWhatPtr, "DIRECT") != NULL) ProvideDirectIO = true; cptr = CgiVar ("WWW_FORM_DIRECT_IO"); if (cptr[0]) ProvideDirectIO = true; if (strstr (CgiFormWhatPtr, "PEAK_DIRECT") != NULL) ProvidePeakDirectIO = true; cptr = CgiVar ("WWW_FORM_PEAK_DIRECT_IO"); if (cptr[0]) ProvidePeakDirectIO = true; if (strstr (CgiFormWhatPtr, "MSCP") != NULL) ProvideMscpIO = true; cptr = CgiVar ("WWW_FORM_MSCP_IO"); if (cptr[0]) ProvideMscpIO = true; if (strstr (CgiFormWhatPtr, "PEAK_MSCP") != NULL) ProvidePeakMscpIO = true; cptr = CgiVar ("WWW_FORM_PEAK_MSCP_IO"); if (cptr[0]) ProvidePeakMscpIO = true; if (strstr (CgiFormWhatPtr, "NET_INT") != NULL) ProvideNetInt = true; cptr = CgiVar ("WWW_FORM_NET_INT"); if (cptr[0]) ProvideNetInt = true; if (strstr (CgiFormWhatPtr, "PEAK_NET_INT") != NULL) ProvidePeakNetInt = true; cptr = CgiVar ("WWW_FORM_PEAK_NET_INT"); if (cptr[0]) ProvidePeakNetInt = true; if (strstr (CgiFormWhatPtr, "FAULTS") != NULL) ProvidePageFaults = true; cptr = CgiVar ("WWW_FORM_FAULTS"); if (cptr[0]) ProvidePageFaults = true; if (strstr (CgiFormWhatPtr, "PEAK_FAULTS") != NULL) ProvidePeakHardPageFaults = true; cptr = CgiVar ("WWW_FORM_PEAK_FAULTS"); if (cptr[0]) ProvidePeakPageFaults = true; if (strstr (CgiFormWhatPtr, "HARD_FAULTS") != NULL) ProvideHardPageFaults = true; cptr = CgiVar ("WWW_FORM_HARD_FAULTS"); if (cptr[0]) ProvideHardPageFaults = true; if (strstr (CgiFormWhatPtr, "PEAK_HARD_FAULTS") != NULL) ProvidePeakHardPageFaults = true; cptr = CgiVar ("WWW_FORM_PEAK_HARD_FAULTS"); if (cptr[0]) ProvidePeakHardPageFaults = true; if (strstr (CgiFormWhatPtr, "MEMORY") != NULL) ProvideMemory = true; cptr = CgiVar ("WWW_FORM_MEMORY"); if (cptr[0]) ProvideMemory = true; if (strstr (CgiFormWhatPtr, "PROCESSES") != NULL) ProvideProcesses = true; cptr = CgiVar ("WWW_FORM_PROCESSES"); if (cptr[0]) ProvideProcesses = true; CgiFormIncludePtr = CgiVar ("WWW_FORM_INCLUDE"); for (cptr = CgiFormIncludePtr; *cptr; cptr++) *cptr = toupper(*cptr); if (strstr (CgiFormIncludePtr, "PEAK") != NULL) IncludePeak = true; if (strstr (CgiFormIncludePtr, "TOTAL") != NULL) IncludeTotal = true; cptr = CgiVar ("WWW_FORM_FROM"); sscanf (cptr, "%4d-%2d-%2d %2d:%2d", &FromYear, &FromMonth, &FromDay, &FromHour, &FromMinute); cptr = CgiVar ("WWW_FORM_TO"); sscanf (cptr, "%4d-%2d-%2d %2d:%2d", &ToYear, &ToMonth, &ToDay, &ToHour, &ToMinute); CgiFormDoPtr = CgiVar ("WWW_FORM_DO"); CgiFormNodePtr = CgiVar ("WWW_FORM_NODE"); if (!CgiFormNodePtr[0]) CgiFormNodePtr = CgiVar ("WWW_FORM_LIST_NODE"); if (!CgiFormNodePtr[0]) CgiFormNodePtr = SystemNodeName(); if (CgiFormNodePtr[0]) { /* ensure the node name is in upper case */ for (cptr = CgiFormNodePtr; *cptr; cptr++) *cptr = toupper(*cptr); } cptr = CgiVar ("WWW_FORM_EXTRACT"); if (cptr[0]) ExtractGraph = true; CgiFormPeriodPtr = CgiVar ("WWW_FORM_PERIOD"); cptr = CgiVar ("WWW_FORM_XMAG"); if (isdigit(cptr[0])) XMag = atoi (cptr); else XMag = 1; if (XMag > 4) XMag = 4; if (XMag < 1) XMag = 1; cptr = CgiVar ("WWW_FORM_YMAG"); if (isdigit(cptr[0])) YMag = atoi (cptr); else YMag = 1; if (YMag > 4) YMag = 4; if (YMag < 1) YMag = 1; } /*****************************************************************************/ /* Process the request parameters (e.g. time, node name). Verify the parameters are within constraints, particular time. Process the time components into values the application can use. */ ValidateRequest () { static long LibJulianDate = LIB$K_JULIAN_DATE; static char *MonthName [] = { "???", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; int status; unsigned long BinTime [2], DeltaTime [2]; unsigned short NumTime [7]; char Scratch [256]; $DESCRIPTOR (TempDsc, ""); /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "ValidateRequest()\n"); if (!CgiFormDoPtr[0]) DoSummaryMenu = true; else if (toupper(CgiFormDoPtr[0]) == 'G') DoGraph = true; else if (toupper(CgiFormDoPtr[0]) == 'P') DoPresentSummaryPage = true; else if (toupper(CgiFormDoPtr[0]) == 'C') DoComprehensiveMenu = true; else if (toupper(CgiFormDoPtr[0]) == 'M') DoSummaryMenu = true; else if (toupper(CgiFormDoPtr[0]) == 'D') DoDump = true; else if (toupper(CgiFormDoPtr[0]) == 'L') DoList = true; else { sprintf (Scratch, "Cannot do \"%s\"", CgiFormDoPtr); CgiLibResponseError (FI_LI, 0, Scratch); exit (SS$_NORMAL); } if ((DoPresentSummaryPage || DoGraph || DoList || DoDump) && !CgiFormNodePtr[0]) { CgiLibResponseError (FI_LI, 0, "Node name not specified."); exit (SS$_NORMAL); } /********************/ /* standard periods */ /********************/ if (CgiFormPeriodPtr[0] && toupper(CgiFormPeriodPtr[0]) != 'O') { /* a standard time period has been specified, other than "other" */ FromHour = 0; FromMinute = 0; ToHour = 23; ToMinute = 59; FromDay = ToDay = CurrentNumTime[2]; FromMonth = ToMonth = CurrentNumTime[1]; FromYear = ToYear = CurrentNumTime[0]; if (toupper(CgiFormPeriodPtr[0]) == 'U') { /* "until_now" (7am to this hour) */ FromHour = 7; ToHour = CurrentNumTime[3]; } else if (toupper(CgiFormPeriodPtr[0]) == 'B') { /* "business" hours (7am to 7pm) */ FromHour = 7; ToHour = 18; } else if (toupper(CgiFormPeriodPtr[0]) == 'T') { /* "today" */ ToHour = 23; } else if (toupper(CgiFormPeriodPtr[0]) == 'S' || toupper(CgiFormPeriodPtr[0]) == 'Y') { /* "since_yesterday" until now, or all of "yesterday" */ TempDsc.dsc$a_pointer = "1 00:00:00.00"; TempDsc.dsc$w_length = 13; if (VMSnok (status = sys$bintim (&TempDsc, &DeltaTime))) { CgiLibResponseError (FI_LI, status, CgiFormPeriodPtr); exit (SS$_NORMAL); } lib$sub_times (&CurrentBinTime, &DeltaTime, &BinTime); sys$numtim (&NumTime, &BinTime); FromDay = NumTime[2]; FromMonth = NumTime[1]; FromYear = NumTime[0]; if (toupper(CgiFormPeriodPtr[0]) == 'S') ToHour = CurrentNumTime[3]; else { ToDay = NumTime[2]; ToMonth = NumTime[1]; ToYear = NumTime[0]; } } else if (isdigit(CgiFormPeriodPtr[0])) { TempDsc.dsc$a_pointer = Scratch; TempDsc.dsc$w_length = sprintf (Scratch, "%s 00:00:00.00", CgiFormPeriodPtr); if (VMSnok (status = sys$bintim (&TempDsc, &DeltaTime))) { CgiLibResponseError (FI_LI, status, CgiFormPeriodPtr); exit (SS$_NORMAL); } lib$sub_times (&CurrentBinTime, &DeltaTime, &BinTime); sys$numtim (&NumTime, &BinTime); FromDay = NumTime[2]; FromMonth = NumTime[1]; FromYear = NumTime[0]; } else { CgiLibResponseError (FI_LI, 0, "Periods are \"until_now\""); exit (SS$_NORMAL); } } /*******************/ /* time components */ /*******************/ /* non-specified date components default to those of the current day */ if (!FromDay) FromDay = CurrentNumTime[2]; if (!FromMonth) FromMonth = CurrentNumTime[1]; if (!FromYear) FromYear = CurrentNumTime[0]; if (!ToDay) ToDay = CurrentNumTime[2]; if (!ToMonth) ToMonth = CurrentNumTime[1]; if (!ToYear) ToYear = CurrentNumTime[0]; /* bit of a sanity check (prevents 'MonthName[x]' access violating, etc.) */ if (FromMonth < 1 || FromMonth > 12) FromMonth = 0; if (ToMonth < 1 || ToMonth > 12) ToMonth = 0; /* ensure the commencement date/time is acceptable */ TempDsc.dsc$a_pointer = DateString; TempDsc.dsc$w_length = sprintf (DateString, "%d-%s-%d %02.02d:%02.02d", FromDay, MonthName[FromMonth], FromYear, FromHour, FromMinute); if (Debug) fprintf (stdout, "DateString |%s|\n", DateString); if (VMSnok (status = sys$bintim (&TempDsc, &BinTime))) { sprintf (Scratch, "%02.02d:%02.02d %02.02d/%02.02d/%02.02d", FromHour, FromMinute, FromDay, FromMonth, FromYear); CgiLibResponseError (FI_LI, status, Scratch); exit (SS$_NORMAL); } /* get the commencement julian date (number of days in epoch) */ lib$cvt_from_internal_time (&LibJulianDate, &FromJulianDate, &BinTime); /* ensure the conclusion date/time is acceptable */ TempDsc.dsc$a_pointer = ToDateString; TempDsc.dsc$w_length = sprintf (ToDateString, "%d-%s-%d %02.02d:%02.02d", ToDay, MonthName[ToMonth], ToYear, ToHour, ToMinute); if (Debug) fprintf (stdout, "ToDateString |%s|\n", ToDateString); if (VMSnok (status = sys$bintim (&TempDsc, &BinTime))) { sprintf (Scratch, "%02.02d:%02.02d %02.02d/%02.02d/%02.02d", ToHour, ToMinute, ToDay, ToMonth, ToYear); CgiLibResponseError (FI_LI, status, Scratch); exit (SS$_NORMAL); } /* get the conclusion julian date (number of days in epoch) */ lib$cvt_from_internal_time (&LibJulianDate, &ToJulianDate, &BinTime); /***************************/ /* calculate period values */ /***************************/ /* using julian dates, get number of days and hours sample period covers */ NumberOfHours = ((ToJulianDate - FromJulianDate) * 24) + ToHour - FromHour; NumberOfDays = (NumberOfHours / 24); if (DoPresentSummaryPage || DoGraph || DoList || DoDump) { if (NumberOfHours < 0 || (NumberOfHours == 0 && ToMinute <= FromMinute)) { sprintf (Scratch, "Beginning of period (%04.04d-%02.02d-%02.02d %02.02d:%02.02d) \ does not precede end (%04.04d-%02.02d-%02.02d %02.02d:%02.02d)!", FromYear, FromMonth, FromDay, FromHour, FromMinute, ToYear, ToMonth, ToDay, ToHour, ToMinute); CgiLibResponseError (FI_LI, 0, Scratch); exit (SS$_NORMAL); } if (NumberOfHours < 1) { CgiLibResponseError (FI_LI, 0, "Little point to such a short period!"); exit (SS$_NORMAL); } if (NumberOfDays > MAX_SAMPLE_PERIOD_DAYS) { sprintf (Scratch, "Maximum sample period is %d days.", MAX_SAMPLE_PERIOD_DAYS); CgiLibResponseError (FI_LI, 0, Scratch); exit (SS$_NORMAL); } } /* rate at which the data (and any graphic) must be X-axis compressed */ if (NumberOfHours <= 12) RecordSampleRate = 1; else if (NumberOfHours <= 24) RecordSampleRate = 2; else RecordSampleRate = (NumberOfDays + 1) * 2; /* add one to number of hours, for graphing purposes, re-calculate days */ NumberOfHours++; NumberOfDays = (NumberOfHours / 24); /* the number of minutes from midnight data begins being processed */ StartMinuteOnFirstDay = (FromHour * 60) + FromMinute; /* the current minute from the start of the specified period */ lib$cvt_from_internal_time (&LibJulianDate, &CurrentJulianDate, &CurrentBinTime); CurrentMinuteFromStartOfPeriod = ((((CurrentJulianDate - FromJulianDate) * 24) + (CurrentNumTime[3] - FromHour)) * 60) + CurrentNumTime[4]; if (Debug) fprintf (stdout, "FromJulianDate: %d ToJulianDate: %d\n\ NumberOfDays: %d NumberOfHours: %d RecordSampleRate: %d\n", FromJulianDate, ToJulianDate, NumberOfDays, NumberOfHours, RecordSampleRate); } /*****************************************************************************/ /* Provide either a standard or comprehensive menu allowing System Performance Information system, category and period to be specified. */ SummaryMenu () { char *CheckedPtr, *TodayCheckedPtr, *UntilNowCheckedPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SummaryMenu()\n"); if (DoComprehensiveMenu) CheckedPtr = ""; else CheckedPtr = " checked"; CgiLibResponseHeader (200, "text/html"); fprintf (stdout, "\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ HyperSPI, Summary Selector\n\ \n\ %s\ \n\ \n", SoftwareID, SoftwareCopy, CgiEnvironmentPtr, UnixDateTime, DefaultStyle, StyleSheetPtr); fprintf (stdout, "
\
HyperSPI
\
Summary Selector
\
%d %s %d %0.2d:%0.2d
\
\n", CurrentNumTime[2], MonthName[CurrentNumTime[1]], CurrentNumTime[0], CurrentNumTime[3], CurrentNumTime[4]); HttpHasBeenOutput = true; fprintf (stdout, "
\n\
\n", CgiScriptNamePtr); SelectNodeNames (); if (DoComprehensiveMenu) { fputs ( "  or ... node \
", stdout); } if (CurrentNumTime[3] >= 7) { UntilNowCheckedPtr = " checked"; TodayCheckedPtr = ""; } else { UntilNowCheckedPtr = ""; TodayCheckedPtr = " checked"; } fprintf (stdout, "

\n\ \ since 7am (until now)
\ today
\n\ \ since yesterday (until now)
\n\ yesterday
\n\ previous week  \n\ two weeks  \n\ four weeks
\n\ \n\ \ from\n\ \ to\n\ \  (yyyy-mm-dd hh:mm)\n\ \n\

\n\ cpu
\n\ memory
\n\ processes
\n", UntilNowCheckedPtr, TodayCheckedPtr, CurrentNumTime[0], CurrentNumTime[1], CurrentNumTime[2], CurrentNumTime[3], CurrentNumTime[0], CurrentNumTime[1], CurrentNumTime[2], CheckedPtr); if (DoComprehensiveMenu) { fputs ( " paging (soft) \ peak
\n", stdout); } fprintf (stdout, " paging", CheckedPtr); if (DoComprehensiveMenu) { fputs ( " (hard)\ peak", stdout); } fputs ("
\n", stdout); fputs ( " disk IO", stdout); if (DoComprehensiveMenu) { fputs ( " peak", stdout); } fputs ("
\n", stdout); fputs ( " other IO", stdout); if (DoComprehensiveMenu) { fputs ( " peak", stdout); } fputs ("
\n", stdout); fputs ( " mscp IO", stdout); if (DoComprehensiveMenu) { fputs ( " peak", stdout); } fputs ("
\n", stdout); fputs ( " network", stdout); if (DoComprehensiveMenu) { fputs ( " peak", stdout); } fputs ("
\n", stdout); if (DoComprehensiveMenu) { fputs ( "\ include peak plot (where applicable)\n\

\n\ graph ...\  X,Y magnification:\ ,\
\n\ list
\n\ dump
\n\ \n\

\n", stdout); } else { fputs ( "\n", stdout); } fputs ( "

 refresh (minutes)", stdout); fputs ( "

\n\ \n", stdout); if (!DoComprehensiveMenu) { fputs ( "  \ double-height graph   \n", stdout); } fprintf (stdout, "\n\

\n\
\n"); SelectorPtr = NULL; ButtonBar (2); fprintf (stdout, "\n\n"); } /*****************************************************************************/ /* Output a list of node names that data can be selected from. Get these either from a command-line-supplied list or from data files present for the current day. */ SelectNodeNames () { int idx; char *CheckedPtr; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SelectNodeNames()\n"); if (SpiNodeNames[0][0]) { NodeCount = 0; for (idx = 0; SpiNodeNames[idx][0]; idx++) NodeCount++; if (NodeCount <= MAX_NODE_COUNT_BEFORE_SELECT) { CheckedPtr = " checked"; for (idx = 0; SpiNodeNames[idx][0]; idx++) { fprintf (stdout, " %s
\n", SpiNodeNames[idx], CheckedPtr, SpiNodeNames[idx]); CheckedPtr = ""; } } else { CheckedPtr = " selected"; fprintf (stdout, "\n", stdout); } } else { /* create file specification for getting node names (today's files) */ DataFileSpecLength = sprintf (DataFileSpec, "%sHYPERSPI_%s_*_%02.02d%02.02d%02.02d.DAT", HYPERSPI_DATA_DIRECTORY, HYPERSPI_DATA_VERSION, FromDay, FromMonth, FromYear%100); if (Debug) fprintf (stdout, "DataFileSpec |%s|\n", DataFileSpec); /* count the number of node data files */ ProcessDataFiles (NULL, false); NodeCount = DataFilesFoundCount; if (NodeCount <= MAX_NODE_COUNT_BEFORE_SELECT) ProcessDataFiles (&SelectNodeNameByDataFileName, false); else { fprintf (stdout, "\n", stdout); } } } /*****************************************************************************/ /* Called by pointer to function each time a matching data file is returned by sys$search(0 in function FindDataFiles(). Output the node name associated with the data file. */ SelectNodeNameByDataFileName () { static char *CheckedPtr = " checked"; static char *SelectedPtr = " selected"; /*********/ /* begin */ /*********/ if (Debug) fprintf (stdout, "SelectNodeNameByFileName() |%s|\n", DataFileName); if (NodeCount < MAX_NODE_COUNT_BEFORE_SELECT) { fprintf (stdout, " %s
\n", DataNode, CheckedPtr, DataNode); CheckedPtr = ""; } else { fprintf (stdout, "