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
Wrap
C/C++ Source or Header
|
1995-11-09
|
7KB
|
282 lines
/**************************************************************************
** File: teststat.cpp
**
** Desc: Test program to test StatsThread class.
**
**
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
**
** Programmers:
**
** Ini Who Firm
** ---------------------------------------------------------------------
** DWH Dirk W. Howard Novell Developer Support
**
**
** History:
**
** When Who What
** ---------------------------------------------------------------------
** 9-18-1995 DWH First code.
**
*/
#include <stdio.h>
#include <process.h>
#include <nwenvrn.h>
#include <conio.h>
#include <nwservst.h>
#include <errno.h>
#include <signal.h>
#include "stats.h"
extern "C"
{
LONG GetServerUtilization(void);
};
long ServerCPU( void );
long CPUAve60( void );
long CPUAve3600( void );
long NCPConnections( void );
long NLMConnections( void );
long AFPConnections( void );
long FTAMConnections( void );
long ANCPConnections( void );
void WeWereUnloaded( int sigtype );
int exiting = FALSE;
int safeToExit = FALSE;
void main()
{
StatsThread *cpuUtil, *cpu60SecAve, *cpu3600SecAve, *ncpConns,
*nlmConns, *afpConns, *ftamConns, *ancpConns;
signal( SIGTERM, WeWereUnloaded );
HideInputCursor();
cpuUtil = new StatsThread( 1, "CPU Utilization",
1000, ServerCPU );
cpu60SecAve = new StatsThread( 2, "Ave Util (1 min)",
1000, CPUAve60 );
cpu3600SecAve = new StatsThread( 3, "Ave Util (1 hr)",
30000, CPUAve3600 );
ncpConns = new StatsThread( 5, "NCP Connections",
1000, NCPConnections, 0, 250 );
nlmConns = new StatsThread( 6, "NLM Connections",
1000, NLMConnections, 0, 250 );
afpConns = new StatsThread( 7, "AFP Connections",
1000, AFPConnections, 0, 250 );
ftamConns = new StatsThread( 8, "FTAM Connections",
1000, FTAMConnections, 0, 250 );
ancpConns = new StatsThread( 9, "ANCP Connections",
1000, ANCPConnections, 0, 250 );
while ( !kbhit() && !exiting )
delay(500);
if ( !exiting )
safeToExit = TRUE;
EnterCritSec();
gotoxy( 33, 0 );
printf( "Shutting down!" );
SetScreenRegionAttribute( 0, 1, 0x8C );
ExitCritSec();
delete cpuUtil;
delete cpu60SecAve;
delete cpu3600SecAve;
delete ncpConns;
delete nlmConns;
delete afpConns;
delete ftamConns;
delete ancpConns;
if ( exiting )
{
safeToExit = TRUE;
delay(100);
}
}
long ServerCPU( void )
{
return (long) GetServerUtilization();
}
long CPUAve60( void )
{
static long element[60];
static BYTE end = 0;
BYTE i;
long total = 0;
element[end] = (long) GetServerUtilization();
end++;
if ( end > 59 )
end = 0;
for ( i=0; i<60; i++ )
total += element[i];
return ( total / 60 );
}
long CPUAve3600( void )
{
static long element[120];
static BYTE end = 0;
BYTE i;
long total = 0;
element[end] = CPUAve60();
end++;
if ( end > 119 )
end = 0;
for ( i=0; i<120; i++ )
total += element[i];
return ( total / 120 );
}
BYTE CountBitsInByte( BYTE in )
{
BYTE bCount = 0;
if ( in & 0x01 ) bCount++;
if ( in & 0x02 ) bCount++;
if ( in & 0x04 ) bCount++;
if ( in & 0x08 ) bCount++;
if ( in & 0x10 ) bCount++;
if ( in & 0x20 ) bCount++;
if ( in & 0x40 ) bCount++;
if ( in & 0x80 ) bCount++;
return bCount;
}
long CountBitsInArray( BYTE *array )
{
int i;
long lCount = 0;
for ( i=0; i<512; i++ )
lCount += CountBitsInByte( array[i] );
return lCount;
}
long NCPConnections( void )
{
LONG lCompCode;
BYTE buf[ 520 ];
GetActiveConnListByTypeStructure *pBuf;
lCompCode = SSGetActiveConnListByType( 0, 2, buf, sizeof(buf) );
if ( lCompCode == ESUCCESS )
{
pBuf = (GetActiveConnListByTypeStructure *) buf;
return CountBitsInArray( pBuf->ActiveConnBitList );
}
else
return 0;
}
long NLMConnections( void )
{
LONG lCompCode;
BYTE buf[ 520 ];
GetActiveConnListByTypeStructure *pBuf;
lCompCode = SSGetActiveConnListByType( 0, 3, buf, sizeof(buf) );
if ( lCompCode == ESUCCESS )
{
pBuf = (GetActiveConnListByTypeStructure *) buf;
return CountBitsInArray( pBuf->ActiveConnBitList );
}
else
return 0;
}
long AFPConnections( void )
{
LONG lCompCode;
BYTE buf[ 520 ];
GetActiveConnListByTypeStructure *pBuf;
lCompCode = SSGetActiveConnListByType( 0, 4, buf, sizeof(buf) );
if ( lCompCode == ESUCCESS )
{
pBuf = (GetActiveConnListByTypeStructure *) buf;
return CountBitsInArray( pBuf->ActiveConnBitList );
}
else
return 0;
}
long FTAMConnections( void )
{
LONG lCompCode;
BYTE buf[ 520 ];
GetActiveConnListByTypeStructure *pBuf;
lCompCode = SSGetActiveConnListByType( 0, 5, buf, sizeof(buf) );
if ( lCompCode == ESUCCESS )
{
pBuf = (GetActiveConnListByTypeStructure *) buf;
return CountBitsInArray( pBuf->ActiveConnBitList );
}
else
return 0;
}
long ANCPConnections( void )
{
LONG lCompCode;
BYTE buf[ 520 ];
GetActiveConnListByTypeStructure *pBuf;
lCompCode = SSGetActiveConnListByType( 0, 6, buf, sizeof(buf) );
if ( lCompCode == ESUCCESS )
{
pBuf = (GetActiveConnListByTypeStructure *) buf;
return CountBitsInArray( pBuf->ActiveConnBitList );
}
else
return 0;
}
void WeWereUnloaded( int sigtype )
{
sigtype = sigtype;
exiting = TRUE;
while ( !safeToExit )
ThreadSwitchWithDelay();
}