monitor(4)monitor(4)Namemonitor - Format of Monitor performance data
Syntax
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/dk.h>
#include <sys/buf.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/dir.h>
#include <sys/param.h>
#include <net/if.h>
#include <netinet/in.h>
#include monitor.h
Description
A monitor data file consists of a number of different sized data
records. The format the data record and all the associated constants
are described in the include file "monitor.h". The other include files
listed above are needed when "monitor.h" is used. Each constant is
written in three forms. Use the one that suits your taste. For exam‐
ple the monitor version number is:
#define MON$C_MAJOR (2)
#define MON$C_MINOR (3)
#define MON_MAJOR (MON$C_MAJOR)
#define MON_MINOR (MON$C_MINOR)
#define MonitorRevMajor (MON$C_MAJOR)
#define MonitorRevMinor (MON$C_MINOR)
The first four bytes of each record are described by the structure:
struct mon_header {
char mon_type, /* record type */
mon_flag ; /* Other information */
short mon_length ; /* record length */
};
The type field indicates what kind of monitor data record it is. The
currently supported data records are:
──────────────────────────────────────────────────────────────────────
Constant Value Description
──────────────────────────────────────────────────────────────────────
MON$C_FIRST 0 The first record written to the file.
MON$C_LAST 1 Hopefully the last record written.
MON$C_SAMPLE 2 The sample summary.
MON$C_CPU 4 Interrupts, system calls, time in states, etc
MON$C_TTY 5 TTY I/O
MON$C_DISK 6 Disk I/O
MON$C_FREE 7 Free memory
MON$C_FORK 8 Fork data
MON$C_PAGE 9 Paging data
MON$C_SWAP 11 Swap space utilization
MON$C_USER 13 Number of users
MON$C_NETIF 14 Network interface data
MON$C_MEMORY 15 All memory information
MON$C_LOADAVE 16 Load averages
MON$C_CACHE 17 Buffer and namei cache
──────────────────────────────────────────────────────────────────────
The flag field is a set of bit flags to encode other information. Cur‐
rently the only value used is MON$M_VALID to indicate whether the data
is valid. Usually all records are valid, but in some cases a record
will be marked invalid and should be ignored.
The last field is the length of the data record. The amount of data
after the header can be found by subtracting the header length.
A data file always begins with a FIRST record. The FIRST record con‐
tains a variety of static data such as the system hostname, the session
start time and the system boot time. Also included is a bit mask to
indicate which data records were collected and for those types that can
have multiple records, the number.
Following the FIRST record will usually be a SAMPLE record, though it's
possible for it to be a LAST or another FIRST record. The SAMPLE
record contains a timestamp when the sample was taken, the number of
clock ticks since boot and sum of the lengths of the data records asso‐
ciated with that sample. The data records that follow the sample are
sorted in ascending order according to the value of the type field.
So, if data was collected on TTY I/O, disk statistics and swap space,
the TTY (5) record will appear first followed by the DISK (6) record(s)
and finally the SWAP (11) record.
Because the data is guaranteed to appear in a particular order it is
possible to use the readv(2) system call to read an entire sample at
once. There are example programs that show how this is done. In gen‐
eral the algorithm is:
while( get-a-record != EOF )
if( the-record is a FIRST )
Clean up from the previous session.
Save the mon_option field.
Turn off the FIRST and SAMPLE bits.
Setup the I/O vector for readv(2).
else if( the-record is a SAMPLE )
Read the sample.
else if( the-record is a LAST )
Clean up from the previous version.
else
Unexpected record type.
If monitor is allowed to exit gracefully the last record written will
be a LAST record. Frequently monitor doesn't have the opportunity to
exit gracefully and the only way to distinguish between sessions if the
presense of a FIRST record.
Restrictions
Monitor will occasionally write empty data records. They can be recog‐
nized by fact that the value in the length field is the length of just
the header. Empty SAMPLE records do not have any other data associated
with them.
See Alsomonitor(1), mon_tools(1), mon_filters(1)monitor(4)