Hi, I am writing an ipfs metrics exporter in go using go-ipfs, If I need the total size of files that exists in ipfs private network having some limited connected peers, do I need CumulativeSize
in curl -X POST "http://127.0.0.1:5001/api/v0/files/stat?arg="/""
? Also, how to get the total blocks using this API? @stebalien could you please help me?
Thereâs no way to get the size of all files in a private network. There isnât even a reliable way to get all files in a private network.
The best you can do is get the size of your local datastore:
curl -X POST 'localhost:5001/api/v0/repo/stat?size-only=true'
- RepoSize: total data (in bytes)
- NumObjects: total blocks. Note: this will be 0 unless you remove
size-only
. However, that will also make the command much slower (it needs to count all objects).
Thank you for your reply.
If we look at the ipfs dashboard, there is data of files
455 KB (PFA). I was looking to get this data.
Ah, thatâs the size of the files in âmfsâ (ipfs files
). This includes all files listed by ipfs files ls /
. However, thatâs not necessarily all of your files:
- Files added with
ipfs add
andipfs pin add
wonâ show up here unless you âcopyâ (ipfs files cp
) them into this directory. - Files you have cached because you downloaded them wonât show up in this directory either.
The webui and IPFS desktop simplify this situation a bit by automatically copying files into this system for a better user experience.
But to answer your question the command youâre looking for is ipfs files stat --size /
(or `curl -X POST âhttp://localhost:5001/api/v0/files/stat?size=true&arg=/â). Look at the CumulativeSize field.
However, note: Itâs possible to âcopyâ files with ipfs files cp
into this special directory without actually downloading them. Theyâll be downloaded lazily as you access them. If you want the size of the local data, youâll have to pass the --with-local
flag which walks the data you have locally and reports the total size.
Thatâs a really useful description. Then same logic for blocks 2k
? Because my local node didnât have these much blocks and curl -X POST 'localhost:5001/api/v0/repo/stat?size-only=true'
returns some different count.
Whatâs âblocks 2kâ? That command will return the total number of âblocksâ (file pieces, directory pieces, etc.).