Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
6.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. perfdll.cxx
  7. This trivial DLL grabs statistics from the w3 server
  8. FILE HISTORY:
  9. t-bilala 04-01-97 Leveraged from perfw3.cxx in \perfmon
  10. */
  11. #include <windows.h>
  12. #include <lm.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <ole2.h>
  16. #include "iisinfo.h"
  17. #include "perfdll.h"
  18. //
  19. // Public prototypes.
  20. //
  21. PerfFunction GetPerformanceData;
  22. DWORD
  23. GetStatisticsValue(
  24. IN LPSTR pszValue,
  25. IN W3_STATISTICS_1 * pW3Stats
  26. );
  27. /*******************************************************************
  28. NAME: GetPerformanceData
  29. SYNOPSIS: Get performance counter value from web server.
  30. ENTRY: pszValue - The name of the value to retrieve
  31. pszServerName - Server name
  32. RETURNS: DWORD - value of performance counter
  33. ********************************************************************/
  34. DWORD
  35. GetPerformanceData(
  36. IN LPSTR pszValue,
  37. IN LPSTR pszServer
  38. )
  39. {
  40. W3_STATISTICS_1 * pW3Stats = NULL;
  41. NET_API_STATUS neterr;
  42. DWORD dwValue;
  43. WCHAR achBuffer[ MAX_PATH ];
  44. if ( pszValue == NULL )
  45. {
  46. return 0;
  47. }
  48. if ( pszServer != NULL )
  49. {
  50. if ( !MultiByteToWideChar( CP_ACP,
  51. MB_PRECOMPOSED,
  52. pszServer,
  53. -1,
  54. achBuffer,
  55. MAX_PATH ) )
  56. {
  57. return FALSE;
  58. }
  59. }
  60. neterr = W3QueryStatistics2(
  61. pszServer ? achBuffer : NULL,
  62. 0,
  63. 1, // instance id
  64. 0,
  65. (LPBYTE *)&pW3Stats );
  66. if( neterr != NERR_Success )
  67. {
  68. CHAR achBuffer[ 256 ];
  69. wsprintf( achBuffer,
  70. "Error was %d\n",
  71. neterr );
  72. OutputDebugString( achBuffer );
  73. dwValue = 0;
  74. }
  75. else
  76. {
  77. dwValue = GetStatisticsValue( pszValue, pW3Stats );
  78. }
  79. if ( pW3Stats != NULL )
  80. {
  81. MIDL_user_free( pW3Stats );
  82. }
  83. return dwValue;
  84. }
  85. DWORD
  86. GetStatisticsValue(
  87. IN LPSTR pszValue,
  88. IN W3_STATISTICS_1 * pW3Stats
  89. )
  90. {
  91. if ( !_stricmp( pszValue, "TotalUsers" ) )
  92. {
  93. return pW3Stats->TotalAnonymousUsers + pW3Stats->TotalNonAnonymousUsers;
  94. }
  95. else if ( !_stricmp( pszValue, "TotalFilesSent" ) )
  96. {
  97. return pW3Stats->TotalFilesSent;
  98. }
  99. else if ( !_stricmp( pszValue, "TotalFilesReceived" ) )
  100. {
  101. return pW3Stats->TotalFilesReceived;
  102. }
  103. else if ( !_stricmp( pszValue, "CurrentAnonymousUsers" ) )
  104. {
  105. return pW3Stats->CurrentAnonymousUsers;
  106. }
  107. else if ( !_stricmp( pszValue, "CurrentNonAnonymousUsers" ) )
  108. {
  109. return pW3Stats->CurrentNonAnonymousUsers;
  110. }
  111. else if ( !_stricmp( pszValue, "TotalAnonymousUsers" ) )
  112. {
  113. return pW3Stats->TotalAnonymousUsers;
  114. }
  115. else if ( !_stricmp( pszValue, "MaxAnonymousUsers" ) )
  116. {
  117. return pW3Stats->MaxAnonymousUsers;
  118. }
  119. else if ( !_stricmp( pszValue, "MaxNonAnonymousUsers" ) )
  120. {
  121. return pW3Stats->MaxNonAnonymousUsers;
  122. }
  123. else if ( !_stricmp( pszValue, "CurrentConnections" ) )
  124. {
  125. return pW3Stats->CurrentConnections;
  126. }
  127. else if ( !_stricmp( pszValue, "MaxConnections" ) )
  128. {
  129. return pW3Stats->MaxConnections;
  130. }
  131. else if ( !_stricmp( pszValue, "ConnectionAttempts" ) )
  132. {
  133. return pW3Stats->ConnectionAttempts;
  134. }
  135. else if ( !_stricmp( pszValue, "LogonAttempts" ) )
  136. {
  137. return pW3Stats->LogonAttempts;
  138. }
  139. else if ( !_stricmp( pszValue, "TotalGets" ) )
  140. {
  141. return pW3Stats->TotalGets;
  142. }
  143. else if ( !_stricmp( pszValue, "TotalPosts" ) )
  144. {
  145. return pW3Stats->TotalPosts;
  146. }
  147. else if ( !_stricmp( pszValue, "TotalHeads" ) )
  148. {
  149. return pW3Stats->TotalHeads;
  150. }
  151. else if ( !_stricmp( pszValue, "TotalPuts" ) )
  152. {
  153. return pW3Stats->TotalPuts;
  154. }
  155. else if ( !_stricmp( pszValue, "TotalDeletes" ) )
  156. {
  157. return pW3Stats->TotalDeletes;
  158. }
  159. else if ( !_stricmp( pszValue, "TotalTraces" ) )
  160. {
  161. return pW3Stats->TotalTraces;
  162. }
  163. else if ( !_stricmp( pszValue, "TotalOthers" ) )
  164. {
  165. return pW3Stats->TotalOthers;
  166. }
  167. else if ( !_stricmp( pszValue, "TotalCGIRequests" ) )
  168. {
  169. return pW3Stats->TotalCGIRequests;
  170. }
  171. else if ( !_stricmp( pszValue, "TotalBGIRequests" ) )
  172. {
  173. return pW3Stats->TotalBGIRequests;
  174. }
  175. else if ( !_stricmp( pszValue, "TotalNotFoundErrors" ) )
  176. {
  177. return pW3Stats->TotalNotFoundErrors;
  178. }
  179. else if ( !_stricmp( pszValue, "CurrentCGIRequests" ) )
  180. {
  181. return pW3Stats->CurrentCGIRequests;
  182. }
  183. else if ( !_stricmp( pszValue, "CurrentBGIRequests" ) )
  184. {
  185. return pW3Stats->CurrentBGIRequests;
  186. }
  187. else if ( !_stricmp( pszValue, "MaxCGIRequests" ) )
  188. {
  189. return pW3Stats->MaxCGIRequests;
  190. }
  191. else if ( !_stricmp( pszValue, "MaxBGIRequests" ) )
  192. {
  193. return pW3Stats->MaxBGIRequests;
  194. }
  195. else if ( !_stricmp( pszValue, "CurrentBlockedRequests" ) )
  196. {
  197. return pW3Stats->CurrentBlockedRequests;
  198. }
  199. else if ( !_stricmp( pszValue, "TotalBlockedRequests" ) )
  200. {
  201. return pW3Stats->TotalBlockedRequests;
  202. }
  203. else if ( !_stricmp( pszValue, "TotalAllowedRequests" ) )
  204. {
  205. return pW3Stats->TotalAllowedRequests;
  206. }
  207. else if ( !_stricmp( pszValue, "TotalRejectedRequests" ) )
  208. {
  209. return pW3Stats->TotalRejectedRequests;
  210. }
  211. else if ( !_stricmp( pszValue, "MeasuredBw" ) )
  212. {
  213. return pW3Stats->MeasuredBw;
  214. }
  215. return 0;
  216. }