Linux操作系统中有三种主要的日志子系统:
(1)连接时间日志
(2)进程统计日志
(3)系统和服务日志
连接时间日志和进程统计日志由rsyslog(旧版是syslog)日志服务驱动,系统和服务日志由相对应的网络服务驱动和管理;
进程统计日志
进程统计日志可以监控用户在服务器上的操作时非常有效,所记录的操作会存入/var/account/pacct文件中;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#accton
accton: no arguments
Usage: accton [OPTION] on|off|ACCOUNTING_FILE
Try
'accton --help'
for
more
information.
# accton --help
Usage: accton [OPTION] on|off|ACCOUNTING_FILE
Turns process accounting on or off, or changes the
file
where this
info is saved.
OPTIONS:
-h, --help Show help and
exit
-V, --version Show version and
exit
ARGUMENTS:
on Activate process accounting and use default
file
off Deactivate process accounting
ACCOUNTING_FILE Activate (
if
not active) and save information
in
this
file
The system
's default process accounting file is '
/var/account/pacct
'.
Report bugs to <bug-acct@gnu.org>
|
(1)启动进程统计日志情况
1
2
|
# accton on
Turning on process accounting,
file
set
to the default
'/var/account/pacct'
.
|
(2)显示进程统计日志情况
1
2
3
4
5
6
7
8
9
10
|
# lastcomm
ksmtuned F root __ 0.00 secs Thu Feb 26 23:05
awk
root __ 0.00 secs Thu Feb 26 23:05
ksmtuned F root __ 0.00 secs Thu Feb 26 23:05
ksmtuned F root __ 0.00 secs Thu Feb 26 23:05
pgrep root __ 0.00 secs Thu Feb 26 23:05
ksmtuned F root __ 0.00 secs Thu Feb 26 23:05
awk
root __ 0.00 secs Thu Feb 26 23:05
sleep
root __ 0.00 secs Thu Feb 26 23:04
accton S root pts
/0
0.00 secs Thu Feb 26 23:04
|
以最后一行为例:
*命令位
*标志位
S表示命令有超级管理员执行
F表示命令有子程序运行,没有使用EXEC
C表示命令运行在PDP-11兼容环境下
X表示命令由SIGTREM信号终止
*用户名
*执行命令的系统
关于lastcomm的用法:
1
2
3
4
5
6
|
# lastcomm --help
Usage: lastcomm [-hpV] [-f
file
] [
command
] ... [user] ... [terminal] ...
[--forwards] [--
file
<
file
>] [--strict-match] [--print-controls]
[--user <name>] [--
tty
<name>] [--
command
<name>] [--debug]
[--show-paging] [--ahz <freq>] [--version] [--help]
The system's default process accounting
file
is
/var/account/pacct
.
|
(3)停止进程统计日志监控
1
|
# lastcomm off
|
使用sa命令进行统计
sa命令可以将/var/account/pacct中的数据压缩到/var/log/savacc(基于命令名称进行索引统计)和/etc/log/usracc(基于用户名进行索引统计的)中;
1
2
3
4
|
# sa -a
4557 50640.33re 1.08cp 0avio 27021k
1 742.55re 0.58cp 0avio 366208k gnome-shell
7 5199.84re 0.23cp 0avio 105595k gmain
|
re表示示例时间,以分钟为单位;
cp表示系统和用户的使用时间,以分钟为单位;
k表示内核占用CPU的平均时间,一个单元大小为KB;
sh表示命令名称;
avio表示每次执行I/O操作的次数;
sa语法如下:
用法:sa [选项]... [文件]...
主要选项如下。
— -a:打印所有命令的名称(包括那些带有不可打印字符的)。
— -b:将输出按用户和系统时间的总和除以调用次数来进行分类。否则,输出为用户时间和系统时间之和。
— -c:将每个命令使用时间打印为相对于所有命令使用时间的百分比。此外,还有用户、系统和实时。
— -C:将记账文件合并到摘要文件中。如果摘要文件为旧用法,则将它转换为新用法。
— -d:将输出按平均磁盘I/O操作数进行分类。
— -D:将输出按总的磁盘I/O操作数进行分类和打印。
— -f:不要强制进行交互式阈值压缩。此标志必须与-v标志一起使用。
— -I:仅读取原始数据,不读取摘要文件。
— -j:打印每个调用的秒数,而不是每个类别的总的分钟数。
— -k:将输出按平均CPU时间进行分类。
— -K:将输出按CPU存储量整数进行分类和打印。
— -l:将系统时间和用户时间分离,而不是组合它们。
— -m:打印每个用户的进程数和CPU分钟数。
— -n:按调用数对输出进行分类。
— -r:将分类的顺序倒置。
— -s:将记账文件合并到摘要文件中。
— -t:打印每个命令的用时与用户和系统时间和之比。
— -u:暂挂所有其他标志并且打印每个命令的用户数字标识和命令名。
本文转自 bannerpei 51CTO博客,原文链接:http://blog.51cto.com/281816327/1615814,如需转载请自行联系原作者