How can I pick up the advertised bandwidth of a Tor relay by looking at cached-microdesc-consensus file?
You can't directly since this information is not contained in the microdescriptor. The microdescriptors contain only the information needed for the client to build circuits, and the advertised bandwidth isn't needed for that. You will need to download the larger server descriptor if you want this information. Tor clients do not download this server descriptor by default, but I think this can be enabled with the FetchUselessDescriptors
option.
For example:
router privater 135.181.213.167 9000 0 0
identity-ed25519
-----BEGIN ED25519 CERT-----
AQQABw7PAYMbb9KFcgEg7Gsl/htuz0AgGtdlKgA7G6t93rWowDNKAQAgBAADCGVm
oBu2q31EVkGpNo8bYsDcJOKJJZGSv7bukEVkt3I0ZDuV07vWO0pgNVRlJwQQgCMn
OffN0dnwxcGUwGdfirXMLoRgQL7InFy2rl4qiMLudQvskpyEZohYBD/PJgU=
-----END ED25519 CERT-----
master-key-ed25519 AwhlZqAbtqt9RFZBqTaPG2LA3CTiiSWRkr+27pBFZLc
or-address [2a01:4f9:3a:2b96::2]:9000
platform Tor 0.4.7.10 on Linux
proto Cons=1-2 Desc=1-2 DirCache=2 FlowCtrl=1-2 HSDir=2 HSIntro=4-5 HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Padding=2 Relay=1-4
published 2022-09-20 09:42:36
fingerprint 57A2 9537 7F31 67AD 554B 521F 4615 1849 43C3 9CE1
uptime 2
bandwidth 31457280 1073741824 41959424
extra-info-digest 4BFE0FF549703B8D72D3199B398404B176D5633B WKIRVM/PrRj3aA8QpM67lwpIBxnfgKuYz+YHFpcZXws
[...]
https://github.com/torproject/torspec/blob/79da008392caed38736c73d839df7aa80628b645/dir-spec.txt#L534
"bandwidth" bandwidth-avg bandwidth-burst bandwidth-observed NL
[Exactly once]
Estimated bandwidth for this router, in bytes per second. The
"average" bandwidth is the volume per second that the OR is willing to
sustain over long periods; the "burst" bandwidth is the volume that
the OR is willing to sustain in very short intervals. The "observed"
value is an estimate of the capacity this relay can handle. The
relay remembers the max bandwidth sustained output over any ten
second period in the past 5 days, and another sustained input. The
"observed" value is the lesser of these two numbers.
Tor versions released before 2018 only kept bandwidth-observed for one
day. These versions are no longer supported or recommended.