この章では、拡張アカウンティングサブシステムを管理する方法について説明します。
拡張アカウンティングサブシステムの概要については、第 4 章拡張アカウンティング (概要)を参照してください。
|
タスク |
説明 |
説明 |
|---|---|---|
|
拡張アカウンティング機能を起動します。 |
拡張アカウンティングを使用して、システムで実行されている各プロジェクトの資源消費を監視します。「拡張アカウンティング」サブシステムを使用すると、タスク、プロセス、およびフローの履歴データを取り込むことができます。 |
「プロセス、タスク、およびフローの拡張アカウンティングを起動する方法」、「起動スクリプトを使って拡張アカウンティングを起動する方法」 |
|
拡張アカウンティングの状態を表示します。 |
拡張アカウンティング機能の状態を調べます。 | |
|
使用可能なアカウンティング資源を表示します。 |
システム上の使用可能なアカウンティング資源を表示します。 | |
|
プロセス、タスク、およびフローのアカウンティング機能を停止します。 |
拡張アカウンティング機能をオフにします。 | |
|
拡張アカウンティング機能に対する Perl インタフェースを使用します。 |
Perl インタフェースを使用して、報告および抽出用のカスタムスクリプトを作成します。 |
ユーザーは、管理対象の拡張アカウンティングの種類に適した権利プロファイルがあれば、拡張アカウンティングの管理 (アカウンティングの開始、アカウンティングの停止、およびアカウンティング構成パラメータの変更) を行うことができます。
フロー管理
プロセス管理
タスク管理
タスク、プロセス、およびフローの拡張アカウンティング機能を起動するには、acctadm コマンドを使用します。acctadm の最後に付けられたオプションのパラメータは、このコマンドが、拡張アカウンティング機能のプロセスアカウンティング構成要素、システムタスクアカウンティング構成要素、フローアカウンティング構成要素のいずれに作用するかを示します。
スーパーユーザーになるか、同等の役割を引き受けます。
役割には、認証と特権コマンドが含まれます。役割の詳細については、『Solaris のシステム管理 (基本編)』の「Solaris 管理ツールを RBAC と組み合わせて使用する (作業マップ)」を参照してください。
プロセスの拡張アカウンティングを起動します。
# acctadm -e extended -f /var/adm/exacct/proc process |
タスクの拡張アカウンティングを起動します。
# acctadm -e extended,mstate -f /var/adm/exacct/task task |
フローの拡張アカウンティングを起動します。
# acctadm -e extended -f /var/adm/exacct/flow flow |
詳細は、acctadm(1M) のマニュアルページを参照してください。
/etc/init.d/acctadm スクリプトへのリンクを /etc/rc2.d に作成することにより、実行中に拡張アカウンティングを起動できます。
# ln -s /etc/init.d/acctadm /etc/rc2.d/Snacctadm # ln -s /etc/init.d/acctadm /etc/rc2.d/Knacctadm |
変数 n は番号で置き換えられます。
構成を設定するために、少なくとも一度は拡張アカウンティングを手動で起動する必要があります。
アカウンティング構成の詳細については、「拡張アカウンティング構成」を参照してください。
引数なしで acctadm と入力すると、拡張アカウンティング機能の現在の状態が表示されます。
# acctadm
Task accounting: active
Task accounting file: /var/adm/exacct/task
Tracked task resources: extended
Untracked task resources: none
Process accounting: active
Process accounting file: /var/adm/exacct/proc
Tracked process resources: extended
Untracked process resources: host
Flow accounting: active
Flow accounting file: /var/adm/exacct/flow
Tracked flow resources: extended
Untracked flow resources: none
|
この例では、システムタスクアカウンティングが拡張モードと mstate モードで動作しています。プロセスアカウンティングとフローアカウンティングは、拡張モードで動作しています。
拡張アカウンティングの分野では、マイクロステート (mstate) は、プロセス状態の微小な変化を反映した拡張データを意味し、このデータはプロセス使用状況ファイルで利用できます (proc(4) のマニュアルページを参照)。このデータは、プロセスの活動に関して、基本レコードや拡張レコードよりも詳細な情報を提供します。
使用可能な資源は、システムやプラットフォームによってさまざまです。acctadm コマンドに -r オプションを付けて実行すると、システム上の使用可能なアカウンティング資源グループを表示できます。
# acctadm -r process: extended pid,uid,gid,cpu,time,command,tty,projid,taskid,ancpid,wait-status,zone,flag, memory,mstatedisplays as one line basic pid,uid,gid,cpu,time,command,tty,flag task: extended taskid,projid,cpu,time,host,mstate,anctaskid,zone basic taskid,projid,cpu,time flow: extended saddr,daddr,sport,dport,proto,dsfield,nbytes,npkts,action,ctime,lseen,projid,uid basic saddr,daddr,sport,dport,proto,nbytes,npkts,action |
プロセス、タスク、およびフローのアカウンティングを停止するには、それぞれを個別にオフにします。そのためには、acctadm コマンドに -x オプションを付けて実行します。
スーパーユーザーになるか、同等の役割を引き受けます。
役割には、認証と特権コマンドが含まれます。役割の詳細については、『Solaris のシステム管理 (基本編)』の「Solaris 管理ツールを RBAC と組み合わせて使用する (作業マップ)」を参照してください。
プロセスアカウンティングをオフにします。
# acctadm -x process |
タスクアカウンティングをオフにします。
# acctadm -x task |
フローアカウンティングをオフにします。
# acctadm -x flow |
タスクアカウンティング、プロセスアカウンティング、およびフローアカウンティングがオフになったことを確認します。
# acctadm
Task accounting: inactive
Task accounting file: none
Tracked task resources: extended
Untracked task resources: none
Process accounting: inactive
Process accounting file: none
Tracked process resources: extended
Untracked process resources: host
Flow accounting: inactive
Flow accounting file: none
Tracked flow resources: extended
Untracked flow resources: none
|
exacct オブジェクトの内容を再帰的に出力するには、次のコードを使用します。この機能は、ライブラリによって Sun::Solaris::Exacct::Object::dump() 関数として提供されています。ea_dump_object() という簡易関数でこの機能を利用することもできます。
sub dump_object
{
my ($obj, $indent) = @_;
my $istr = ' ' x $indent;
#
# Retrieve the catalog tag. Because we are
# doing this in an array context, the
# catalog tag will be returned as a (type, catalog, id)
# triplet, where each member of the triplet will behave as
# an integer or a string, depending on context.
# If instead this next line provided a scalar context, e.g.
# my $cat = $obj->catalog()->value();
# then $cat would be set to the integer value of the
# catalog tag.
#
my @cat = $obj->catalog()->value();
#
# If the object is a plain item
#
if ($obj->type() == &EO_ITEM) {
#
# Note: The '%s' formats provide s string context, so
# the components of the catalog tag will be displayed
# as the symbolic values. If we changed the '%s'
# formats to '%d', the numeric value of the components
# would be displayed.
#
printf("%sITEM\n%s Catalog = %s|%s|%s\n",
$istr, $istr, @cat);
$indent++;
#
# Retrieve the value of the item. If the item contains
# in turn a nested exacct object (i.e., an item or
# group),then the value method will return a reference
# to the appropriate sort of perl object
# (Exacct::Object::Item or Exacct::Object::Group).
# We could of course figure out that the item contained
# a nested item orgroup by examining the catalog tag in
# @cat and looking for a type of EXT_EXACCT_OBJECT or
# EXT_GROUP.
#
my $val = $obj->value();
if (ref($val)) {
# If it is a nested object, recurse to dump it.
dump_object($val, $indent);
} else {
# Otherwise it is just a 'plain' value, so
# display it.
printf("%s Value = %s\n", $istr, $val);
}
#
# Otherwise we know we are dealing with a group. Groups
# represent contents as a perl list or array (depending on
# context), so we can process the contents of the group
# with a 'foreach' loop, which provides a list context.
# In a list context the value method returns the content
# of the group as a perl list, which is the quickest
# mechanism, but doesn't allow the group to be modified.
# If we wanted to modify the contents of the group we could
# do so like this:
# my $grp = $obj->value(); # Returns an array reference
# $grp->[0] = $newitem;
# but accessing the group elements this way is much slower.
#
} else {
printf("%sGROUP\n%s Catalog = %s|%s|%s\n",
$istr, $istr, @cat);
$indent++;
# 'foreach' provides a list context.
foreach my $val ($obj->value()) {
dump_object($val, $indent);
}
printf("%sENDGROUP\n", $istr);
}
}
|
新しいグループレコードを作成して /tmp/exacct というファイルに書き込むには、次のスクリプトを使用します。
#!/usr/bin/perl
use strict;
use warnings;
use Sun::Solaris::Exacct qw(:EXACCT_ALL);
# Prototype list of catalog tags and values.
my @items = (
[ &EXT_STRING | &EXC_DEFAULT | &EXD_CREATOR => "me" ],
[ &EXT_UINT32 | &EXC_DEFAULT | &EXD_PROC_PID => $$ ],
[ &EXT_UINT32 | &EXC_DEFAULT | &EXD_PROC_UID => $< ],
[ &EXT_UINT32 | &EXC_DEFAULT | &EXD_PROC_GID => $( ],
[ &EXT_STRING | &EXC_DEFAULT | &EXD_PROC_COMMAND => "/bin/rec" ],
);
# Create a new group catalog object.
my $cat = ea_new_catalog(&EXT_GROUP | &EXC_DEFAULT | &EXD_NONE)
# Create a new Group object and retrieve its data array.
my $group = ea_new_group($cat);
my $ary = $group->value();
# Push the new Items onto the Group array.
foreach my $v (@items) {
push(@$ary, ea_new_item(ea_new_catalog($v->[0]), $v->[1]));
}
# Open the exacct file, write the record & close.
my $f = ea_new_file('/tmp/exacct', &O_RDWR | &O_CREAT | &O_TRUNC)
|| die("create /tmp/exacct failed: ", ea_error_str(), "\n");
$f->write($group);
$f = undef;
|
exacct ファイルの内容を出力するには、次の Perl スクリプトを使用します。
#!/usr/bin/perl
use strict;
use warnings;
use Sun::Solaris::Exacct qw(:EXACCT_ALL);
die("Usage is dumpexacct <exacct file>\n") unless (@ARGV == 1);
# Open the exact file and display the header information.
my $ef = ea_new_file($ARGV[0], &O_RDONLY) || die(error_str());
printf("Creator: %s\n", $ef->creator());
printf("Hostname: %s\n\n", $ef->hostname());
# Dump the file contents
while (my $obj = $ef->get()) {
ea_dump_object($obj);
}
# Report any errors
if (ea_error() != EXR_OK && ea_error() != EXR_EOF) {
printf("\nERROR: %s\n", ea_error_str());
exit(1);
}
exit(0);
|
「新しいグループレコードを作成してファイルに書き込む方法」で作成されたファイルに Sun::Solaris::Exacct::Object->dump() を実行した場合の出力例を示します。
Creator: root
Hostname: localhost
GROUP
Catalog = EXT_GROUP|EXC_DEFAULT|EXD_NONE
ITEM
Catalog = EXT_STRING|EXC_DEFAULT|EXD_CREATOR
Value = me
ITEM
Catalog = EXT_UINT32|EXC_DEFAULT|EXD_PROC_PID
Value = 845523
ITEM
Catalog = EXT_UINT32|EXC_DEFAULT|EXD_PROC_UID
Value = 37845
ITEM
Catalog = EXT_UINT32|EXC_DEFAULT|EXD_PROC_GID
Value = 10
ITEM
Catalog = EXT_STRING|EXC_DEFAULT|EXD_PROC_COMMAND
Value = /bin/rec
ENDGROUP
|