0

from sar command on saX file we can get the disks utilization as the follwing

sar -d -f /var/log/sa/sa18  | grep Average
Average:       dev8-0      1.24      0.00    150.06    121.40      0.04     30.40      4.72      0.58
Average:     dev253-0      0.32      0.00      3.75     11.83      0.01     17.95      3.48      0.11
Average:     dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:     dev253-2      1.12      0.00    146.31    130.68      0.04     31.79      4.46      0.50
Average:      dev8-16      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:      dev8-32      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:      dev8-48      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:     dev253-3      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

we can see that disks defined as MAJ:MIN as ( dev8-16 , dev8-48 , etc )

is it possible to get the real disks name as sdb , sdc sdc , etc ? using the sar cli ( sar -d -f /var/log/sa/sa18 | grep Average )

yael
  • 13,106

2 Answers2

2

The documentation man sar tells you how to get name lookups for sar -d:

-d Report activity for each block device. When data are displayed, the device name is displayed as it (should) appear in /dev. sar uses data in /sys to determine the device name based on its major and minor numbers. If this name resolution fails, sar will use name mapping controlled by /etc/sysstat/sysstat.ioconf file. Persistent device names can also be printed if option -j is used […]

In summary,

  1. It should already happen
  2. If it doesn't you can add them to /etc/sysstat/sysstat.ioconf
  3. You might prefer to use one of the -j {option} options such as LABEL.

I've recently enabled system accounting on a Pi that I have here. Obviously the statistics run is not significant but I can already see that on this machine the disk names are correctly displayed:

sar -d -f /var/log/sysstat/sa18
Linux 4.9.35-v7+ (pi)   18/01/23        _armv7l_        (4 CPU)

12:16:05 LINUX RESTART (4 CPU)

12:40:01 DEV tps rkB/s wkB/s dkB/s areq-sz aqu-sz await %util 12:42:08 mmcblk0 3.37 14.35 19.58 0.00 10.06 0.08 23.15 0.58 12:42:08 dm-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Average: mmcblk0 3.37 14.35 19.58 0.00 10.06 0.08 23.15 0.58 Average: dm-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

I wonder if you have copied the sa* files to a different server for analysis, perhaps? In which case you may indeed need to edit sysstat.ioconf to name them.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
1

Try this:

#! /bin/bash

devrez() { l=/sys/dev/block/echo "$1" | sed 's/dev//g;s/-/:/g' test ! -L "$l" && echo "[$1] not found" && return -1 readlink -f "$l" | awk -F / '{ORS="";print "\t"$NF}' }

export -f devrez

sar -d -f /var/log/sa/sa18 | awk '{OFS="\t";ORS="";print $1; system("/bin/bash -c '''devrez "$2"'''");$1="";$2="";print "";print;print "\n"}'

  • since we are using python script, do you think its possible to do the same in pytyon instead of what you wrote in bash ? – yael Jan 18 '23 at 16:44
  • 1
    Sorry, my python fu is missing :-) This should be easier to do in python actually. – Artem S. Tashkinov Jan 18 '23 at 16:55
  • ok np , I will try it in python but I am stuck to do something similar to export -f devrez – yael Jan 18 '23 at 17:02
  • 1
    You don't need to use this function in python, it has a os.readlink() method. Instead of AWK, you use split(). It must be easy. My script uses sed to dev253-0 -> 253:0, this could be done with .replace(). – Artem S. Tashkinov Jan 18 '23 at 17:07