kstat - format of output data?

Hi,

I am looking for a cpu usage data (%usr, %iowait, %idle, %kernel) using kstat. The output of kstat is below. How do I interpret those numeric values? In other words, how do I calculate the percentage value using the values below?

Thanks a lot!
Ozvena

module: cpu_stat                        instance: 9
name:   cpu_stat9                       class:    misc

.
.
.

        idle                            1033213481
        iowait                          0
        kernel                          13188786
        user                            40271834
.
.
.
.

Even with a question like... no mention of which os is involved. :frowning: There is no hope...

That looks like output from the SunOS kstat command. I really don't understand this kstat driver or kstat library on SunOS. Traditionally, this stuff would come from a sysinfo structure. "nm /dev/ksyms" shows that the sysinfo structure is there and the structure is documented in /usr/include/sys/sysinfo.h. So that is where I would expect SunOS to get this info. After studying the sar source code which Sun so kindly made available yesterday, it does appear that you are looking at the right data.

So how did you figure this much out? Were you reading the source code too, or did you have some kstat reference?

Roughly, you read the numbers once. And then you wait. And then you read them again. Then you subtract the first numbers from the second to get an array of deltas. You have 10 instances so I guess you have 10 cpus. Consider just one instance. (Or maybe you want to add the instances together to get a system-wide view.) You add the deltas up and you have total number of times that any of the counters for that cpu incremented during the wait period. Now you figure out how much of the total each piece is. That gives the percentages over the wait period.

You know, you could just run "sar 1 4" or something.

Thank you for your response.

Yes, this is Sun OS kstat command.

�So how did you figure this much out?� �Were you reading the source code too, or did you have some kstat reference?�

Well, our product performance is monitored by a third party SW that we have no detail information about. This monitoring SW uses kstat as we have learned and data coming out of this monitor concern our customer. We did monitor our system (cpu utilization) using top, prstat, sar but we do not see spikes in cpu utilization as reported by this monitor based on kstat. Our goal is to understand kstat data.

I used man pages for kstat and learned syntax but it doesn't describe output data in any way. :frowning: Also I used my intuition to figure out what data I am looking at.

Actually we have more than 10 CPUs and yes the example is for CPU #10.

�Roughly, you read the numbers once. And then you wait. And then you read them again. Then you subtract the first numbers from the second to get an array of deltas.�

�You add the deltas up and you have total number of times that any of the counters for that cpu incremented during the wait period. Now you figure out how much of the total each piece is. That gives the percentages over the wait period.�

I am not sure what you mean here but I guess it is too late for me to get it. I will re-read it tomorrow morning. :slight_smile:

�You know, you could just run "sar 1 4" or something.� Yeah, sar is nice but not consistent with data we see on the third party monitor with a sampling rate of 15 seconds.

Maybe thsi will help... every so often (HZ times a second I believe), a routine runs. It will increment one of those 4 counters. If 33% of the time it incremented idle, you want to say the cpu was 33% idle. So if you read the counters, wait 1 second, and read them again, you have two sets of counters. By subtracting you get the deltas (or differences). The deltas tell you how many times each counter was incremented over the past second. Now you need to calculate the % that each delta is of the total delta.

Thnaks for directions!

/usr/src/cmd/sa/sadc.c
* load statistics, summing across CPUs where needed
.
.
.
static int all_stat_load(void)
.
.
* Accumulate cpu ticks for CPU_IDLE, CPU_USER, CPU_KERNEL and
* CPU_WAIT with respect to each of the cpus.
  for (j = 0; j < CPU_STATES; j++)
	cpu_tick[j] += tp[j];
.
.
.