home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xcpp1.exe / SRC / TESTSTAT.CPP < prev   
C/C++ Source or Header  |  1995-11-09  |  7KB  |  282 lines

  1. /**************************************************************************
  2. ** File: teststat.cpp
  3. **
  4. ** Desc: Test program to test StatsThread class.
  5. **
  6. **
  7. **   DISCLAIMER  
  8. **  
  9. **   Novell, Inc. makes no representations or warranties with respect to
  10. **   any NetWare software, and specifically disclaims any express or
  11. **   implied warranties of merchantability, title, or fitness for a
  12. **   particular purpose.  
  13. **
  14. **   Distribution of any NetWare software is forbidden without the
  15. **   express written consent of Novell, Inc.  Further, Novell reserves
  16. **   the right to discontinue distribution of any NetWare software.
  17. **   
  18. **   Novell is not responsible for lost profits or revenue, loss of use
  19. **   of the software, loss of data, costs of re-creating lost data, the
  20. **   cost of any substitute equipment or program, or claims by any party
  21. **   other than you.  Novell strongly recommends a backup be made before
  22. **   any software is installed.   Technical support for this software
  23. **   may be provided at the discretion of Novell.
  24. **
  25. **
  26. ** Programmers:
  27. **
  28. **    Ini   Who                  Firm
  29. **    ---------------------------------------------------------------------
  30. **    DWH   Dirk W. Howard       Novell Developer Support
  31. **
  32. **
  33. ** History:
  34. **
  35. **    When        Who      What
  36. **    ---------------------------------------------------------------------
  37. **    9-18-1995    DWH      First code.
  38. **
  39. */
  40.  
  41. #include <stdio.h>
  42. #include <process.h>
  43. #include <nwenvrn.h>
  44. #include <conio.h>
  45. #include <nwservst.h>
  46. #include <errno.h>
  47. #include <signal.h>
  48. #include "stats.h"
  49.  
  50. extern "C"
  51. {
  52. LONG  GetServerUtilization(void);
  53. };
  54.  
  55. long ServerCPU( void );
  56. long CPUAve60( void );
  57. long CPUAve3600( void );
  58. long NCPConnections( void );
  59. long NLMConnections( void );
  60. long AFPConnections( void );
  61. long FTAMConnections( void );
  62. long ANCPConnections( void );
  63.  
  64. void WeWereUnloaded( int sigtype );
  65.  
  66. int exiting = FALSE;
  67. int safeToExit = FALSE;
  68.  
  69. void main()
  70. {
  71.    StatsThread  *cpuUtil, *cpu60SecAve, *cpu3600SecAve, *ncpConns,
  72.                 *nlmConns, *afpConns, *ftamConns, *ancpConns;
  73.  
  74.    signal( SIGTERM, WeWereUnloaded );
  75.    HideInputCursor();
  76.  
  77.    cpuUtil       = new StatsThread( 1, "CPU Utilization",
  78.                         1000, ServerCPU );
  79.    cpu60SecAve   = new StatsThread( 2, "Ave Util (1 min)",
  80.                         1000, CPUAve60 );
  81.    cpu3600SecAve = new StatsThread( 3, "Ave Util (1 hr)",
  82.                         30000, CPUAve3600 );
  83.    ncpConns      = new StatsThread( 5, "NCP Connections",
  84.                         1000, NCPConnections, 0, 250 );
  85.    nlmConns      = new StatsThread( 6, "NLM Connections", 
  86.                         1000, NLMConnections, 0, 250 );
  87.    afpConns      = new StatsThread( 7, "AFP Connections", 
  88.                         1000, AFPConnections, 0, 250 );
  89.    ftamConns     = new StatsThread( 8, "FTAM Connections", 
  90.                         1000, FTAMConnections, 0, 250 );
  91.    ancpConns     = new StatsThread( 9, "ANCP Connections", 
  92.                         1000, ANCPConnections, 0, 250 );
  93.  
  94.    while ( !kbhit() && !exiting )
  95.       delay(500);
  96.  
  97.    if ( !exiting )
  98.       safeToExit = TRUE;
  99.  
  100.    EnterCritSec();
  101.    gotoxy( 33, 0 );
  102.    printf( "Shutting down!" );
  103.    SetScreenRegionAttribute( 0, 1, 0x8C );
  104.    ExitCritSec();
  105.  
  106.    delete cpuUtil;
  107.    delete cpu60SecAve;
  108.    delete cpu3600SecAve;
  109.    delete ncpConns;
  110.    delete nlmConns;
  111.    delete afpConns;
  112.    delete ftamConns;
  113.    delete ancpConns;
  114.  
  115.    if ( exiting )
  116.    {
  117.       safeToExit = TRUE;
  118.       delay(100);
  119.    }
  120.  
  121. }
  122.  
  123.  
  124. long ServerCPU( void )
  125. {
  126.    return (long) GetServerUtilization();
  127. }
  128.  
  129. long CPUAve60( void )
  130. {
  131.    static long element[60];
  132.    static BYTE end = 0;
  133.    BYTE        i;
  134.    long        total = 0;
  135.    
  136.    element[end] = (long) GetServerUtilization();
  137.    end++;
  138.    if ( end > 59 )
  139.       end = 0;
  140.  
  141.    for ( i=0; i<60; i++ )
  142.       total += element[i];
  143.  
  144.    return ( total / 60 );
  145. }
  146.  
  147. long CPUAve3600( void )
  148. {
  149.    static long element[120];
  150.    static BYTE end = 0;
  151.    BYTE        i;
  152.    long        total = 0;
  153.    
  154.    element[end] = CPUAve60();
  155.    end++;
  156.    if ( end > 119 )
  157.       end = 0;
  158.  
  159.    for ( i=0; i<120; i++ )
  160.       total += element[i];
  161.  
  162.    return ( total / 120 );
  163. }
  164.  
  165. BYTE CountBitsInByte( BYTE in )
  166. {
  167.    BYTE bCount = 0;
  168.  
  169.    if ( in & 0x01 ) bCount++;
  170.    if ( in & 0x02 ) bCount++;
  171.    if ( in & 0x04 ) bCount++;
  172.    if ( in & 0x08 ) bCount++;
  173.    if ( in & 0x10 ) bCount++;
  174.    if ( in & 0x20 ) bCount++;
  175.    if ( in & 0x40 ) bCount++;
  176.    if ( in & 0x80 ) bCount++;
  177.  
  178.    return bCount;
  179. }
  180.  
  181. long CountBitsInArray( BYTE *array )
  182. {
  183.    int  i;
  184.    long lCount = 0;
  185.  
  186.    for ( i=0; i<512; i++ )
  187.       lCount += CountBitsInByte( array[i] );
  188.  
  189.    return lCount;
  190. }
  191.  
  192. long NCPConnections( void )
  193. {
  194.    LONG lCompCode;
  195.    BYTE buf[ 520 ];
  196.    GetActiveConnListByTypeStructure     *pBuf;
  197.  
  198.    lCompCode = SSGetActiveConnListByType( 0, 2, buf, sizeof(buf) );
  199.    if ( lCompCode == ESUCCESS )
  200.    {
  201.       pBuf = (GetActiveConnListByTypeStructure *) buf;
  202.       return CountBitsInArray( pBuf->ActiveConnBitList );
  203.    }
  204.    else
  205.       return 0;
  206. }
  207.  
  208. long NLMConnections( void )
  209. {
  210.    LONG lCompCode;
  211.    BYTE buf[ 520 ];
  212.    GetActiveConnListByTypeStructure     *pBuf;
  213.  
  214.    lCompCode = SSGetActiveConnListByType( 0, 3, buf, sizeof(buf) );
  215.    if ( lCompCode == ESUCCESS )
  216.    {
  217.       pBuf = (GetActiveConnListByTypeStructure *) buf;
  218.       return CountBitsInArray( pBuf->ActiveConnBitList );
  219.    }
  220.    else
  221.       return 0;
  222. }
  223.  
  224. long AFPConnections( void )
  225. {
  226.    LONG lCompCode;
  227.    BYTE buf[ 520 ];
  228.    GetActiveConnListByTypeStructure     *pBuf;
  229.  
  230.    lCompCode = SSGetActiveConnListByType( 0, 4, buf, sizeof(buf) );
  231.    if ( lCompCode == ESUCCESS )
  232.    {
  233.       pBuf = (GetActiveConnListByTypeStructure *) buf;
  234.       return CountBitsInArray( pBuf->ActiveConnBitList );
  235.    }
  236.    else
  237.       return 0;
  238. }
  239.  
  240. long FTAMConnections( void )
  241. {
  242.    LONG lCompCode;
  243.    BYTE buf[ 520 ];
  244.    GetActiveConnListByTypeStructure     *pBuf;
  245.  
  246.    lCompCode = SSGetActiveConnListByType( 0, 5, buf, sizeof(buf) );
  247.    if ( lCompCode == ESUCCESS )
  248.    {
  249.       pBuf = (GetActiveConnListByTypeStructure *) buf;
  250.       return CountBitsInArray( pBuf->ActiveConnBitList );
  251.    }
  252.    else
  253.       return 0;
  254. }
  255.  
  256. long ANCPConnections( void )
  257. {
  258.    LONG lCompCode;
  259.    BYTE buf[ 520 ];
  260.    GetActiveConnListByTypeStructure     *pBuf;
  261.  
  262.    lCompCode = SSGetActiveConnListByType( 0, 6, buf, sizeof(buf) );
  263.    if ( lCompCode == ESUCCESS )
  264.    {
  265.       pBuf = (GetActiveConnListByTypeStructure *) buf;
  266.       return CountBitsInArray( pBuf->ActiveConnBitList );
  267.    }
  268.    else
  269.       return 0;
  270. }
  271.  
  272.  
  273. void WeWereUnloaded( int sigtype )
  274. {
  275.    sigtype = sigtype;
  276.  
  277.    exiting = TRUE;
  278.    while ( !safeToExit )
  279.         ThreadSwitchWithDelay();
  280. }
  281.  
  282.