12

I have a an InfluxDB measurement named kpi. I want to get the size of that single measurement in MB.

So far I have tried:

du -sh /var/lib/influxdb/data/demo/
27M     /var/lib/influxdb/data/demo/

But this command gives me the size of the whole database.

I have also tried this command:

> select count(counter) from kpi

name: kpi
time count
---- -----
0    1479533
>

But this only gives me the entries count.

How can I get the size of this particular measurement?

sebasth
  • 959
  • 10
  • 21
Shubham Bansal
  • 121
  • 1
  • 1
  • 4
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) or [Database Administrators Stack Exchange](http://dba.stackexchange.com/) would be a better place to ask. – jww Sep 21 '18 at 02:43
  • 2
    This question was [cross-posted](https://unix.stackexchange.com/questions/470445/how-to-get-measurement-size-in-influxdb) and closed in U&L. IMO this question qualifies "[*software tools commonly used by programmers; and a practical, answerable problem that is unique to software development*](http://stackoverflow.com/help/on-topic)" as table size information issue is IMHO more a software development detail, and is more on-topic here on SO. – sebasth Sep 22 '18 at 10:11

3 Answers3

9

I have a grafana board that shows me 'filestore' bytes from influx internal stats, like so:

SELECT sum("diskBytes") FROM "_internal".."tsm1_filestore" WHERE time >= now() - 6h GROUP BY time(30s), "database"

This is not the actual size on disk (compared with /var/lib/influxdb/data/), but could give you an indication which database is growing large.

Update:

This ensures to have the latest value of each database which is much more accurate.

SELECT SUM(diskBytes) FROM (
  SELECT max(diskBytes) AS "diskBytes" 
  FROM "influxdb_tsm1_filestore" 
  WHERE $timeFilter AND "database" != 'annotation'
  GROUP BY "database", "id"
)  GROUP BY time($__interval), "database"
DrPsychick
  • 384
  • 4
  • 7
3

In InfluxDB v1.x, you can use following command to find out the disk usage of database, measurement and even shards:

influx_inspect report-disk -detailed /var/lib/influxdb/data/

enter image description here

In InfluxDB v2.x, you could take advantage of the internal stats as following:

from(bucket: "yourBucket")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "storage_shard_disk_size")
    |> filter(fn: (r) => r["_field"] == "gauge")
    |> last()

It will show you the size of each database. enter image description here

Munin
  • 1,576
  • 2
  • 19
0

The issue here is a Measurement spans multiple shards in its lifetime which makes measuring the size of one rather non-trivial. May I ask why you're looking to do this? Perhaps merely knowing the number of series in this kpi measurement would suffice?

To do this, you would simply use the command: show series cardinality from kpi

Sam Dillard
  • 670
  • 1
  • 5
  • 18
  • 2
    I am transferring data from postgres db table to influx db , the data in the table is around 15 GB , so i want to know the size of the measurement that i am putting data into to compare and check feasibility of using influxdb – Shubham Bansal Sep 25 '18 at 10:01