Collect ipfs metrics

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 ""/"" ? 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).
1 Like

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:

  1. Files added with ipfs add and ipfs pin add won’ show up here unless you “copy” (ipfs files cp) them into this directory.
  2. 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.

1 Like

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.).