I want to generate a file which has cpu usage
logs in 24 hour format (from 00:00:00
to 23:59:59
). I am using sar
command but it gives time in AM or PM format which is not required.
Sample:
12:01:01 AM all 1.33 0.00 1.06 0.24 0.00 97.37
12:02:01 AM all 1.30 0.00 1.02 0.04 0.00 97.64
Expected result:
00:01:01 all 1.33 0.00 1.06 0.24 0.00 97.37
00:02:01 all 1.30 0.00 1.02 0.04 0.00 97.64
These parameters must be written in HH:MM:SS format, or sar will ignore them with an error. The -r argument is used to display memory usage data. 3. sar historic data is stored in /var/log/sa directory in case of RedHat based distributions.
sar: System Activity Report. It can be used to monitor Linux system's resources like CPU usage, Memory utilization, I/O devices consumption, Network monitoring, Disk usage, process and thread allocation, battery performance, Plug and play devices, Processor performance, file system and more.
Use the sar -r command to report the number of memory pages and swap-file disk blocks that are currently unused. Output from the -r option is described in the table below. The average number of memory pages available to user processes over the intervals sampled by the command. Page size is machine-dependent.
Description. The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters, writes information the specified number of times spaced at the specified intervals in seconds.
The sar
program is a so-called locale aware program. Meaning it's output format is controlled by the LC_*
environment variables. The variable LC_TIME
is responsible for the output of time data. (see man locale
).
Looks like you are using a system where LC_TIME
is set to en_US
- a locale using the 12hours AM/PM format
(or LC_TIME
was kept empty which will lead to using the default locale). You need to use a locale setting which is using the 24 hour format. Lets say en_UK
. You can specify it on the command line:
LC_TIME=en_UK.utf8 sar
Output:
Linux 3.13.0-44-generic (desktop1) 01/22/15 _x86_64_ (4 CPU)
00:00:01 CPU %user %nice %system %iowait %steal %idle
00:02:01 all 2,26 0,00 0,41 0,71 0,00 96,63
00:04:01 all 2,68 0,00 0,72 0,46 0,00 96,13
...
Note! If the locale en_UK.uft8
isn't available on your system, you need to generate it using:
sudo locale-gen en_UK.utf8
or you can use POSIX
or C
:
LC_TIME='POSIX' sar
LC_TIME='C' sar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With