Query selecting only 'distinct on' rows

collectd
grafana
influxdb
#1

How should I modify this query so it only reports the last/newest samples of an instance. In the current query some instances are listed twice.

SELECT * FROM “ceph_value” WHERE “type” = ‘ceph_bytes’ AND “type_instance” = ‘Osd.numpg’ AND “value” > 0 AND time > now() - 30s ORDER BY time DESC LIMIT 40

time                           host instance type       type_instance value
----                           ---- -------- ----       ------------- -----
2018-01-10T09:38:27.524637642Z c03  osd.5    ceph_bytes Osd.numpg     155
2018-01-10T09:38:27.518771543Z c03  osd.2    ceph_bytes Osd.numpg     52
2018-01-10T09:38:24.625571475Z c01  osd.0    ceph_bytes Osd.numpg     129
2018-01-10T09:38:24.621389891Z c01  osd.3    ceph_bytes Osd.numpg     51
2018-01-10T09:38:24.215214993Z c02  osd.4    ceph_bytes Osd.numpg     142
2018-01-10T09:38:24.210770483Z c02  osd.1    ceph_bytes Osd.numpg     44
2018-01-10T09:38:17.522840089Z c03  osd.5    ceph_bytes Osd.numpg     155
2018-01-10T09:38:17.517757301Z c03  osd.2    ceph_bytes Osd.numpg     52
2018-01-10T09:38:14.634087585Z c01  osd.7    ceph_bytes Osd.numpg     56
2018-01-10T09:38:14.625388215Z c01  osd.0    ceph_bytes Osd.numpg     129
2018-01-10T09:38:14.621325111Z c01  osd.3    ceph_bytes Osd.numpg     51
2018-01-10T09:38:14.215173666Z c02  osd.4    ceph_bytes Osd.numpg     142
2018-01-10T09:38:14.210634992Z c02  osd.1    ceph_bytes Osd.numpg     44
2018-01-10T09:38:07.523106781Z c03  osd.5    ceph_bytes Osd.numpg     155
2018-01-10T09:38:07.517833556Z c03  osd.2    ceph_bytes Osd.numpg     52