xref: /illumos-gate/usr/src/man/man8/kstat.8 (revision 3b8c21f5248de9b48d63b0842c93815134478ded)
1.\"
2.\" The contents of this file are subject to the terms of the
3.\" Common Development and Distribution License (the "License").
4.\" You may not use this file except in compliance with the License.
5.\"
6.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7.\" or http://www.opensolaris.org/os/licensing.
8.\" See the License for the specific language governing permissions
9.\" and limitations under the License.
10.\"
11.\" When distributing Covered Code, include this CDDL HEADER in each
12.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13.\" If applicable, add the following below this CDDL HEADER, with the
14.\" fields enclosed by brackets "[]" replaced with your own identifying
15.\" information: Portions Copyright [yyyy] [name of copyright owner]
16.\"
17.\" Copyright (c) 2000, Sun Microsystems, Inc. All Rights Reserved
18.\" Copyright 2025 Edgecast Cloud LLC.
19.\"
20.Dd June 19, 2025
21.Dt KSTAT 8
22.Os
23.Sh NAME
24.Nm kstat
25.Nd display kernel statistics
26.Sh SYNOPSIS
27.Nm
28.Op Fl Cjlq
29.Op Fl p Op Fl V
30.Op Fl T Ar u Ns | Ns Ar d
31.Op Fl c Ar class
32.Op Fl m Ar module
33.Op Fl i Ar instance
34.Op Fl n Ar name
35.Op Fl s Ar statistic
36.Op Ar interval Op Ar count
37.Nm
38.Op Fl Cjlq
39.Op Fl p Op Fl V
40.Op Fl T Ar u Ns | Ns Ar d
41.Op Fl c Ar class
42.Oo
43.Ar module Ns
44.Oo : Ns Ar instance Ns
45.Oo : Ns Ar name Ns
46.Oo : Ns Ar statistic Oc Oc Oc Oc Ns ...
47.Op Ar interval Op Ar count
48.Sh DESCRIPTION
49The
50.Nm
51utility examines the available kernel statistics, or kstats, on
52the system and reports those statistics which match the criteria specified on
53the command line.
54Each matching statistic is printed with its module, instance,
55and name fields, as well as its actual value.
56.Pp
57Kernel statistics may be published by various kernel subsystems, such as
58drivers or loadable modules; each kstat has a module field that denotes its
59publisher.
60Since each module might have countable entities
61.Po such as multiple disks associated with the
62.Xr sd 4D
63driver
64.Pc
65for which it wishes to report statistics, the kstat also has an instance field
66to index the statistics for each entity; kstat instances are numbered starting
67from zero.
68Finally, the kstat is given a name unique within its module.
69.Pp
70Each kstat may be a special kstat type, an array of name-value pairs, or raw
71data.
72In the name-value case, each reported value is given a label, which we
73refer to as the statistic.
74Known raw and special kstats are given statistic labels for each of their
75values by
76.Nm ;
77thus, all published values can be referenced as
78.Ar module : Ns Ar instance : Ns Ar name : Ns Ar statistic .
79.Pp
80When invoked without any module operands or options,
81.Nm
82will match all defined statistics on the system.
83Example invocations are provided below.
84All times are displayed as fractional seconds since system boot.
85.Sh OPTIONS
86The tests specified by the following options are logically ANDed, and all
87matching kstats will be selected.
88A regular expression containing shell metacharacters must be protected from
89the shell by enclosing it with the appropriate quotes.
90.Pp
91The argument for the
92.Fl c , i , m , n ,
93and
94.Fl s
95options may be specified as a shell glob pattern, or a regular expression
96enclosed in '/' characters.
97.Bl -tag -width ""
98.It Fl C
99Displays output in parsable format with a colon as separator.
100.It Fl c Ar class
101Displays only kstats that match the specified class.
102.Ar class
103is a kernel-defined string which classifies the
104.Qq type
105of the kstat.
106.It Fl i Ar instance
107Displays only kstats that match the specified instance.
108.It Fl j
109Displays output in JSON format.
110.It Fl l
111Lists matching kstat names without displaying values.
112.It Fl m Ar module
113Displays only kstats that match the specified module.
114.It Fl n Ar name
115Displays only kstats that match the specified name.
116.It Fl p Op Fl V
117Displays output in parsable format, with
118.Fl V
119used, only values are displayed.
120All example output in this document is given in this format.
121If this option is not specified,
122.Nm
123produces output in a human-readable, table format.
124.It Fl q
125Displays no output, but return appropriate exit status for matches against
126given criteria.
127.It Fl s Ar statistic
128Displays only kstats that match the specified statistic.
129.It Fl T Ar d | Ar u
130Displays a time stamp before each statistics block, either in
131.Xr date 1
132format
133.Pq Ar d
134or as an alphanumeric representation of the value returned by
135.Xr time 2
136.Pq Ar u .
137.El
138.Sh OPERANDS
139The following operands are supported:
140.Bl -tag -width ""
141.It Ar module : Ns Ar instance : Ns Ar name : Ns Ar statistic
142Alternate method of specifying module, instance, name, and statistic as
143described above.
144Each of the module, instance, name, or statistic specifiers
145may be a shell glob pattern or a regular expression enclosed by
146.Sq /
147characters.
148It is possible to use both specifier types within a single operand.
149Leaving a specifier empty is equivalent to using the
150.Sq *
151glob pattern for that specifier.
152.It Ar interval
153The number of seconds between reports.
154.It Ar count
155The number of reports to be printed.
156.El
157.Sh FILES
158.Bl -tag -width ""
159.It Sy /dev/kstat
160kernel statistics driver
161.El
162.Sh EXIT STATUS
163The following exit values are returned:
164.Bl -tag -width ""
165.It Sy 0
166One or more statistics were matched.
167.It Sy 1
168No statistics were matched.
169.It Sy 2
170Invalid command line options were specified.
171.It Sy 3
172A fatal error occurred.
173.El
174.Sh EXAMPLES
175In the following examples, all the command lines in a block produce the same
176output, as shown immediately below.
177The exact statistics and values will of course vary from machine to machine.
178.Bl -tag -width ""
179.It Sy Example 1 No Using the Nm kstat No Command
180.Bd -literal
181example$ \fBkstat -p -m unix -i 0 -n system_misc -s 'avenrun*'\fR
182example$ \fBkstat -p -s 'avenrun*'\fR
183example$ \fBkstat -p 'unix:0:system_misc:avenrun*'\fR
184example$ \fBkstat -p ':::avenrun*'\fR
185example$ \fBkstat -p ':::/^avenrun_[0-9]+min$/'\fR
186
187unix:0:system_misc:avenrun_15min        3
188unix:0:system_misc:avenrun_1min 4
189unix:0:system_misc:avenrun_5min 2
190.Ed
191.It Sy Example 2 No Using the Nm kstat No Command
192.Bd -literal
193example$ \fBkstat -p -m cpu_stat -s 'intr*'\fR
194example$ \fBkstat -p cpu_stat:::/^intr/\fR
195
196cpu_stat:0:cpu_stat0:intr       29682330
197cpu_stat:0:cpu_stat0:intrblk    87
198cpu_stat:0:cpu_stat0:intrthread 15054222
199cpu_stat:1:cpu_stat1:intr       426073
200cpu_stat:1:cpu_stat1:intrblk    51
201cpu_stat:1:cpu_stat1:intrthread 289668
202cpu_stat:2:cpu_stat2:intr       134160
203cpu_stat:2:cpu_stat2:intrblk    0
204cpu_stat:2:cpu_stat2:intrthread 131
205cpu_stat:3:cpu_stat3:intr       196566
206cpu_stat:3:cpu_stat3:intrblk    30
207cpu_stat:3:cpu_stat3:intrthread 59626
208.Ed
209.It Sy Example 3 No Using the Nm kstat No Command
210.Bd -literal
211example$ \fBkstat -p :::state ':::avenrun*'\fR
212example$ \fBkstat -p :::state :::/^avenrun/\fR
213
214cpu_info:0:cpu_info0:state      on-line
215cpu_info:1:cpu_info1:state      on-line
216cpu_info:2:cpu_info2:state      on-line
217cpu_info:3:cpu_info3:state      on-line
218unix:0:system_misc:avenrun_15min        4
219unix:0:system_misc:avenrun_1min 10
220unix:0:system_misc:avenrun_5min 3
221.Ed
222.It Sy Example 4 No Using the Nm kstat No Command
223.Bd -literal
224example$ \fBkstat -p 'unix:0:system_misc:avenrun*' 1 3\fR
225unix:0:system_misc:avenrun_15min        15
226unix:0:system_misc:avenrun_1min 11
227unix:0:system_misc:avenrun_5min 21
228
229unix:0:system_misc:avenrun_15min        15
230unix:0:system_misc:avenrun_1min 11
231unix:0:system_misc:avenrun_5min 21
232
233unix:0:system_misc:avenrun_15min        15
234unix:0:system_misc:avenrun_1min 11
235unix:0:system_misc:avenrun_5min 21
236.Ed
237.It Sy Example 5 No Using the Nm kstat No Command
238.Bd -literal
239example$ \fBkstat -p -T d 'unix:0:system_misc:avenrun*' 5 2\fR
240Thu Jul 22 19:39:50 1999
241unix:0:system_misc:avenrun_15min        12
242unix:0:system_misc:avenrun_1min 0
243unix:0:system_misc:avenrun_5min 11
244
245Thu Jul 22 19:39:55 1999
246unix:0:system_misc:avenrun_15min        12
247unix:0:system_misc:avenrun_1min 0
248unix:0:system_misc:avenrun_5min 11
249.Ed
250.It Sy Example 6 No Using the Nm kstat No Command
251.Bd -literal
252example$ \fBkstat -p -T u 'unix:0:system_misc:avenrun*'\fR
253932668656
254unix:0:system_misc:avenrun_15min        14
255unix:0:system_misc:avenrun_1min 5
256unix:0:system_misc:avenrun_5min 18
257.Ed
258.El
259.Sh SEE ALSO
260.Xr date 1 ,
261.Xr sh 1 ,
262.Xr time 2 ,
263.Xr gmatch 3GEN ,
264.Xr kstat 3KSTAT ,
265.Xr kstat 4D ,
266.Xr sd 4D ,
267.Xr attributes 7 ,
268.Xr regex 7 ,
269.Xr kstat 9S
270.Sh NOTES
271If the pattern argument contains glob or RE metacharacters which are also
272shell metacharacters, it will be necessary to enclose the pattern with
273appropriate shell quotes.
274