Leaked source code of windows server 2003
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.

283 lines
7.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ServStat.cpp
  7. The server statistics dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "ServStat.h"
  12. #include "server.h"
  13. #include "intltime.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. enum
  20. {
  21. SERVER_STAT_START_TIME = 0,
  22. SERVER_STAT_UPTIME,
  23. SERVER_STAT_DISCOVERS,
  24. SERVER_STAT_OFFERS,
  25. SERVER_STAT_REQUESTS,
  26. SERVER_STAT_ACKS,
  27. SERVER_STAT_NACKS,
  28. SERVER_STAT_DECLINES,
  29. SERVER_STAT_RELEASES,
  30. SERVER_STAT_TOTAL_SCOPES,
  31. SERVER_STAT_TOTAL_ADDRESSES,
  32. SERVER_STAT_IN_USE,
  33. SERVER_STAT_AVAILABLE,
  34. SERVER_STAT_MAX
  35. };
  36. /*---------------------------------------------------------------------------
  37. CServerStats implementation
  38. ---------------------------------------------------------------------------*/
  39. const ContainerColumnInfo s_rgServerStatsColumnInfo[] =
  40. {
  41. { IDS_SERVER_STATS_START_TIME, 0, TRUE },
  42. { IDS_SERVER_STATS_UPTIME, 0, TRUE },
  43. { IDS_SERVER_STATS_DISCOVERS, 0, TRUE },
  44. { IDS_SERVER_STATS_OFFERS, 0, TRUE },
  45. { IDS_SERVER_STATS_REQUESTS, 0, TRUE },
  46. { IDS_SERVER_STATS_ACKS, 0, TRUE },
  47. { IDS_SERVER_STATS_NACKS, 0, TRUE },
  48. { IDS_SERVER_STATS_DECLINES, 0, TRUE },
  49. { IDS_SERVER_STATS_RELEASES, 0, TRUE },
  50. { IDS_STATS_TOTAL_SCOPES, 0, TRUE },
  51. { IDS_STATS_TOTAL_ADDRESSES, 0, TRUE },
  52. { IDS_STATS_IN_USE, 0, TRUE },
  53. { IDS_STATS_AVAILABLE, 0, TRUE },
  54. };
  55. CServerStats::CServerStats()
  56. : StatsDialog(STATSDLG_VERTICAL)
  57. {
  58. SetColumnInfo(s_rgServerStatsColumnInfo,
  59. DimensionOf(s_rgServerStatsColumnInfo));
  60. }
  61. CServerStats::~CServerStats()
  62. {
  63. }
  64. BEGIN_MESSAGE_MAP(CServerStats, StatsDialog)
  65. //{{AFX_MSG_MAP(CServerStatistics)
  66. //}}AFX_MSG_MAP
  67. ON_MESSAGE(WM_NEW_STATS_AVAILABLE, OnNewStatsAvailable)
  68. END_MESSAGE_MAP()
  69. HRESULT CServerStats::RefreshData(BOOL fGrabNewData)
  70. {
  71. if (fGrabNewData)
  72. {
  73. DWORD dwError = 0;
  74. LPDHCP_MIB_INFO pMibInfo = NULL;
  75. BEGIN_WAIT_CURSOR;
  76. dwError = ::DhcpGetMibInfo(m_strServerAddress, &pMibInfo);
  77. END_WAIT_CURSOR;
  78. if (dwError != ERROR_SUCCESS)
  79. {
  80. ::DhcpMessageBox(dwError);
  81. return hrOK;
  82. }
  83. UpdateWindow(pMibInfo);
  84. if (pMibInfo)
  85. ::DhcpRpcFreeMemory(pMibInfo);
  86. }
  87. return hrOK;
  88. }
  89. BOOL CServerStats::OnInitDialog()
  90. {
  91. CString st;
  92. BOOL bRet;
  93. AfxFormatString1(st, IDS_SERVER_STATS_TITLE, m_strServerAddress);
  94. SetWindowText((LPCTSTR) st);
  95. bRet = StatsDialog::OnInitDialog();
  96. // set the default window size
  97. RECT rect;
  98. GetWindowRect(&rect);
  99. SetWindowPos(NULL, rect.left, rect.top, SERVER_STATS_DEFAULT_WIDTH, SERVER_STATS_DEFAULT_HEIGHT, SWP_SHOWWINDOW);
  100. // Set the default column widths to the width of the widest column
  101. SetColumnWidths(2 /* Number of Columns */);
  102. return bRet;
  103. }
  104. void CServerStats::Sort(UINT nColumnId)
  105. {
  106. // we don't sort any of our stats
  107. }
  108. afx_msg long CServerStats::OnNewStatsAvailable(UINT wParam, LONG lParam)
  109. {
  110. SPITFSNode spNode;
  111. CDhcpServer * pServer;
  112. pServer = GETHANDLER(CDhcpServer, m_spNode);
  113. LPDHCP_MIB_INFO pMibInfo = pServer->DuplicateMibInfo();
  114. Assert(pMibInfo);
  115. if (!pMibInfo)
  116. return 0;
  117. UpdateWindow(pMibInfo);
  118. pServer->FreeDupMibInfo(pMibInfo);
  119. return 0;
  120. }
  121. void CServerStats::UpdateWindow(LPDHCP_MIB_INFO pMibInfo)
  122. {
  123. Assert (pMibInfo);
  124. UINT i;
  125. UINT nTotalAddresses = 0, nTotalInUse = 0, nTotalAvailable = 0;
  126. if (pMibInfo)
  127. {
  128. LPSCOPE_MIB_INFO pScopeMibInfo = pMibInfo->ScopeInfo;
  129. // walk the list of scopes and calculate totals
  130. for (i = 0; i < pMibInfo->Scopes; i++)
  131. {
  132. nTotalAddresses += (pScopeMibInfo[i].NumAddressesInuse + pScopeMibInfo[i].NumAddressesFree);
  133. nTotalInUse += pScopeMibInfo[i].NumAddressesInuse;
  134. nTotalAvailable += pScopeMibInfo[i].NumAddressesFree;
  135. }
  136. }
  137. int nPercent;
  138. CString st;
  139. TCHAR szFormat[] = _T("%d");
  140. TCHAR szPercentFormat[] = _T("%d (%d%%)");
  141. for (i = 0; i < SERVER_STAT_MAX; i++)
  142. {
  143. if (!pMibInfo)
  144. st = _T("---");
  145. else
  146. {
  147. switch (i)
  148. {
  149. case SERVER_STAT_START_TIME:
  150. {
  151. FILETIME filetime;
  152. filetime.dwLowDateTime = pMibInfo->ServerStartTime.dwLowDateTime;
  153. filetime.dwHighDateTime = pMibInfo->ServerStartTime.dwHighDateTime;
  154. FormatDateTime(st, &filetime);
  155. }
  156. break;
  157. case SERVER_STAT_UPTIME:
  158. {
  159. FILETIME filetime;
  160. filetime.dwLowDateTime = pMibInfo->ServerStartTime.dwLowDateTime;
  161. filetime.dwHighDateTime = pMibInfo->ServerStartTime.dwHighDateTime;
  162. CTime timeServerStart(filetime);
  163. CTime timeCurrent = CTime::GetCurrentTime();
  164. CTimeSpan timeUp = timeCurrent - timeServerStart;
  165. LONG_PTR nHours = timeUp.GetTotalHours();
  166. LONG nMinutes = timeUp.GetMinutes();
  167. LONG nSeconds = timeUp.GetSeconds();
  168. CString strFormat;
  169. strFormat.LoadString(IDS_UPTIME_FORMAT);
  170. st.Format(strFormat, nHours, nMinutes, nSeconds);
  171. }
  172. break;
  173. case SERVER_STAT_DISCOVERS:
  174. st.Format(szFormat, pMibInfo->Discovers);
  175. break;
  176. case SERVER_STAT_OFFERS:
  177. st.Format(szFormat, pMibInfo->Offers);
  178. break;
  179. case SERVER_STAT_REQUESTS:
  180. st.Format(szFormat, pMibInfo->Requests);
  181. break;
  182. case SERVER_STAT_ACKS:
  183. st.Format(szFormat, pMibInfo->Acks);
  184. break;
  185. case SERVER_STAT_NACKS:
  186. st.Format(szFormat, pMibInfo->Naks);
  187. break;
  188. case SERVER_STAT_DECLINES:
  189. st.Format(szFormat, pMibInfo->Declines);
  190. break;
  191. case SERVER_STAT_RELEASES:
  192. st.Format(szFormat, pMibInfo->Releases);
  193. break;
  194. case SERVER_STAT_TOTAL_SCOPES:
  195. st.Format(szFormat, pMibInfo->Scopes);
  196. break;
  197. case SERVER_STAT_TOTAL_ADDRESSES:
  198. st.Format(szFormat, nTotalAddresses);
  199. break;
  200. case SERVER_STAT_IN_USE:
  201. if (nTotalAddresses > 0)
  202. nPercent = (int) ((float) (nTotalInUse * 100) / (float) nTotalAddresses);
  203. else
  204. nPercent = 0;
  205. st.Format(szPercentFormat, nTotalInUse, nPercent);
  206. break;
  207. case SERVER_STAT_AVAILABLE:
  208. if (nTotalAddresses > 0)
  209. nPercent = (int) ((float) (nTotalAvailable * 100) / (float) nTotalAddresses);
  210. else
  211. nPercent = 0;
  212. st.Format(szPercentFormat, nTotalAvailable, nPercent);
  213. break;
  214. default:
  215. Panic1("Unknown server id : %d", i);
  216. break;
  217. }
  218. }
  219. m_listCtrl.SetItemText(i, 1, (LPCTSTR) st);
  220. }
  221. }