Ticket #228 (closed defect: fixed)

Opened 6 years ago

Last modified 7 months ago

cpu plugin shows wrong values

Reported by: dz@426.ch Assigned to: janl
Priority: normal Milestone: Munin 1.4
Component: plugins Version: 1.2.4
Severity: minor Keywords:
Cc:

Description

The cpu plugin depends on the correct clock tick (HZ) to calculate the correct percentage values. Unfortunatly the HZ differs from kernel to kernel. I have introduced a HZ configuration variable:

--- cpu.orig    2006-05-09 14:25:54.000000000 +0200
+++ cpu 2006-05-12 08:21:46.000000000 +0200
@@ -9,6 +9,16 @@
 #      config   (required)
 #      autoconf (optional - used by munin-config)
 #
+# Environment variables:
+#
+#      hz      Number of clock ticks per second (default 1000).
+#              Older linux kernels have 100 instead. Find out the correct
+#              value in /usr/src/linux/include/asm/param.h or execute
+#              (cat /proc/interrupts;sleep 1;cat /proc/interrupts)|grep timer,
+#              subtract the first big numbers and decide if they are
+#              closer to 100 or 1000.
+#
+#
 # $Log$
 # Revision 1.8  2004/12/09 22:12:56  jimmyo
 # Added "graph_period" option, to make "graph_sums" usable.
@@ -49,6 +59,7 @@
 #%# capabilities=autoconf


+hz=${hz:-1000}

 if [ "$1" = "autoconf" ]; then
        if [ -r /proc/stat ]; then
@@ -152,7 +163,7 @@

 if [ ! -z "$extinfo" ]
 then
-       awk '/^cpu / { print "user.value " $2 "\nnice.value " $3 "\nsystem.value " $4 "\nidle.value " $5 "\niowait.value " $6 "\nirq.value " $7 "\nsoftirq.value " $8 }' < /proc/stat
+       awk -v hz=$hz '/^cpu / { print "user.value " $2*100/hz "\nnice.value " $3*100/hz "\nsystem.value " $4*100/hz "\nidle.value " $5*100/hz "\niowait.value " $6*100/hz "\nirq.value " $7*100/hz "\nsoftirq.value " $8*100/hz }' < /proc/stat
 else
-       awk '/^cpu / { print "user.value " $2 "\nnice.value " $3 "\nsystem.value " $4 "\nidle.value " $5 }' < /proc/stat
+       awk -v hz=$hz '/^cpu / { print "user.value " int($2*100/hz) "\nnice.value " int($3*100/hz) "\nsystem.value " int($4*100/hz) "\nidle.value " int($5*100/hz) }' < /proc/stat
 fi

Notes:

  • This patch relates to Ticket 120
  • The "if [ ! -z "$extinfo" ]" branch is not tested due to lack of a 2.6 kernel

Change History

14/06/06 20:41:02 changed by janl

  • owner changed from jo to anonymous.
  • priority changed from high to normal.
  • status changed from new to assigned.
  • severity changed from normal to minor.

I cannot see why this should be needed. The plugin works correcyly on 2.6 kernels with 1000 Hz. Can you please provide more information?

Nicolai

14/06/06 20:41:28 changed by janl

  • owner changed from anonymous to janl.
  • status changed from assigned to new.

22/06/06 21:23:48 changed by janl

  • status changed from new to assigned.

No i386 or x86_64 I have access to (all running 2.6 and using HZ=1000) display this problem but I've finaly gotten my head around the mechanism. Patch in 1034.

28/06/06 12:01:17 changed by janl

The fix gives:

> fetch cpu
> user.value 3.59307e+09
> nice.value 508709
> system.value 508899567
> idle.value 1467626129

Use printf:

awk -v hz=$HZ '/^cpu / { printf "user.value %.0f\nnice.value %.0f\nsystem.value %.0f\nidle.value %.0f ", $2*100/hz, $3*100/hz, $4*100/hz, $5*100/hz }' < /proc/stat

07/07/06 18:07:04 changed by dz@426.ch

Typo (by me not janl ;) )

Omit the space after "idle.value %.0f".

Correct is:

awk -v hz=$HZ '/^cpu / { printf "user.value %.0f\nnice.value %.0f\nsystem.value %.0f\nidle.value %.0f", $2*100/hz, $3*100/hz, $4*100/hz, $5*100/hz }' < /proc/stat

25/08/06 00:37:57 changed by janl

  • status changed from assigned to closed.
  • resolution set to fixed.

Alright, think I got it all now. Revision 1048.

27/10/11 11:45:43 changed by puncvirecberg1973

Anyone who loves movies is likely to love movie downloads, too. The very fact is this pattern is changing into a big one and it is nice for many who want to create giant collections with out having to dole out high greenback or premium house space to do so. How to download from vimeo are actually obtainable legally from all kinds of massive movie studios and even tv networks, as well. A video collection created digitally has a number of benefits over regular disk purchases, too. The most important perks of video downloads contain the storage points and pricing. But, why? Video downloads are typically a number of dollars or extra less than a regular DVD buy as a result of there is no such thing as a packaging points to contend with. Plus, there's the easy reality delivery is not an issue either. Since the companies that promote downloads save on delivery and the film studios save on packaging, they can pass on a few of these savings on to buyers. In regard to storage, it is a easy fact of space. It's an entire lot simpler to retailer motion pictures on a computer drive or a backup drive than it is to hold a hundred videos in a room. There's no want for shelf after shelf or tons of DVD towers when a group is created through video download. Administration of films and tv downloads can be a whole lot easier, too. It's pretty simple to create folders on the pc to store motion pictures by genre and it is a complete lot faster, too. Video downloads are becoming the favorites of many for a cause beyond storage or pricing. This reason is variety. The very fact is the kinds of downloads available will be literally thoughts boggling. Let's look at what kinds of video downloads could be found legally: Hit motion pictures Nearly each new movie that hits the theaters will end up in a legal obtain format shortly after release. This means there is not any have to run to the video retailer, or worse, pay top greenback at a theater to see a new release. Tv programs Vimeo tube downloads Because the movie studios jump on the bandwagon, so too are the tv studios. Hit exhibits from all many years might be found by the season or by the episode by way of video download.Classics Because the movie obtain business turns into more popular, many studios are video through their catalogues and providing downloads of their older movies. From the classics of the Twenties to vacation favorites of the Eighties, they will all be discovered via video download. And, if a title cannot be discovered right now, it's doubtless it will be added soon as every major film studio falls into place providing downloads through a number of different sites. Video downloads provide their users with an on demand aspect, price savings and storage concern reduction that common DVD buys cannot. As this new format becomes increasingly accepted, it's changing into the method of choice for buying and watching movies. Original works There are tons of areas to get video downloads from newbie or little recognized creators. These videos might not have the financial backing of a few of the major motion pictures in history, however that doesn't mean there isn't some good entertainment out there. Indie works are getting an entire new viewers due to video downloads and the Internet.