<chapter id="rmacct-1"><title>Extended Accounting (Overview)</title><highlights><para>By using the project and task facilities that are described in <olink targetptr="rmtaskproj-1" remap="internal">Chapter&nbsp;2, Projects and Tasks (Overview)</olink> to label and separate workloads,
you can monitor resource consumption by each workload. You can use the <emphasis>extended accounting</emphasis> subsystem to capture a detailed set of resource consumption
statistics on both processes and tasks.</para><para>The following topics are covered in this chapter.</para><itemizedlist><listitem><para><olink targetptr="rmacct-2" remap="internal">Introduction to Extended Accounting</olink></para>
</listitem><listitem><para><olink targetptr="rmacct-6" remap="internal">How Extended Accounting Works</olink></para>
</listitem><listitem><para><olink targetptr="rmacct-5" remap="internal">Extended Accounting Configuration</olink></para>
</listitem><listitem><para><olink targetptr="rmacct.task-18" remap="internal">Commands Used With Extended Accounting</olink></para>
</listitem><listitem><para><olink targetptr="rmacct-7" remap="internal">Perl Interface to libexacct</olink></para>
</listitem>
</itemizedlist><para>To begin using extended accounting, see <olink targetptr="rmacct.task-2" remap="internal">How
to Activate Extended Accounting for Processes, Tasks, and Flows</olink>.</para>
</highlights><sect1 id="rmacct-2"><title>Introduction to Extended Accounting</title><para>The extended accounting subsystem labels usage records with the project
for which the work was done. You can also use extended accounting, in conjunction
with the Internet Protocol Quality of Service (IPQoS) flow accounting module described
in <olink targetdoc="sysadv3" targetptr="ipqos-accounting-1" remap="external">Chapter 33, <citetitle remap="chapter">Using Flow Accounting and Statistics Gathering (Tasks),</citetitle> in <citetitle remap="book">System Administration Guide: IP Services</citetitle></olink>, to capture
network flow information on a system.</para><para>Before you can apply resource management mechanisms, you must first be able
to characterize the resource consumption demands that various workloads place on a
system. The extended accounting facility in the Solaris Operating System provides
a flexible way to record system and network resource consumption on a task or process
basis, or on the basis of selectors provided by the IPQoS <literal>flowacct</literal> module.
For more information, see <citerefentry><refentrytitle>ipqos</refentrytitle><manvolnum>7IPP</manvolnum></citerefentry>.</para><para>Unlike online monitoring tools, which enable you to measure system usage in
real time, extended accounting enables you to examine historical usage. You can then
make assessments of capacity requirements for future workloads.</para><para>With extended accounting data available, you can develop or purchase software
for resource chargeback, workload monitoring, or capacity planning.</para>
</sect1><sect1 id="rmacct-6"><title>How Extended Accounting Works</title><para>The extended accounting facility in the Solaris Operating System uses
a versioned, extensible file format to contain accounting data. Files that use this
data format can be accessed or be created by using the API provided in the included
library,  <literal>libexacct</literal> (see <olink targetdoc="group-refman" targetptr="libexacct-3lib" remap="external"><citerefentry><refentrytitle>libexacct</refentrytitle><manvolnum>3LIB</manvolnum></citerefentry></olink>).
These files can then be analyzed on any platform with extended accounting enabled,
and their data can be used for capacity planning and chargeback.</para><para>If extended accounting is active, statistics are gathered that can be examined
by the <filename>libexacct</filename> API. <filename>libexacct</filename> allows examination
of the <literal>exacct</literal> files either forward or backward. The API supports
third-party files that are generated by <filename>libexacct</filename> as well as
those files that are created by the kernel. There is a Practical Extraction and Report
Language (Perl) interface to <filename>libexacct</filename> that enables you to develop
customized reporting and extraction scripts. See <olink targetptr="rmacct-7" remap="internal">Perl
Interface to libexacct</olink>.</para><para>With extended accounting enabled, the task tracks the aggregate resource usage
of its member processes. A task accounting record is written at task completion. Interim
records on running processes and tasks can also be written. For more information on
tasks, see <olink targetptr="rmtaskproj-1" remap="internal">Chapter&nbsp;2, Projects and Tasks (Overview)</olink>.</para><figure id="rmacct-fig-33"><title>Task Tracking With Extended Accounting Activated</title><mediaobject><imageobject><imagedata entityref="rmexacct1"/>
</imageobject><textobject><simpara>Flow diagram shows how aggregate resource usage of a task's processes
is captured in the record that is written at task completion.</simpara>
</textobject>
</mediaobject>
</figure><sect2 id="rmacct-3"><title>Extensible Format</title><para>The extended accounting format is substantially more extensible than the <trademark>SunOS</trademark> legacy system accounting software format (see <olink targetdoc="sysadv2" targetptr="sysresacctsetup-35" remap="external"><citetitle remap="section">What is System Accounting?</citetitle> in <citetitle remap="book">System Administration Guide: Advanced Administration</citetitle></olink>). Extended accounting permits accounting metrics to be added
and removed from the system between releases, and even during system operation.</para><note><para>Both extended accounting and legacy system accounting software can be
active on your system at the same time.</para>
</note>
</sect2><sect2 id="rmacct-4"><title><literal>exacct</literal> Records and Format</title><para>Routines that allow <literal>exacct</literal> records to be created serve two
purposes.</para><itemizedlist><listitem><para>To enable third-party <literal>exacct</literal> files to be created.</para>
</listitem><listitem><para>To enable the creation of tagging records to be embedded in the kernel
accounting file by using the <filename>putacct</filename> system call (see <olink targetdoc="group-refman" targetptr="getacct-2" remap="external"><citerefentry><refentrytitle>getacct</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink>).</para><note><para>The <filename>putacct</filename> system call is also available from the
Perl interface. </para>
</note>
</listitem>
</itemizedlist><para>The format permits different forms of accounting records to be captured without
requiring that every change be an explicit version change. Well-written applications
that consume accounting data must ignore records they do not understand.</para><para>The <filename>libexacct</filename> library converts and produces files in the <literal>exacct</literal> format. This library is the <emphasis>only</emphasis> supported interface
to <literal>exacct</literal> format files.</para><note><para>The <command>getacct</command>, <command>putacct</command>, and <command>wracct</command> system calls do not apply to flows. The kernel creates flow records
and writes them to the file when IPQoS flow accounting is configured.</para>
</note>
</sect2><sect2 id="rmacct-8"><title>Using Extended Accounting on a Solaris System with Zones
Installed</title><para>The extended accounting subsystem collects and reports information for the entire
system (including non-global zones) when run in the global zone. The global administrator
can also determine resource consumption on a per-zone basis. See <olink targetptr="z.admin.ov-6" remap="internal">Extended Accounting on a Solaris System With Zones Installed</olink> for more information.</para>
</sect2>
</sect1><sect1 id="rmacct-5"><title>Extended Accounting Configuration</title><para>The <filename>/etc/acctadm.conf</filename> file contains the current extended
accounting configuration. The file is edited through the <command>acctadm</command> interface,
not by the user.</para><para>The directory <filename>/var/adm/exacct</filename> is the standard location
for placing extended accounting data. You can use the <command>acctadm</command> command
to specify a different location for the process and task accounting-data files. See <olink targetdoc="group-refman" targetptr="acctadm-1m" remap="external"><citerefentry><refentrytitle>acctadm</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> for more information.</para>
</sect1><sect1 id="rmacct.task-18"><title>Commands Used With Extended Accounting</title><informaltable frame="all"><tgroup cols="2" colsep="1" rowsep="1"><colspec colwidth="30*"/><colspec colwidth="70*"/><thead><row><entry><para>Command Reference</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><olink targetdoc="group-refman" targetptr="acctadm-1m" remap="external"><citerefentry><refentrytitle>acctadm</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink></para>
</entry><entry><para>Modifies various attributes of the extended accounting facility, stops and starts
extended accounting, and is used to select accounting attributes to track for processes,
tasks, and flows.</para>
</entry>
</row><row><entry><para><olink targetdoc="group-refman" targetptr="wracct-1m" remap="external"><citerefentry><refentrytitle>wracct</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink></para>
</entry><entry><para>Writes extended accounting records for active processes and active tasks.</para>
</entry>
</row><row><entry><para><olink targetdoc="group-refman" targetptr="lastcomm-1" remap="external"><citerefentry><refentrytitle>lastcomm</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink></para>
</entry><entry><para>Displays previously invoked commands. <command>lastcomm</command> can consume
either standard accounting-process data or extended-accounting process data.</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><para>For information on commands that are associated with tasks and projects,
see <olink targetptr="rmtaskproj.task-1" remap="internal">Example Commands and Command Options</olink>.
For information on IPQoS flow accounting, see <olink targetdoc="group-refman" targetptr="ipqosconf-1m" remap="external"><citerefentry><refentrytitle>ipqosconf</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink>.</para>
</sect1><sect1 id="rmacct-7"><title>Perl Interface to <command>libexacct</command></title><para>The Perl interface allows you to create Perl scripts that can read the
accounting files produced by the <literal>exacct</literal> framework. You can also
create Perl scripts that write <literal>exacct</literal> files.</para><para>The interface is functionally equivalent to the underlying C API. When possible,
the data obtained from the underlying C API is presented as Perl data types. This
feature makes accessing the data easier and it removes the need for buffer pack and
unpack operations. Moreover, all memory management is performed by the Perl library.</para><para>The various project, task, and <literal>exacct</literal>-related functions are
separated into groups. Each group of functions is located in a separate Perl module.
Each module begins with the Sun standard <literal>Sun::Solaris::</literal> Perl package
prefix. All of the classes provided by the Perl <literal>exacct</literal> library
are found under the <literal>Sun::Solaris::Exacct</literal> module.</para><para>The underlying <olink targetdoc="group-refman" targetptr="libexacct-3lib" remap="external"><citerefentry><refentrytitle>libexacct</refentrytitle><manvolnum>3LIB</manvolnum></citerefentry></olink> library
provides operations on <literal>exacct</literal> format files, catalog tags, and <literal>exacct</literal> objects. <literal>exacct</literal> objects are subdivided into two
types:</para><itemizedlist><listitem><para>Items, which are single-data values (scalars)</para>
</listitem><listitem><para>Groups, which are lists of Items</para>
</listitem>
</itemizedlist><para>The following table summarizes each of the modules.</para><informaltable frame="all" pgwide="1"><tgroup cols="3" colsep="1" rowsep="1"><colspec colwidth="27*"/><colspec colwidth="39*"/><colspec colwidth="33*"/><thead><row><entry><para>Module (should not contain spaces)</para>
</entry><entry><para>Description</para>
</entry><entry><para>For More Information</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>Sun::Solaris::Project</literal></para>
</entry><entry><para>This module provides functions to access the project manipulation functions <olink targetdoc="group-refman" targetptr="getprojid-2" remap="external"><citerefentry><refentrytitle>getprojid</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="endprojent-3project" remap="external"><citerefentry><refentrytitle>endprojent</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink> , <olink targetdoc="group-refman" targetptr="fgetprojent-3project" remap="external"><citerefentry><refentrytitle>fgetprojent</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="getdefaultproj-3project" remap="external"><citerefentry><refentrytitle>getdefaultproj</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="getprojbyid-3project" remap="external"><citerefentry><refentrytitle>getprojbyid</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="getprojbyname-3project" remap="external"><citerefentry><refentrytitle>getprojbyname</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="getprojent-3project" remap="external"><citerefentry><refentrytitle>getprojent</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="getprojidbyname-3project" remap="external"><citerefentry><refentrytitle>getprojidbyname</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="inproj-3project" remap="external"><citerefentry><refentrytitle>inproj</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="project-walk-3project" remap="external"><citerefentry><refentrytitle>project_walk</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="setproject-3project" remap="external"><citerefentry><refentrytitle>setproject</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink> ,
and <olink targetdoc="group-refman" targetptr="setprojent-3project" remap="external"><citerefentry><refentrytitle>setprojent</refentrytitle><manvolnum>3PROJECT</manvolnum></citerefentry></olink>. </para>
</entry><entry><para><literal>Project</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Task</literal></para>
</entry><entry><para>This module provides functions to access the task manipulation functions <olink targetdoc="group-refman" targetptr="gettaskid-2" remap="external"><citerefentry><refentrytitle>gettaskid</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink> and <olink targetdoc="group-refman" targetptr="settaskid-2" remap="external"><citerefentry><refentrytitle>settaskid</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink>.</para>
</entry><entry><para><literal>Task</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Exacct</literal></para>
</entry><entry><para>This module is the top-level <literal>exacct</literal> module. This module provides
functions to access the <literal>exacct</literal>-related system calls <olink targetdoc="group-refman" targetptr="getacct-2" remap="external"><citerefentry><refentrytitle>getacct</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="putacct-2" remap="external"><citerefentry><refentrytitle>putacct</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink>,
and <olink targetdoc="group-refman" targetptr="wracct-2" remap="external"><citerefentry><refentrytitle>wracct</refentrytitle><manvolnum>2</manvolnum></citerefentry></olink>. This module
also provides functions to access the <olink targetdoc="group-refman" targetptr="libexacct-3lib" remap="external"><citerefentry><refentrytitle>libexacct</refentrytitle><manvolnum>3LIB</manvolnum></citerefentry></olink> library
function <olink targetdoc="group-refman" targetptr="ea-error-3exacct" remap="external"><citerefentry><refentrytitle>ea_error</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>. Constants
for all of the  <literal>exacct</literal> EO_*, EW_*, EXR_*, P_*, and TASK_* macros
are also provided in this module.</para>
</entry><entry><para><literal>Exacct</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Exacct:: Catalog</literal></para>
</entry><entry><para>This module provides object-oriented methods to access the bitfields in an <literal>exacct</literal> catalog tag. This module also provides access to the constants for
the EXC_*, EXD_*, and EXD_* macros.</para>
</entry><entry><para><literal>Exacct::Catalog</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Exacct:: File</literal></para>
</entry><entry><para>This module provides object-oriented methods to access the <literal>libexacct</literal> accounting file functions <olink targetdoc="group-refman" targetptr="ea-open-3exacct" remap="external"><citerefentry><refentrytitle>ea_open</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="ea-close-3exacct" remap="external"><citerefentry><refentrytitle>ea_close</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="ea-get-creator-3exacct" remap="external"><citerefentry><refentrytitle>ea_get_creator</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="ea-get-hostname-3exacct" remap="external"><citerefentry><refentrytitle>ea_get_hostname</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="ea-next-object-3exacct" remap="external"><citerefentry><refentrytitle>ea_next_object</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>, <olink targetdoc="group-refman" targetptr="ea-previous-object-3exacct" remap="external"><citerefentry><refentrytitle>ea_previous_object</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>, and <olink targetdoc="group-refman" targetptr="ea-write-object-3exacct" remap="external"><citerefentry><refentrytitle>ea_write_object</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink>.</para>
</entry><entry><para><literal>Exacct::File</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Exacct:: Object</literal></para>
</entry><entry><para>This module provides object-oriented methods to access an individual <literal>exacct</literal> accounting file object. An <literal>exacct</literal> object is represented
as an opaque reference blessed into the appropriate <literal>Sun::Solaris::Exacct::Object</literal> subclass. This module is further subdivided into the object types Item
and Group. At this level, there are methods to access the <olink targetdoc="group-refman" targetptr="ea-match-object-catalog-3exacct" remap="external"><citerefentry><refentrytitle>ea_match_object_catalog</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink> and <olink targetdoc="group-refman" targetptr="ea-attach-to-object-3exacct" remap="external"><citerefentry><refentrytitle>ea_attach_to_object</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink> functions. </para>
</entry><entry><para><literal>Exacct::Object</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Exacct:: Object::Item</literal> </para>
</entry><entry><para>This module provides object-oriented methods to access an individual <literal>exacct</literal> accounting file Item. Objects of this type inherit from <literal>Sun::Solaris::Exacct::Object</literal>.</para>
</entry><entry><para><literal>Exacct::Object::Item</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Exacct:: Object::Group</literal> </para>
</entry><entry><para>This module provides object-oriented methods to access an individual <literal>exacct</literal> accounting file Group. Objects of this type inherit from <literal>Sun::Solaris::Exacct::Object</literal>. These objects provide access to the <olink targetdoc="group-refman" targetptr="ea-attach-to-group-3exacct" remap="external"><citerefentry><refentrytitle>ea_attach_to_group</refentrytitle><manvolnum>3EXACCT</manvolnum></citerefentry></olink> function.
The Items contained within the Group are presented as a Perl array. </para>
</entry><entry><para><literal>Exacct::Object::Group</literal>(3PERL)</para>
</entry>
</row><row><entry><para><literal>Sun::Solaris::Kstat</literal></para>
</entry><entry><para>This module provides a Perl tied hash interface to the <command>kstat</command> facility.
A usage example for this module can be found in <literal>/bin/kstat</literal>, which
is written in Perl.</para>
</entry><entry><para><literal>Kstat</literal>(3PERL)</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><para>For examples that show how to use the modules described in the previous table,
see <olink targetptr="rmacct.task-19" remap="internal">Using the Perl Interface to libexacct</olink>.</para>
</sect1>
</chapter>