공룡호가 사는 세상 이야기

system accounting +1

accounting은 크게 connection, process, disk, fee accounting으로 분류되어진다.
일단 SUNWaccr SUNWaccu 패키지가 있어야 한다. <- 시스템을 Entire 로 깔았으면  깔려있음.
- 시스템 재원의 상태 정보를 모니터링 함 (분석 가능)
- 기본적으로 세팅되어 있지 않음. 사용할 경우 시스템 I/O에 영향을 줄 가능성
- Job Schedule을 설정할 경우 time interval을 길게 한다. (I/O 최소화)

확인 #pkginfo SUNWaccu SUNWaccr

#ln -s  /etc/init.d/acct  /etc/rc2.d/S22acct
#ln -s /etc/init.d/acct /etc/rc0.d/K22acct

Enable : #touch /var/adm/pacct

콘쉘이라면
#export EDITOR=vi
#crontab -e
30 22 * *  4 /usr/lib/acct/dodisk
#crontab  -e adm
0 * * * * /usr/lib/acct/ckpacct
#위프로그램은 /var/adm 디렉토리가 500kbyte밖에 안남으면 accounting을 멈춘다.
30 2 * * * /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log
#여러 프로세스 사용, 디스크사용등을 리포트한다.
30 7 1 * * /usr/lib/acct/monacct
#위프로그램은 월별 리포트를 만든다.

위사항은 오전 2시 30분에 일별 리포트를 ,  매월 1일 오전 7:30분에 월별 리포트를 만드니까 필요시 변경
#/etc/init.d/acct start    #accounting 시작

#즉시 결과를 보고 싶다면 아래를 하면 즉시 daily report를 볼 수 있다.
#su - adm
#nohup /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log &
#각종 에러메시지는 /var/adm/acct/nite/fd2log에 기록된다
#runacct 프로그램이 수행되면 또다른 runacct의 수행을 방지 하기 위해서 lock와 lock1을 만든다  그래서 다시 시작하려면
# cd /var/adm/acct/nite;rm lastdate lock* 을 먼저 수행하고
#runacct 월일 2> /var/adm/acct/nite/fd2log & 을 하면 된다.


#잠시 정시 / 시작 하려면
위의 crontab 설정을 커멘트 처리하고 ,
#/etc/init.d/acct stop  #정지
#/etc/init.d/acct start #다시 시작

#리포트확인
#cat /var/adm/acct/sum/rprt월일
    
#나중에 각달의 2일쯤에 /var/adm/acct/fiscal/fiscrpt월 의 파일을 보고서로 활용하면 됨.


           %%%%%%%%%%%%%%%%%%%% Daily Report

#cat /var/adm/acct/sum/rprt월일  (예제)
Jun 11 02:30:02 1998  DAILY REPORT FOR mercury Page 1
 
 
from Wed Jun 10 02:30:02 1998
to   Thu Jun 11 02:30:02 1998
1       system boot
1       run-level 3
1       acctg on
1       runacct
1       acctcon
 
TOTAL DURATION IS 1384 MINUTES
LINE         MINUTES  PERCENT  # SESS  # ON  # OFF
/dev/pts/5   0        0        0       0     0  
/dev/pts/6   0        0        0       0     1  
/dev/pts/7   0        0        0       0     0  
console      1337     97       1       1     1  
pts/3        0        0        0       0     1  
pts/4        0        0        0       0     1  
pts/5        3        0        2       2     3  
pts/6        232      17       5       5     5  
pts/7        54       4        1       1     2  
pts/8        0        0        0       0     1  
pts/9        0        0        0       0     1  
TOTALS       1625     --       9       9     16
-----------------------------------------------------------------


위에서
Column                                     Description
  LINE                        터미널라인 이나 Access 포트
  MINUTES                 accounting 동안 해당라인이 사용된 분 
  PERCENT                 TOTAL DURATION을 MINUTES으로 나눈 율
  # SESS                    로그인 세션에 이 포트가 어세스된 수 
  # ON                       더이상 의미없음
  # OFF                      유저의 로그아웃회수나 cable,modem등의 문제로 인터럽트가 걸린 회수

 

Jun 11 02:30:02 1998  DAILY USAGE REPORT FOR mercury Page 1
      LOGIN    CPU (MINS) KCORE-MINS  CONNECT (MINS) DISK  # OF  # OF # DISK FEE
UID   NAME   PRIME NPRIME PRIME NPRIME PRIME NPRIME  BLOCKS PROCS SESS SAMPLES
0     TOTAL  1     1      2017  717    785   840    660361  1067  9     7    20
0     root   1     1      1833  499    550   840    400443  408   2     1    0
1     daemon 0     0      0     0      0     0      400     0     0     1    0
2     bin    0     0      0     0      0     0      253942  0     0     1    0
3     sys    0     0      0     0      0     0      2       0     0     1    0
4     adm    0     0      46    83     0     0      104     280   0     1    0
5     uucp   0     0      74    133    0     0      1672    316   0     1    0
71    lp     0     0      0     2      0     0      3798    1     0     1    0
8198  ksm    0     0      8     0      0     0      0       6     1     0    0
52171 pjm    0     0      56    0      234   0      0       56    6     0    20

--------------------------------------------------------------------------------


위에서
Column                             Description
  UID                          유저아이디
  LOGIN NAME            유저이름
  CPU-MINS                유저프로세스가 CPU를 사용한 시간 PRIME 과 NPRIME(non-prime)으로 구분 되어있

                                  는데 이것은 /etc/acct/holidays 파일에서 변경 가능하다 .
  KCORE-MINS            유저프로세스 활동중에 메모리를 kbyte단위로 사용한 축적양
  CONNECT-MINS        유저가 로그인한 실제시간 
  DISK BLOCKS           dodisk가 동작해서 출력한  512 bytes단위의 디스크블럭 수 
  # OF PROCS             유저가 띄운 프로세스의 수
  # OF SESS                유저의 로그인 회수 
  # DISK SAMPLES  dodisk가 동작해서 가지고온 샘플의 회수 

  FEE                         잘 안쓰지만 , chargefee명령으로 수집된 fee                       


Jun 11 02:30:02 1998  DAILY COMMAND SUMMARY Page 1
 
                                   TOTAL COMMAND SUMMARY
COMMAND NUMBER    TOTAL    TOTAL    TOTAL   MEAN    MEAN    HOG    CHARS  BLOCKS
NAME     CMDS  KCOREMIN  CPU-MIN  REAL-MIN  SIZE-K  CPU-MIN FACTOR TRNSFD   READ
 
TOTALS   1067   2730.99    2.01    1649.38 1361.41   0.00  0.00    6253571  2305
 
sendmail   28   1085.87    0.05      0.24  23865.20  0.00  0.19     101544    39
admintoo    3    397.68    0.12   1132.96  3443.12   0.04  0.00     680220    83
sh        166    204.78    0.31    161.13  651.80    0.00  0.00     598158    20
nroff      12    167.17    0.14      0.24  1205.55   0.01  0.59     709048    22
find       10    151.27    0.27      2.72  563.40    0.03  0.10     877971  1580
acctdusg    3     87.40    0.13      2.74  698.29    0.04  0.05     883845   203
lp         10     74.29    0.05      0.22  1397.38   0.01  0.24     136460    57
expr       20     67.48    0.02      0.06  3213.24   0.00  0.34       6380     1
mail.loc    3     65.83    0.01      0.04  11285.60  0.00  0.15      24709    15
cmdtool     1     37.65    0.02     20.13  2091.56   0.02  0.00     151296     1
uudemon.  105     37.38    0.09      0.32  435.46    0.00  0.27      62130    17
csh         6     35.17    0.05     57.28  756.30    0.01  0.00     209560    13
col        12     31.12    0.06      0.26  523.00    0.00  0.23     309932     0
ntpdate    22     27.55    0.05     11.18  599.00    0.00  0.00      22419     0
uuxqt      44     18.66    0.04      0.06  417.79    0.00  0.74      32604     3
man        12     15.11    0.03      7.05  503.67    0.00  0.00      85266    47
__________________________________________________________________________________


위에서
  Column                                     Description
  COMMAND NAME                  명령어 이름(쉘프로그램인 경우 프로그램 이름만 나옴 )
                                              accton 명령으로 유저를 판단 할 수 있다
  NUMBER CMNDS                   prime time동안 명령어 사용회수 .
  TOTAL KCOREMIN                수행시간 동안 프로세스가 분당, 메모리를 차지한 총 Kbyte segments
  TOTAL CPU-MIN:                   prime time동안 수행한 총 프로세싱시간 .
  TOTAL REAL-MIN                  총 real-time minutes
  MEAN SIZE-K                        평균 메모리 요구량
  MEAN CPU-MIN                     평균 CPU시간
  HOG FACTOR                        The ratio of CPU time to actual elapased time.
  CHARS TRNSFD                     read and write system calls에 의해 전달된 character의 수
  BLOCKS READ                       프로그램에 의해 읽거나 쓴 디스크 블럭 수

 

Last Login report
Jun  9 02:30:03 1998  LAST LOGIN Page 1 
.

.
00-00-00  arimmer       00-00-00  lister        97-02-27  pjm
00-00-00  reception     00-00-00  smithey       97-02-27  ksm
00-00-00  release       00-00-00  smsc          97-02-27  root
00-00-00  resch         00-00-00  datab
년-월-일 유저이름 순으로 표시

 

 %%%%%%%%%%%%%%%%%%%Monthly Report


#cat /var/adm/acct/fiscal/ficrpt월
Jun  9 02:30:03 1998  MONTHLY TOTAL COMMAND SUMMARY Page 1
 
                                     TOTAL COMMAND SUMMARY
COMMAND NUMBER     TOTAL    TOTAL     TOTAL   MEAN   MEAN   HOG    CHARS  BLOCKS
NAME      CMDS  KCOREMIN   CPU-MIN REAL-MIN SIZE-K CPU-MIN FACTOR TRNSFD   READ
 
TOTALS     771    483.70   0.94    8984.09  515.12   0.00  0.00   2248299   179
 
sh         105    155.41   0.23     429.58  667.94   0.00  0.00    491870     1
uudemon.    85     29.39   0.07       0.29  434.28   0.00  0.23     49630    14
acctcms      5     27.21   0.04       0.04  752.41   0.01  0.90    218880     1
ntpdate     17     21.30   0.04      14.10  605.73   0.00  0.00     18192     0
dtpad        1     19.69   0.01      10.87 2072.70   0.01  0.00     46992     8
sendmail    17     16.75   0.02       0.02  859.04   0.00  0.91     1965      0
acctprc      1     14.92   0.03       0.03  552.69   0.03  0.95    115584     0
uuxqt       34     14.78   0.03       0.04  426.29   0.00  0.92     25194     0
uusched     34     10.96   0.03       0.03  363.25   0.00  0.91     25194     0
sed         40     10.15   0.03       0.09  315.50   0.00  0.36     64162     2
man          5     10.08   0.02      57.58  555.05   0.00  0.00     25773     2
getent       1      7.68   0.01       0.02  921.60   0.01  0.40     20136     0

 

대부분의 월별 리포트는 일별 리포트와 비슷하다 .

%%%%%%%%%%%%%%%%%%Last Login report
#cat /var/adm/acct/sum/loginlog
Jun  9 02:30:03 1998  LAST LOGIN Page 1 
.

.
00-00-00  arimmer       00-00-00  lister        97-02-27  pjm
00-00-00  reception     00-00-00  smithey       97-02-27  ksm
00-00-00  release       00-00-00  smsc          97-02-27  root
00-00-00  resch         00-00-00  datab
년-월-일 유저이름 순으로 표시

 

#모아지는 데이터 파일 정리
/var/adm/디렉토리 밑

  File             Description
  dtmp             Output from the acctdusg program
  fee       Output from the chargefee program, ASCII tacct records
  pacct             Active process accounting file
  pacctn              Process accounting files switched using turnacct
  Spacctn.MMDD                         Process accounting files for MMDD during execution of runacct


/var/adm/acct/nite 디렉토리 밑

  File                                     Description
  active             Used by runacct to record progress and print warning and error messages
  activeMMDD             Same as active after runacct detects an error
  cms                         ASCII total command summary used by prdaily
  ctacct.MMDD             Connect accounting records in tacct.h format
  ctmp                         Output of acctcon1 program, connect session records in ctmp.h format (acctcon1 and acctcon2 are provided for compatibility purposes)
  daycms                         ASCII daily command summary used by prdaily
  daytacct             Total accounting records for one day in tacct.h format
  disktacct             Disk accounting records in tacct.h format, created by the dodisk procedure
  fd2log                         Diagnostic output during execution of runacct
  lastdate             Last day runacct executed (in date +%m%d format)
  lock                         Used to control serial use of runacct
  lineuse                         tty line usage report used by prdaily
  log                         Diagnostic output from acctcon
  log.MMDD             Same as log after runacct detects an error
  owtmp                         Previous day's wtmp file
  reboots                         Beginning and ending dates from wtmp and a listing of reboots
  statefile             Used to record current state during execution of runacct
  tmpwtmp                         wtmp file corrected by wtmpfix
  wtmperror             Place for wtmpfix error messages
  wtmperror.MMDD Same as wtmperror after runacct detects an error
  wtmp.MMDD runacct's copy of the wtmp file

/var/adm/acct/sum 디렉토리 밑

           File                                     Description
  cms                         Total command summary file for current fiscal period in internal summary format
  cmsprev                         Command summary file without latest update
  daycms                         Command summary file for the day's usage in internal summary format
  loginlog             Record of last date each user logged on; created by lastlogin and used in the prdaily program
  rprt.MMDD             Saved output of prdaily program
  tacct                         Cumulative total accounting file for current fiscal period
  tacctprev             Same as tacct without latest update
  tacct.MMDD             Total accounting file for MMDD


/var/adm/acct/fiscal 디렉토리 밑

           File                         Description
  cmsn              Total command summary file for fiscal period n in internal summary format
  fiscrptn  Report similar to rprtn for fiscal period n
  tacctn    Total accounting file for fiscal period n


#runacct 프로그램에 의해서 만들어 지는 파일

                       File                                     Description
  nite/lineuse                         runacct calls acctcon to gather data on terminal line usage from /var/adm/acct/nite/tmpwtmp and writes the data to /var/adm/acct/nite/lineuse.  prdaily uses this data to report line usage. This report is especially useful for detecting bad lines. If the ratio between the number of logouts to logins is greater than about three to one, there is a good possibility that the line is failing.
  nite/daytacct             This file is the total accounting file for the day in tacct.h format.
  sum/tacct                         This file is the accumulation of each day's nite/daytacct and can be used for billing purposes. It is restarted each month or fiscal period by the monacct procedure.
  sum/daycms                         runacct calls acctcms to process the data about the commands used during the day. This information is stored in /var/adm/acct/sum/daycms. It contains the daily command summary. The ASCII version of this file is /var/adm/acct/nite/daycms.
  sum/cms                                     This file is the accumulation of each day's command summaries. It is restarted by the execution of monacct. The ASCII version is nite/cms.
  sum/loginlog                         runacct calls lastlogin to update the last date logged in for the logins in /var/adm/acct/sum/loginlog. lastlogin also removes from this file logins that are no longer valid.
  sum/rprt.MMDD             Each execution of runacct saves a copy of the daily report that was printed by prdaily.

 

#만일 다중 사용자 레벨에서 date 가 변경되었다면 /var/adm/wtmp 에 변경 사항이 기록되는데이 변경 사항이 리포트에 문제를 일으킬 수 있다 . 그래서 wtmpfix 명령어가 wtmp의 레코드를 수정하는데 쓰일 수 있다.


#/usr/lib/acct/wtmpfix /var/adm/acct/nite/wtmp.월일 xwtmp
#xwtmp의 충돌하는 내용을 삭제하거나 변경한다.
#fwtmp -ic xwtmp /var/adm/acct/nite/wtmp.월일 # xwtmp binary로 고친다.

 

#주의 -- daily accounting 리포트가 만들어지면 raw data 들이 지워지고
monthly accounting리포트가 만들어지면 daily report 가 지워진다.