how to cli grep local-lvm usage but use less cpu resource?

kevinshane

Member
Jun 11, 2021
5
0
6
40
Hey guys, I am writing a script to grep my local-lvm usage then output to a json file.

I am currently use "pvesm status" method:
Bash:
time pvesm status | grep "local-lvm"

local-lvm     lvmthin     active       158994432       119532013        39462418   75.18%
real    0m0.526s
user    0m0.311s
sys     0m0.029s

But, as you can see that, the `pvesm` command is a bit intensive, and also takes more time (0.5 second is a lot).
I am calling this pvesm command for every few seconds, causing cpu fan much louder, which is not good.

I would like to know if there is any other solution(or command) to get a "lvm basic usage" using bash, without taking too much time to grep a result?

Thanks guys~
 
Last edited:
Just a thought: since Proxmox always monitors storages, can't you get the information from the rdd data (which is the basis for the graph in the web GUI)? I have no experience with this, sorry.

EDIT: I don't know how to access the rdd data. It was just an idea, as it already contains the data you want.
 
Last edited:
Just a thought: since Proxmox always monitors storages, can't you get the information from the rdd data (which is the basis for the graph in the web GUI)? I have no experience with this, sorry.
Thanks man, how can I access the rdd data? thro api or ssh? Can't find any info.

edit1: OK I search the forum and see the pvesh command, let me try that one. Thanks for the rdd info :)
edit2: nope it still takes too much processing time for calling pvesh command
time pvesh get /nodes/58u/disks/lvmthin real 0m0.568s user 0m0.454s sys 0m0.051s
 
Last edited:
You can query the database with rrdtool: https://stackoverflow.com/questions/14494114/how-to-read-rrd-file-to-get-usage-data
The database is located here: ./lib/rrdcached

pvesm status - actually goes out and queries each storage in real time. In addition, it has to spin up language interpreter and other system stuff.
pvesm still has to spin up language interpreter "/usr/bin/pvesh: Perl script text executable"

Nothing beats direct API access:
Code:
time curl --insecure  --cookie "$(<cookie)" --header "$(<csrftoken)" -X GET https://127.0.0.1:8006/api2/json/nodes/pve7demo1/disks/lvmthin
{"data":[{"metadata_used":900936,"lv_type":"t","metadata_size":8388608,"lv":"data","vg":"pve","ctime":"1645838725","lv_size":7516192768,"lv_state":"a","used":0}]}
real    0m0.074s
user    0m0.013s
sys     0m0.000s


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Nothing beats direct API access
Thanks man, that's awesome, did some test and it's working like a charm, and fast, really fast!
However, setting the cookie and csrf those stuffs are just a little bit tedious.. have to run on every node..

I also found a command "lvs" will also doing really fast, it also reports the data and meta in %, which is exactly the same as gui summary shows. This is what the gui shows: 80.46% (131.00 GB of 162.81 GB)

here is the cli output:
Code:
LV                        VG  Attr       LSize    Pool Origin                   Data%  Meta%  Move Log Cpy%Sync Convert
  data                      pve twi-aotz-- <151.63g                               80.46  4.13

As you can see that the number of percents is 80.46% matched exactly as gui's.
But I have no idea how proxmox gui summary caculate the GiB of total local-lvm size. I've done some manual caculation but it won't match the gui one. Do you have any idea?

What I trying to achive is figure it out how pve calculate the actual GiB number, then a simple shell script will get this info really quick(with lvs grep the data usage %), without setting those API stuffs of cause.

Thanks
 
However, setting the cookie and csrf those stuffs are just a little bit tedious.. have to run on every node..
not sure why you would need that, the API provides single point of management.
But I have no idea how proxmox gui summary caculate the GiB of total local-lvm size. I've done some manual caculation but it won't match the gui one. Do you have any idea?
you can always examine source code to see what the storage specific plugin is doing, ie:
grep "^sub " /usr/share/perl5/PVE/Storage/LVMPlugin.pm
grep -E "^sub " /usr/share/perl5/PVE/Storage/LVMPlugin.pm| grep -E "info|status"
sub lvm_pv_info {
sub status {
sub volume_size_info {


The LVM suite consists of more than "lvs". There are things like [pv|vg|lv]s and [pv|vg|lv]display, etc.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!