Systemverwaltungshandbuch: Oracle Solaris Container - Ressourcenverwaltung und Solaris Zones

Kapitel 5 Verwalten des Extended Accounting (Vorgehen)

In diesem Kapitel wird die Verwaltung des Extended Accounting beschrieben.

Eine Einführung in das Extended Accounting finden Sie in Kapitel 4Einführung in das Extended Accounting.

Verwalten des Extended Accounting (Übersicht der Schritte)

Aufgabe 

Beschreibung 

Siehe 

Aktivieren des Extended Accounting. 

Verwenden des Extended Accounting zur Überwachung des Ressourcenverbrauchs durch einzelne, auf dem System ausgeführte Projekte. Mit dem Extended Accounting können Sie Verlaufsdaten für Aufgaben, Prozesse und Flows erfassen.

So aktivieren Sie das Extended Accounting für Prozesse, Aufgaben und Flows, So aktivieren Sie das Extended Accounting mit einem Startskript

Anzeigen des Extended Accounting-Status. 

Ermitteln des Status des Extended Accounting. 

So zeigen Sie den Extended Accounting-Status an

Anzeigen der verfügbaren Accounting-Ressourcen. 

Anzeigen der auf dem System verfügbaren Accounting-Ressourcen. 

So zeigen Sie die verfügbaren Accounting-Ressourcen an

Deaktivieren des Prozess-, Aufgaben- und Flow-Accounting. 

Deaktivieren des Extended Accounting. 

So deaktivieren Sie das Prozess-, Aufgaben- und Flow-Accounting

Verwenden der Perl-Schnittstelle für das Extended Accounting. 

Verwenden der Perl-Schnittstelle zum Entwickeln von benutzerdefinierten Skripten zur Berichterstattung und Extraktion. 

Verwenden der Perl-Schnittstelle für libexacct

Verwenden des Extended Accounting

Benutzer können Extended Accounting verwalten (starten, beenden, Konfigurationsparameter ändern), wenn Sie über ein entsprechendes Rechteprofil für den zu verwaltenden Extended Accounting-Typ verfügen:

ProcedureSo aktivieren Sie das Extended Accounting für Prozesse, Aufgaben und Flows

Mit dem Befehl acctadm aktivieren Sie das Extended Accounting für Aufgaben, Prozesse und Flows. Der optionale finale Parameter für acctadm gibt an, ob der Befehl an den Accounting-Komponenten eines Prozesses, einer Systemtask oder eines Flows ausgeführt werden soll.

  1. Melden Sie sich als Superuser an oder nehmen Sie eine entsprechende Rolle an.

    Rollen umfassen Autorisierungen und privilegierte Befehle. Weitere Informationen zu Rollen finden Sie unter Using the Solaris Management Tools With RBAC (Task Map) in System Administration Guide: Basic Administration.

  2. Aktivieren Sie das Extended Accounting für Prozesse.


    # acctadm -e extended -f /var/adm/exacct/proc process
    
  3. Aktivieren Sie das Extended Accounting für Aufgaben.


    # acctadm -e extended,mstate -f /var/adm/exacct/task task
    
  4. Aktivieren Sie das Extended Accounting für Flows.


    # acctadm -e extended -f /var/adm/exacct/flow flow
    
Siehe auch

Weitere Informationen finden Sie unter acctadm(1M).

So aktivieren Sie das Extended Accounting mit einem Startskript

Aktivieren Sie das Extended Accounting für die ständige Ausführung, indem Sie das Skript /etc/init.d/acctadm mit /etc/rc2.d verknüpfen.


# ln -s /etc/init.d/acctadm /etc/rc2.d/Snacctadm
# ln -s /etc/init.d/acctadm /etc/rc2.d/Knacctadm

Die Variable n wird durch eine Zahl ersetzt.

Anschließend müssen Sie das Extended Accounting mindestens einmal manuell aktivieren, um die Konfiguration einzurichten.

Weitere Informationen zur Accounting-Konfiguration finden Sie unter Konfiguration des Extended Accounting.

So zeigen Sie den Extended Accounting-Status an

Zum Anzeigen des aktuellen Status des Extended Accounting geben Sie den Befehl acctadm ohne Argumente ein.


# 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

Im obigen Beispiel ist das Systemtask-Accounting im erweiterten Modus und im mstate-Modus aktiv. Prozess- und Flow-Accounting sind im erweiterten Modus aktiv.


Hinweis –

In Bezug auf das Extended Accounting bezieht sich „microstate“ (mstate) auf die erweiterten Daten, die den Microstate-Prozessübergängen zugeordnet sind, die in der Prozessnutzungsdatei zur Verfügung stehen (siehe proc(4)). Diese Daten enthalten wesentlich mehr Details über die Aktivitäten des Prozesses als allgemeine oder erweiterte Datensätze.


So zeigen Sie die verfügbaren Accounting-Ressourcen an

Die verfügbaren Ressourcen variieren von System zu System und von Plattform zu Plattform. Mit dem Befehl acctadm und der Option -r können Sie die auf dem System verfügbaren Accounting-Ressourcengruppen anzeigen.


# 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

ProcedureSo deaktivieren Sie das Prozess-, Aufgaben- und Flow-Accounting

Zum Deaktivieren des Prozess-, Aufgaben- und Flow-Accounting geben Sie jeweils den Befehl acctadm mit der Option-x ein.

  1. Melden Sie sich als Superuser an oder nehmen Sie eine entsprechende Rolle an.

    Rollen umfassen Autorisierungen und privilegierte Befehle. Weitere Informationen zu Rollen finden Sie unter Using the Solaris Management Tools With RBAC (Task Map) in System Administration Guide: Basic Administration.

  2. Deaktivieren Sie das Prozess-Accounting.


    # acctadm -x process 
    
  3. Deaktivieren Sie das Aufgaben-Accounting.


    # acctadm -x task
    
  4. Deaktivieren Sie das Flow-Accounting.


    # acctadm -x flow
    
  5. Überprüfen Sie, ob Aufgaben-, Prozess-und Flow-Accounting deaktiviert wurden.


    	# 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

Verwenden der Perl-Schnittstelle für libexacct

So drucken Sie rekursiv den Inhalt eines exacct-Objekts

Mit dem folgenden Code drucken Sie rekursiv den Inhalt eines exacct-Objekts. Diese Eigenschaft wird von der Bibliothek als Funktion Sun::Solaris::Exacct::Object::dump() bereitgestellt. Diese Eigenschaft ist auch über die Convenience-Funktion ea_dump_object() verfügbar.


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);
             }
     }

So erstellen Sie einen neuen Gruppendatensatz und schreiben ihn in eine Datei

Mit dem folgenden Skript erstellen Sie einen neuen Gruppendatensatz und schreiben ihn in eine Datei namens /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;

So drucken Sie den Inhalt einer exacct-Datei

Mit dem folgenden Perl-Skript drucken Sie den Inhalt einer exacct-Datei.


#!/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);

Beispiel einer Ausgabe von Sun::Solaris::Exacct::Object->dump()

Das Folgende ist ein Beispiel für eine Ausgabe, die durch das Ausführen von Sun::Solaris::Exacct::Object->dump() an der Datei erzeugt wird, die unter So erstellen Sie einen neuen Gruppendatensatz und schreiben ihn in eine Datei erstellt wurde.


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