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.

297 lines
15 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. getstats.c
  5. Abstract:
  6. Tests NT-level NetStatisticsGet API
  7. Author:
  8. Richard L Firth (rfirth) 08-Aug-1991
  9. Revision History:
  10. 09-May-1992 rfirth
  11. Change to use new redirector/wksta statistics
  12. 08-Aug-1991 rfirth
  13. Created
  14. --*/
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <windows.h>
  18. #include <lmcons.h>
  19. #include <lmstats.h>
  20. #include <lmsname.h>
  21. #include <lmapibuf.h>
  22. #include <lmerr.h>
  23. #include <tstring.h>
  24. #define IS_ARG(c) (((c) == '-') || ((c) == '/'))
  25. void main(int, char**);
  26. void usage(void);
  27. void main(int argc, char** argv) {
  28. LPTSTR service_name;
  29. LPTSTR server_name = NULL;
  30. DWORD level = 0;
  31. DWORD options = 0;
  32. LPBYTE buffer;
  33. NET_API_STATUS rc;
  34. for (--argc, ++argv; argc; --argc, ++argv) {
  35. if (IS_ARG(**argv)) {
  36. ++*argv;
  37. switch (tolower(**argv)) {
  38. case 'c':
  39. options = STATSOPT_CLR;
  40. break;
  41. case 'h':
  42. case '?':
  43. usage();
  44. break;
  45. case 'l':
  46. level = (DWORD)atoi(++*argv);
  47. break;
  48. case 'w':
  49. service_name = SERVICE_WORKSTATION;
  50. break;
  51. case 's':
  52. service_name = SERVICE_SERVER;
  53. break;
  54. default:
  55. printf("error: bad flag: '%c'\n", **argv);
  56. usage();
  57. }
  58. } else if (server_name) {
  59. //
  60. // allow the user to enter a service name. This allows us to expand
  61. // the test to cover other services which may be included in future
  62. //
  63. service_name = *argv;
  64. } else {
  65. server_name = *argv;
  66. }
  67. }
  68. rc = NetStatisticsGet(server_name, service_name, level, options, &buffer);
  69. if (rc != NERR_Success) {
  70. printf("error: NetStatisticsGet returns %u\n", rc);
  71. exit(2);
  72. } else {
  73. if (!STRCMP(service_name, SERVICE_SERVER)) {
  74. printf("Server statistics for %s:\n"
  75. "Time stats started............................: %u\n"
  76. "Number of file opens..........................: %u\n"
  77. "Number of device opens........................: %u\n"
  78. "Number of print jobs spooled..................: %u\n"
  79. "Number of server session started..............: %u\n"
  80. "Number of sessions auto disconnected..........: %u\n"
  81. "Number of server sessions failed with error...: %u\n"
  82. "Number of password violations.................: %u\n"
  83. "Number of server system errors................: %u\n"
  84. "Number of bytes sent to net (low).............: %u\n"
  85. "Number of bytes sent to net (high)............: %u\n"
  86. "Number of bytes received from net (low).......: %u\n"
  87. "Number of bytes received from net (high)......: %u\n"
  88. "Average response time.........................: %u\n"
  89. "Number of failures to allocate buffer.........: %u\n"
  90. "Number of failures to allocate big buf........: %u\n",
  91. server_name,
  92. ((LPSTAT_SERVER_0)buffer)->sts0_start,
  93. ((LPSTAT_SERVER_0)buffer)->sts0_fopens,
  94. ((LPSTAT_SERVER_0)buffer)->sts0_devopens,
  95. ((LPSTAT_SERVER_0)buffer)->sts0_jobsqueued,
  96. ((LPSTAT_SERVER_0)buffer)->sts0_sopens,
  97. ((LPSTAT_SERVER_0)buffer)->sts0_stimedout,
  98. ((LPSTAT_SERVER_0)buffer)->sts0_serrorout,
  99. ((LPSTAT_SERVER_0)buffer)->sts0_pwerrors,
  100. ((LPSTAT_SERVER_0)buffer)->sts0_permerrors,
  101. ((LPSTAT_SERVER_0)buffer)->sts0_syserrors,
  102. ((LPSTAT_SERVER_0)buffer)->sts0_bytessent_low,
  103. ((LPSTAT_SERVER_0)buffer)->sts0_bytessent_high,
  104. ((LPSTAT_SERVER_0)buffer)->sts0_bytesrcvd_low,
  105. ((LPSTAT_SERVER_0)buffer)->sts0_bytesrcvd_high,
  106. ((LPSTAT_SERVER_0)buffer)->sts0_avresponse,
  107. ((LPSTAT_SERVER_0)buffer)->sts0_reqbufneed,
  108. ((LPSTAT_SERVER_0)buffer)->sts0_bigbufneed
  109. );
  110. } else if (!STRCMP(service_name, SERVICE_WORKSTATION)) {
  111. printf("Workstation statistics for %s:\n"
  112. #ifdef LM20_WORKSTATION_STATISTICS
  113. "Time stats started..............................: %u\n"
  114. "Total NCBs issued by redirector.................: %u\n"
  115. "Total NCBs issued by server.....................: %u\n"
  116. "Total NCBs issued by apps.......................: %u\n"
  117. "Failed NCBs issued by redirector................: %u\n"
  118. "Failed NCBs issued by server....................: %u\n"
  119. "Failed NCBs issued by apps......................: %u\n"
  120. "NCBs issued by redir failing before completion..: %u\n"
  121. "NCBs issued by server failing before completion.: %u\n"
  122. "NCBs issued by apps failing before completion...: %u\n"
  123. "Number of sessions started......................: %u\n"
  124. "Number of sessions failed to connect............: %u\n"
  125. "Number of sessions failed after connecting......: %u\n"
  126. "Number of uses..................................: %u\n"
  127. "Number of failed uses...........................: %u\n"
  128. "Number of auto reconnections....................: %u\n"
  129. "Number of bytes sent to net (high)..............: %u\n"
  130. "Number of bytes sent to net (low)...............: %u\n"
  131. "Number of bytes received from net (high)........: %u\n"
  132. "Number of bytes received from net (low).........: %u\n"
  133. "Number of server bytes sent to net (high).......: %u\n"
  134. "Number of server bytes sent to net (low)........: %u\n"
  135. "Number of server bytes received from net (high).: %u\n"
  136. "Number of server bytes received from net (low)..: %u\n"
  137. "Number of app bytes sent to net (high)..........: %u\n"
  138. "Number of app bytes sent to net (low)...........: %u\n"
  139. "Number of app bytes received from net (high)....: %u\n"
  140. "Number of app bytes received from net (low).....: %u\n"
  141. "Number of failures to allocate buffer...........: %u\n"
  142. "Number of failures to allocate big buf..........: %u\n",
  143. server_name,
  144. ((LPSTAT_WORKSTATION_0)buffer)->stw0_start,
  145. ((LPSTAT_WORKSTATION_0)buffer)->stw0_numNCB_r,
  146. ((LPSTAT_WORKSTATION_0)buffer)->stw0_numNCB_s,
  147. ((LPSTAT_WORKSTATION_0)buffer)->stw0_numNCB_a,
  148. ((LPSTAT_WORKSTATION_0)buffer)->stw0_fiNCB_r,
  149. ((LPSTAT_WORKSTATION_0)buffer)->stw0_fiNCB_s,
  150. ((LPSTAT_WORKSTATION_0)buffer)->stw0_fiNCB_a,
  151. ((LPSTAT_WORKSTATION_0)buffer)->stw0_fcNCB_r,
  152. ((LPSTAT_WORKSTATION_0)buffer)->stw0_fcNCB_s,
  153. ((LPSTAT_WORKSTATION_0)buffer)->stw0_fcNCB_a,
  154. ((LPSTAT_WORKSTATION_0)buffer)->stw0_sesstart,
  155. ((LPSTAT_WORKSTATION_0)buffer)->stw0_sessfailcon,
  156. ((LPSTAT_WORKSTATION_0)buffer)->stw0_sessbroke,
  157. ((LPSTAT_WORKSTATION_0)buffer)->stw0_uses,
  158. ((LPSTAT_WORKSTATION_0)buffer)->stw0_usefail,
  159. ((LPSTAT_WORKSTATION_0)buffer)->stw0_autorec,
  160. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytessent_r_hi,
  161. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytessent_r_lo,
  162. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytesrcvd_r_hi,
  163. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytesrcvd_r_lo,
  164. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytessent_s_hi,
  165. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytessent_s_lo,
  166. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytesrcvd_s_hi,
  167. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytesrcvd_s_lo,
  168. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytessent_a_hi,
  169. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytessent_a_lo,
  170. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytesrcvd_a_hi,
  171. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bytesrcvd_a_lo,
  172. ((LPSTAT_WORKSTATION_0)buffer)->stw0_reqbufneed,
  173. ((LPSTAT_WORKSTATION_0)buffer)->stw0_bigbufneed
  174. #else
  175. "Bytes Received....................: %08x%08x\n"
  176. "SMBs Received.....................: %08x%08x\n"
  177. "Paging Read Bytes Requested.......: %08x%08x\n"
  178. "Non-paging Read Bytes Requested...: %08x%08x\n"
  179. "Cache Read Bytes Requested........: %08x%08x\n"
  180. "Network Read Bytes Requested......: %08x%08x\n"
  181. "Bytes Transmitted.................: %08x%08x\n"
  182. "SMBs Transmitted..................: %08x%08x\n"
  183. "Paging Write Bytes Requested......: %08x%08x\n"
  184. "Non-paging Write Bytes Requested..: %08x%08x\n"
  185. "Cache Write Bytes Requested.......: %08x%08x\n"
  186. "Network Write Bytes Requested.....: %08x%08x\n"
  187. "Read Operations...................: %u\n"
  188. "Random Read Operations............: %u\n"
  189. "Read SMBs.........................: %u\n"
  190. "Large Read SMBs...................: %u\n"
  191. "Small Read SMBs...................: %u\n"
  192. "Write Operations..................: %u\n"
  193. "Random Write Operations...........: %u\n"
  194. "Write SMBs........................: %u\n"
  195. "Large Write SMBs..................: %u\n"
  196. "Small Write SMBs..................: %u\n"
  197. "Raw Reads Denied..................: %u\n"
  198. "Raw Writes Dennied................: %u\n"
  199. "Network Errors....................: %u\n"
  200. "Sessions..........................: %u\n"
  201. "Reconnects........................: %u\n"
  202. "Core Connects.....................: %u\n"
  203. "Lanman 2.0 Connects...............: %u\n"
  204. "Lanman 2.1 Connects...............: %u\n"
  205. "Lanman NT Connects................: %u\n"
  206. "Server Disconnects................: %u\n"
  207. "Hung Sessions.....................: %u\n"
  208. "Current Commands..................: %u\n",
  209. server_name,
  210. ((LPSTAT_WORKSTATION_0)buffer)->BytesReceived.HighPart,
  211. ((LPSTAT_WORKSTATION_0)buffer)->BytesReceived.LowPart,
  212. ((LPSTAT_WORKSTATION_0)buffer)->SmbsReceived.HighPart,
  213. ((LPSTAT_WORKSTATION_0)buffer)->SmbsReceived.LowPart,
  214. ((LPSTAT_WORKSTATION_0)buffer)->PagingReadBytesRequested.HighPart,
  215. ((LPSTAT_WORKSTATION_0)buffer)->PagingReadBytesRequested.LowPart,
  216. ((LPSTAT_WORKSTATION_0)buffer)->NonPagingReadBytesRequested.HighPart,
  217. ((LPSTAT_WORKSTATION_0)buffer)->NonPagingReadBytesRequested.LowPart,
  218. ((LPSTAT_WORKSTATION_0)buffer)->CacheReadBytesRequested.HighPart,
  219. ((LPSTAT_WORKSTATION_0)buffer)->CacheReadBytesRequested.LowPart,
  220. ((LPSTAT_WORKSTATION_0)buffer)->NetworkReadBytesRequested.HighPart,
  221. ((LPSTAT_WORKSTATION_0)buffer)->NetworkReadBytesRequested.LowPart,
  222. ((LPSTAT_WORKSTATION_0)buffer)->BytesTransmitted.HighPart,
  223. ((LPSTAT_WORKSTATION_0)buffer)->BytesTransmitted.LowPart,
  224. ((LPSTAT_WORKSTATION_0)buffer)->SmbsTransmitted.HighPart,
  225. ((LPSTAT_WORKSTATION_0)buffer)->SmbsTransmitted.LowPart,
  226. ((LPSTAT_WORKSTATION_0)buffer)->PagingWriteBytesRequested.HighPart,
  227. ((LPSTAT_WORKSTATION_0)buffer)->PagingWriteBytesRequested.LowPart,
  228. ((LPSTAT_WORKSTATION_0)buffer)->NonPagingWriteBytesRequested.HighPart,
  229. ((LPSTAT_WORKSTATION_0)buffer)->NonPagingWriteBytesRequested.LowPart,
  230. ((LPSTAT_WORKSTATION_0)buffer)->CacheWriteBytesRequested.HighPart,
  231. ((LPSTAT_WORKSTATION_0)buffer)->CacheWriteBytesRequested.LowPart,
  232. ((LPSTAT_WORKSTATION_0)buffer)->NetworkWriteBytesRequested.HighPart,
  233. ((LPSTAT_WORKSTATION_0)buffer)->NetworkWriteBytesRequested.LowPart,
  234. ((LPSTAT_WORKSTATION_0)buffer)->ReadOperations,
  235. ((LPSTAT_WORKSTATION_0)buffer)->RandomReadOperations,
  236. ((LPSTAT_WORKSTATION_0)buffer)->ReadSmbs,
  237. ((LPSTAT_WORKSTATION_0)buffer)->LargeReadSmbs,
  238. ((LPSTAT_WORKSTATION_0)buffer)->SmallReadSmbs,
  239. ((LPSTAT_WORKSTATION_0)buffer)->WriteOperations,
  240. ((LPSTAT_WORKSTATION_0)buffer)->RandomWriteOperations,
  241. ((LPSTAT_WORKSTATION_0)buffer)->WriteSmbs,
  242. ((LPSTAT_WORKSTATION_0)buffer)->LargeWriteSmbs,
  243. ((LPSTAT_WORKSTATION_0)buffer)->SmallWriteSmbs,
  244. ((LPSTAT_WORKSTATION_0)buffer)->RawReadsDenied,
  245. ((LPSTAT_WORKSTATION_0)buffer)->RawWritesDenied,
  246. ((LPSTAT_WORKSTATION_0)buffer)->NetworkErrors,
  247. ((LPSTAT_WORKSTATION_0)buffer)->Sessions,
  248. ((LPSTAT_WORKSTATION_0)buffer)->Reconnects,
  249. ((LPSTAT_WORKSTATION_0)buffer)->CoreConnects,
  250. ((LPSTAT_WORKSTATION_0)buffer)->Lanman20Connects,
  251. ((LPSTAT_WORKSTATION_0)buffer)->Lanman21Connects,
  252. ((LPSTAT_WORKSTATION_0)buffer)->LanmanNtConnects,
  253. ((LPSTAT_WORKSTATION_0)buffer)->ServerDisconnects,
  254. ((LPSTAT_WORKSTATION_0)buffer)->HungSessions,
  255. ((LPSTAT_WORKSTATION_0)buffer)->CurrentCommands
  256. #endif
  257. );
  258. } else {
  259. printf("warning: don't know how to display info for service %s\n", service_name);
  260. }
  261. NetApiBufferFree(buffer);
  262. exit(0);
  263. }
  264. }
  265. void usage() {
  266. printf("usage: GetStats -w|-s -c -l# [\\\\ServerName] [optional_service_name]\n"
  267. "where: -w : gets WorkStation statistics\n"
  268. " -s : gets Server statistics\n"
  269. " -c : clears statistics\n"
  270. " -l#: level of information required (API=MBZ, default)\n"
  271. );
  272. exit(1);
  273. }