home *** CD-ROM | disk | FTP | other *** search
/ Tutto per Internet / Internet.iso / soft95 / Varie / server / isrvmon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-05  |  8.0 KB  |  264 lines

  1. /*
  2.   isrvmon.c
  3.  
  4.   This is a Internet Information Server Application that displays 
  5.   performance information about the Microsoft Internet Information Server
  6.  
  7.   Exports:
  8.  
  9.     BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *pVer )
  10.  
  11.     As per the ISAPI Spec, this just returns the
  12.     version of the spec that this server was built with.  This
  13.     function is prototyped in httpext.h
  14.  
  15.     BOOL WINAPI HttpExtensionProc(   EXTENSION_CONTROL_BLOCK *pECB )
  16.  
  17.     This function does all of the work.
  18.  
  19. */
  20. #include <windows.h>
  21. #include <httpext.h>
  22.  
  23. #define SYS_INFO "SystemInfo"
  24. #define MEMORY_STATUS "MemoryStatus"
  25. #define PROCESSINFO  "ProcessInfo"
  26. #define GET  "get"
  27.  
  28. BOOL FillInSystemInfo(char *buff);
  29. BOOL FillInMemoryStatus(char *buff);
  30. BOOL FillInProcessInfo(char *buff);
  31.  
  32. BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *pVer )
  33.  {
  34.   pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR, HSE_VERSION_MAJOR );
  35.  
  36.   lstrcpyn( pVer->lpszExtensionDesc,
  37.             "Sample Internet Web Server Application",
  38.             HSE_MAX_EXT_DLL_NAME_LEN );
  39.  
  40.   return TRUE;
  41.  } // GetExtensionVersion()
  42.  
  43. DWORD WINAPI HttpExtensionProc( EXTENSION_CONTROL_BLOCK *pECB )
  44.  {
  45.  
  46.     CHAR  buff[4096];
  47.     CHAR  *lpszQuery;
  48.     CHAR  *lpszTemp=NULL;
  49.     DWORD cbQuery;
  50.     BOOL  Success=FALSE;
  51.  
  52.     pECB->dwHttpStatusCode=0; // 0 Failure
  53.  
  54.     //
  55.     //  The Query parameter will contain some or all of the following
  56.     //  strings:
  57.     //
  58.     //  SystemInfo
  59.     //  MemoryStatus
  60.     //  ProcessInfo
  61.     //
  62.     //  We have to parse the string, determine which are passed, and do
  63.     //  the appropriate APIs.  Just for fun we will create the html page
  64.     //  first, and then append the appropriate data as we go along.
  65.     //
  66.  
  67.     //
  68.     //
  69.     //  Note the HTTP header block is terminated by a blank '\r\n' pair,
  70.     //  followed by the document body
  71.     //
  72.  
  73.     wsprintf( buff,
  74.              "Content-Type: text/html\r\n"
  75.              "\r\n"
  76.              "<head><title>Sample Web Server Application</title></head>\n"
  77.              "<body><h1>Internet Server Performance Characteristics</h1>\n"
  78.              "<hr>\n");
  79.  
  80.  
  81.     //
  82.     //  If the request is a GET, then the lpszQueryString member of the ECB
  83.     //  contains the query string.
  84.     //
  85.     //  If the request is a POST, then you have to get all of the data, both
  86.     //  from the lpbData member, and then read the rest of the data via the
  87.     //  ReadClient() call.
  88.     //
  89.  
  90.     if (!stricmp(pECB->lpszMethod, GET))
  91.         lpszQuery = pECB->lpszQueryString;
  92.     else 
  93.     {
  94.  
  95.         if(pECB->cbTotalBytes == 0)     // No Query at all
  96.             goto nodata;
  97.         else
  98.         {
  99.             if(!(lpszTemp = (CHAR *)LocalAlloc(LPTR, pECB->cbTotalBytes)))
  100.                 return HSE_STATUS_ERROR;
  101.  
  102.             strcpy(lpszTemp, pECB->lpbData);
  103.  
  104.             if((cbQuery = pECB->cbTotalBytes - pECB->cbAvailable) > 0)
  105.                 pECB->ReadClient(pECB->ConnID, (LPVOID) (lpszTemp + pECB->cbAvailable), &cbQuery);
  106.  
  107.             lpszQuery = lpszTemp;
  108.         }
  109.     }
  110.  
  111.     if (strstr(lpszQuery, SYS_INFO))
  112.         Success |= FillInSystemInfo(buff);
  113.  
  114.     if (strstr(lpszQuery, MEMORY_STATUS))
  115.         Success |= FillInMemoryStatus(buff);
  116.  
  117.     if (strstr(lpszQuery, PROCESSINFO))
  118.         Success |= FillInProcessInfo(buff);
  119.  
  120. nodata:
  121.     if (!Success)
  122.         strcat(buff,"<p>No Data Requested");
  123.      {
  124.       DWORD dwLen=lstrlen(buff);
  125.  
  126.       if ( !pECB->ServerSupportFunction( pECB->ConnID,
  127.                                          HSE_REQ_SEND_RESPONSE_HEADER,
  128.                                          "200 OK",
  129.                                          &dwLen,
  130.                                          (LPDWORD) buff ))
  131.       {
  132.         return HSE_STATUS_ERROR;
  133.       }
  134.      }
  135.  
  136.     pECB->dwHttpStatusCode=200; // 200 OK
  137.  
  138.     if(lpszTemp)
  139.         LocalFree(lpszTemp);
  140.  
  141.     return HSE_STATUS_SUCCESS;
  142.  
  143.  } // HttpExtensionProc()
  144.  
  145. CHAR *lpszArchitecture[]={"INTEL", "MIPS", "ALPHA", "PPC"};
  146.  
  147. BOOL FillInSystemInfo(CHAR *buff)
  148. {
  149.     SYSTEM_INFO si;
  150.     CHAR        tmpbuf[1024];
  151.  
  152.     GetSystemInfo(&si);
  153.  
  154. //
  155. // Need to actually handle processor level.  
  156. // Just print it for now as a number
  157. //
  158.     wsprintf(tmpbuf,
  159.              "<h2>System Information</h2>\n"
  160.              "<pre>Type Of Machine:      %s</pre>\n"
  161.              "<pre>Level Of Processor:   %d</pre>\n"
  162.              "<pre>Number Of Processors: %d</pre>\n"
  163.              "<hr>\n",
  164.               lpszArchitecture[si.wProcessorArchitecture],
  165.               si.wProcessorLevel,
  166.               si.dwNumberOfProcessors);
  167.  
  168.     buff = strcat(buff,tmpbuf);
  169.     
  170.     return TRUE;
  171. } // FillInSystemInfo
  172.  
  173. BOOL FillInMemoryStatus(CHAR *buff)
  174. {
  175.     MEMORYSTATUS ms;
  176.     CHAR         tmpbuf[1024];
  177.  
  178.     ms.dwLength = sizeof(MEMORYSTATUS);
  179.  
  180.     GlobalMemoryStatus(&ms);
  181.  
  182.     wsprintf(tmpbuf,
  183.              "<h2>Global Memory Status</h2>\n"
  184.              "<pre>Memory Load:               %d%%\n</pre>\n"
  185.              "<pre>Total Physical Memory:     %d MB</pre>\n"
  186.              "<pre>Available Physical Memory: %d MB\n</pre>\n"
  187.              "<pre>Total Page File:           %d MB</pre>\n"
  188.              "<pre>Available Page File:       %d MB\n</pre>\n"
  189.              "<pre>Total Virtual Memory:      %d MB</pre>\n"
  190.              "<pre>Available Virtual Memory:  %d MB</pre>\n"
  191.              "<hr>\n",
  192.              ms.dwMemoryLoad,
  193.              ms.dwTotalPhys/1024/1024,
  194.              ms.dwAvailPhys/1024/1024,
  195.              ms.dwTotalPageFile/1024/1024,
  196.              ms.dwAvailPageFile/1024/1024,
  197.              ms.dwTotalVirtual/1024/1024,
  198.              ms.dwAvailVirtual/1024/1024);
  199.              
  200.     buff = strcat(buff,tmpbuf);
  201.  
  202.     return TRUE;
  203. } // FillInMemoryStatus
  204.  
  205. BOOL FillInProcessInfo(CHAR *buff)
  206. {
  207.     LONGLONG    ftCreationTime;
  208.     LONGLONG    ftExitTime;
  209.     LONGLONG    ftKernelTime;
  210.     LONGLONG    ftUserTime;
  211.     LONGLONG    ftCurrentTime;
  212.     LONGLONG    ftElapsedTime;
  213.     SYSTEMTIME  stCurrentTime;
  214.     CHAR        tmpbuf[1024];
  215.     
  216.     buff = strcat(buff,"<h2>Process Information</h2>\n");
  217.  
  218.     if(!GetProcessTimes(GetCurrentProcess(),
  219.                         (FILETIME *) &ftCreationTime,
  220.                         (FILETIME *) &ftExitTime,
  221.                         (FILETIME *) &ftKernelTime,
  222.                         (FILETIME *) &ftUserTime))
  223.     {
  224.         buff = strcat(buff,"<p>No Process Information Available\n<hr>\n");
  225.         return TRUE;
  226.     }
  227.                             
  228.  
  229.     GetSystemTime(&stCurrentTime);
  230.     SystemTimeToFileTime(&stCurrentTime,(FILETIME *) &ftCurrentTime);
  231.     ftElapsedTime = (ftCurrentTime - ftCreationTime)/10000;
  232.     ftKernelTime = ftKernelTime/10000;
  233.     ftUserTime = ftUserTime/10000;
  234.  
  235.     wsprintf(tmpbuf,
  236.              "<pre>ElapsedTime:   %d Day(s)</pre>\n"
  237.              "<pre>               %d Hr</pre>\n"
  238.              "<pre>               %d Min</pre>\n"
  239.              "<pre>               %d Sec</pre>\n"
  240.              "<pre>               %d mSec\n</pre>\n" 
  241.              "<pre>KernelTime:    %d Min</pre>\n"
  242.              "<pre>               %d Sec</pre>\n"
  243.              "<pre>               %d mSec\n</pre>\n" 
  244.              "<pre>UserTime:      %d Min</pre>\n"
  245.              "<pre>               %d Sec</pre>\n"
  246.              "<pre>               %d mSec</pre>\n"
  247.              "<hr>\n",
  248.              (DWORD) (ftElapsedTime/86400000),
  249.              (DWORD) (ftElapsedTime%86400000/3600000),
  250.              (DWORD) (ftElapsedTime%86400000%3600000/60000),
  251.              (DWORD) (ftElapsedTime%86400000%3600000%60000/1000),
  252.              (DWORD) (ftElapsedTime%86400000%3600000%60000%1000),
  253.              (DWORD) (ftKernelTime/60000),
  254.              (DWORD) (ftKernelTime%60000/1000),
  255.              (DWORD) (ftKernelTime%60000%1000),
  256.              (DWORD) (ftUserTime/60000),
  257.              (DWORD) (ftUserTime%60000/1000),
  258.              (DWORD) (ftUserTime%60000%1000));
  259.              
  260.             
  261.     buff = strcat(buff,tmpbuf);
  262.     return TRUE;
  263. } // FillInProcessInfo
  264.