Categories
SysOps

How to parse the fastest available dnf mirror data

Parse the fastest available dnf mirror data.

Inspect fastest available mirror data.

$ cat /var/cache/dnf/fastestmirror.cache
[:_librepo_:]
version=1

[https://centos-stream.koyanet.lv]
ts=1649548443
connectime=0.02913

[http://centos-stream.koyanet.lv]
ts=1649548443
connectime=0.030173000000000002

[https://mirror.im.jku.at]
ts=1649548443
connectime=0.087350999999999998

[http://mirror1.hs-esslingen.de]
ts=1649548443
connectime=0.087381

[https://mirror.alwyzon.net]
ts=1649548443
connectime=0.139458

[http://mirror.alwyzon.net]
ts=1649548443
connectime=0.13947899999999999

[https://mirror1.hs-esslingen.de]
ts=1649548443
connectime=0.19158

[https://mirror.lanet.network]
ts=1649548443
connectime=0.22782099999999994

[https://ftp.fi.muni.cz]
ts=1649548443
connectime=0.231931

[https://mirror.netzwerge.de]
ts=1649548443
connectime=0.23413699999999993

[http://mirror.karneval.cz]
ts=1649548443
connectime=0.24405499999999999

[https://ftp.nsc.ru]
ts=1649548443
connectime=0.246948

[http://linuxsoft.cern.ch]
ts=1649548443
connectime=0.27870200000000001

[https://linuxsoft.cern.ch]
ts=1649548443
connectime=0.28032400000000002

[http://ftp.plusline.net]
ts=1649548443
connectime=0.28035900000000002

[https://lon.mirror.rackspace.com]
ts=1649548443
connectime=0.28157300000000007

[http://mirror.lanet.network]
ts=1649548443
connectime=0.28164600000000006

[https://ftp.plusline.net]
ts=1649548443
connectime=0.28617499999999996

[https://centos-stream.ip-connect.info]
ts=1649548443
connectime=0.299149

[http://ftp.nsc.ru]
ts=1649548443
connectime=0.29925399999999996

[http://ftp.fi.muni.cz]
ts=1649548443
connectime=0.33033100000000004

[http://mirror.netzwerge.de]
ts=1649548443
connectime=0.33238500000000004

[http://humirror.lonyai.com]
ts=1649548443
connectime=0.33634399999999998

[http://lon.mirror.rackspace.com]
ts=1649548443
connectime=0.33637500000000009

[https://mirror.karneval.cz]
ts=1649548443
connectime=0.351433

[https://mirror.netsite.dk]
ts=1649548443
connectime=0.40093200000000001

[http://mirror.netsite.dk]
ts=1649548443
connectime=0.40328199999999997

[http://fr2.rpmfind.net]
ts=1649548443
connectime=0.44637100000000002

[https://centos-stream.mirror.wearetriple.com]
ts=1649548443
connectime=0.45562399999999997

[https://fr2.rpmfind.net]
ts=1649548443
connectime=0.49880199999999997

[http://mirror.im.jku.at]
ts=1649548443
connectime=0.50580000000000003

[http://semirror.lonyai.com]
ts=1649548443
connectime=0.50639299999999998

[http://centos-stream.ip-connect.info]
ts=1649548443
connectime=0.50662200000000002

[https://humirror.lonyai.com]
ts=1649548443
connectime=0.52758099999999997

[http://centos-stream.mirror.wearetriple.com]
ts=1649548443
connectime=0.55832000000000004

[https://mirror.in2p3.fr]
ts=1649548443
connectime=0.55834300000000003

[http://mirror.in2p3.fr]
ts=1649548443
connectime=0.55835599999999996

[https://semirror.lonyai.com]
ts=1649548443
connectime=0.61046900000000004

Parse fastest available mirror data and pretty-print the list.

$ awk 'BEGIN {
       RS="\n\n"                                   # record separator
       print "mirror,last checked,connection time" # table header
      } 
      NR > 1 {                                     # skip first record
        gsub(/[\[\]]/,"",$1);                      # remove "[]" characters from mirror definition
        split($2,ts,"=");                          # extract last checked value
        split($3,ct,"=");                          # extract connection time value
        t=strftime("%Y-%m-%d %H:%M:%S", ts[2]);    # get human-readable time
        printf "%s,%s,%.7s\n",$1,t,ct[2]           # print each row
      }' /var/cache/dnf/fastestmirror.cache | \
  column -t -s,
mirror                                        last checked         connection time
https://centos-stream.koyanet.lv              2022-04-09 23:54:03  0.02913
http://centos-stream.koyanet.lv               2022-04-09 23:54:03  0.03017
https://mirror.im.jku.at                      2022-04-09 23:54:03  0.08735
http://mirror1.hs-esslingen.de                2022-04-09 23:54:03  0.08738
https://mirror.alwyzon.net                    2022-04-09 23:54:03  0.13945
http://mirror.alwyzon.net                     2022-04-09 23:54:03  0.13947
https://mirror1.hs-esslingen.de               2022-04-09 23:54:03  0.19158
https://mirror.lanet.network                  2022-04-09 23:54:03  0.22782
https://ftp.fi.muni.cz                        2022-04-09 23:54:03  0.23193
https://mirror.netzwerge.de                   2022-04-09 23:54:03  0.23413
http://mirror.karneval.cz                     2022-04-09 23:54:03  0.24405
https://ftp.nsc.ru                            2022-04-09 23:54:03  0.24694
http://linuxsoft.cern.ch                      2022-04-09 23:54:03  0.27870
https://linuxsoft.cern.ch                     2022-04-09 23:54:03  0.28032
http://ftp.plusline.net                       2022-04-09 23:54:03  0.28035
https://lon.mirror.rackspace.com              2022-04-09 23:54:03  0.28157
http://mirror.lanet.network                   2022-04-09 23:54:03  0.28164
https://ftp.plusline.net                      2022-04-09 23:54:03  0.28617
https://centos-stream.ip-connect.info         2022-04-09 23:54:03  0.29914
http://ftp.nsc.ru                             2022-04-09 23:54:03  0.29925
http://ftp.fi.muni.cz                         2022-04-09 23:54:03  0.33033
http://mirror.netzwerge.de                    2022-04-09 23:54:03  0.33238
http://humirror.lonyai.com                    2022-04-09 23:54:03  0.33634
http://lon.mirror.rackspace.com               2022-04-09 23:54:03  0.33637
https://mirror.karneval.cz                    2022-04-09 23:54:03  0.35143
https://mirror.netsite.dk                     2022-04-09 23:54:03  0.40093
http://mirror.netsite.dk                      2022-04-09 23:54:03  0.40328
http://fr2.rpmfind.net                        2022-04-09 23:54:03  0.44637
https://centos-stream.mirror.wearetriple.com  2022-04-09 23:54:03  0.45562
https://fr2.rpmfind.net                       2022-04-09 23:54:03  0.49880
http://mirror.im.jku.at                       2022-04-09 23:54:03  0.50580
http://semirror.lonyai.com                    2022-04-09 23:54:03  0.50639
http://centos-stream.ip-connect.info          2022-04-09 23:54:03  0.50662
https://humirror.lonyai.com                   2022-04-09 23:54:03  0.52758
http://centos-stream.mirror.wearetriple.com   2022-04-09 23:54:03  0.55832
https://mirror.in2p3.fr                       2022-04-09 23:54:03  0.55834
http://mirror.in2p3.fr                        2022-04-09 23:54:03  0.55835
https://semirror.lonyai.com                   2022-04-09 23:54:03  0.61046

Parse fastest available mirror data and pretty-print the sorted list.

$ awk 'BEGIN {
       RS="\n\n"                                   # record separator
       print "mirror,last checked,connection time" # table header
      } 
      NR > 1 {                                     # skip first record
        gsub(/[\[\]]/,"",$1);                      # remove "[]" characters from mirror definition
        split($2,ts,"=");                          # extract last checked value
        split($3,ct,"=");                          # extract connection time value
        t=strftime("%Y-%m-%d %H:%M:%S", ts[2]);    # get human-readable time
        printf "%s,%s,%.7s\n",$1,t,ct[2]           # print each row
      }' /var/cache/dnf/fastestmirror.cache | \
  column -t -s, | (sed -u 1q; sort -k 3)
mirror                                        last checked         connection time
https://centos-stream.koyanet.lv              2022-04-09 23:54:03  0.02913
http://centos-stream.koyanet.lv               2022-04-09 23:54:03  0.03017
https://mirror.im.jku.at                      2022-04-09 23:54:03  0.08735
http://mirror1.hs-esslingen.de                2022-04-09 23:54:03  0.08738
https://mirror.alwyzon.net                    2022-04-09 23:54:03  0.13945
http://mirror.alwyzon.net                     2022-04-09 23:54:03  0.13947
https://mirror1.hs-esslingen.de               2022-04-09 23:54:03  0.19158
https://mirror.lanet.network                  2022-04-09 23:54:03  0.22782
https://ftp.fi.muni.cz                        2022-04-09 23:54:03  0.23193
https://mirror.netzwerge.de                   2022-04-09 23:54:03  0.23413
http://mirror.karneval.cz                     2022-04-09 23:54:03  0.24405
https://ftp.nsc.ru                            2022-04-09 23:54:03  0.24694
http://linuxsoft.cern.ch                      2022-04-09 23:54:03  0.27870
https://linuxsoft.cern.ch                     2022-04-09 23:54:03  0.28032
http://ftp.plusline.net                       2022-04-09 23:54:03  0.28035
https://lon.mirror.rackspace.com              2022-04-09 23:54:03  0.28157
http://mirror.lanet.network                   2022-04-09 23:54:03  0.28164
https://ftp.plusline.net                      2022-04-09 23:54:03  0.28617
https://centos-stream.ip-connect.info         2022-04-09 23:54:03  0.29914
http://ftp.nsc.ru                             2022-04-09 23:54:03  0.29925
http://ftp.fi.muni.cz                         2022-04-09 23:54:03  0.33033
http://mirror.netzwerge.de                    2022-04-09 23:54:03  0.33238
http://humirror.lonyai.com                    2022-04-09 23:54:03  0.33634
http://lon.mirror.rackspace.com               2022-04-09 23:54:03  0.33637
https://mirror.karneval.cz                    2022-04-09 23:54:03  0.35143
https://mirror.netsite.dk                     2022-04-09 23:54:03  0.40093
http://mirror.netsite.dk                      2022-04-09 23:54:03  0.40328
http://fr2.rpmfind.net                        2022-04-09 23:54:03  0.44637
https://centos-stream.mirror.wearetriple.com  2022-04-09 23:54:03  0.45562
https://fr2.rpmfind.net                       2022-04-09 23:54:03  0.49880
http://mirror.im.jku.at                       2022-04-09 23:54:03  0.50580
http://semirror.lonyai.com                    2022-04-09 23:54:03  0.50639
http://centos-stream.ip-connect.info          2022-04-09 23:54:03  0.50662
https://humirror.lonyai.com                   2022-04-09 23:54:03  0.52758
http://centos-stream.mirror.wearetriple.com   2022-04-09 23:54:03  0.55832
https://mirror.in2p3.fr                       2022-04-09 23:54:03  0.55834
http://mirror.in2p3.fr                        2022-04-09 23:54:03  0.55835
https://semirror.lonyai.com                   2022-04-09 23:54:03  0.61046

Parse fastest available mirror data and pretty-print the the top ten mirrors.

$ awk 'BEGIN {
       RS="\n\n"                                   # record separator
       print "mirror,last checked,connection time" # table header
      } 
      NR > 1 {                                     # skip first record
        gsub(/[\[\]]/,"",$1);                      # remove "[]" characters from mirror definition
        split($2,ts,"=");                          # extract last checked value
        split($3,ct,"=");                          # extract connection time value
        t=strftime("%Y-%m-%d %H:%M:%S", ts[2]);    # get human-readable time
        printf "%s,%s,%.7s\n",$1,t,ct[2]           # print each row
      }' /var/cache/dnf/fastestmirror.cache | \
  column -t -s, | (sed -u 1q; sort -k 3 | head)
mirror                                        last checked         connection time
https://centos-stream.koyanet.lv              2022-04-09 23:54:03  0.02913
http://centos-stream.koyanet.lv               2022-04-09 23:54:03  0.03017
https://mirror.im.jku.at                      2022-04-09 23:54:03  0.08735
http://mirror1.hs-esslingen.de                2022-04-09 23:54:03  0.08738
https://mirror.alwyzon.net                    2022-04-09 23:54:03  0.13945
http://mirror.alwyzon.net                     2022-04-09 23:54:03  0.13947
https://mirror1.hs-esslingen.de               2022-04-09 23:54:03  0.19158
https://mirror.lanet.network                  2022-04-09 23:54:03  0.22782
https://ftp.fi.muni.cz                        2022-04-09 23:54:03  0.23193
https://mirror.netzwerge.de                   2022-04-09 23:54:03  0.23413