@@ -380,6 +380,7 @@ const (
380380 epBuildinfo = apiPrefix + "/status/buildinfo"
381381 epRuntimeinfo = apiPrefix + "/status/runtimeinfo"
382382 epTSDB = apiPrefix + "/status/tsdb"
383+ epTSDBBlocks = apiPrefix + "/status/tsdb/blocks"
383384 epWalReplay = apiPrefix + "/status/walreplay"
384385 epFormatQuery = apiPrefix + "/format_query"
385386)
@@ -504,6 +505,8 @@ type API interface {
504505 Metadata (ctx context.Context , metric , limit string ) (map [string ][]Metadata , error )
505506 // TSDB returns the cardinality statistics.
506507 TSDB (ctx context.Context , opts ... Option ) (TSDBResult , error )
508+ // TSDBBlocks returns the list of currently loaded TSDB blocks and their metadata.
509+ TSDBBlocks (ctx context.Context ) (TSDBBlocksResult , error )
507510 // WalReplay returns the current replay status of the wal.
508511 WalReplay (ctx context.Context ) (WalReplayStatus , error )
509512 // FormatQuery formats a PromQL expression in a prettified way.
@@ -693,6 +696,40 @@ type TSDBHeadStats struct {
693696 MaxTime int `json:"maxTime"`
694697}
695698
699+ // TSDBBlocksResult contains the results from querying the tsdb blocks endpoint.
700+ type TSDBBlocksResult struct {
701+ Status string `json:"status"`
702+ Data TSDBBlocksData `json:"data"`
703+ }
704+
705+ // TSDBBlocksData contains the metadata for the tsdb blocks.
706+ type TSDBBlocksData struct {
707+ Blocks []TSDBBlocksBlockMetadata `json:"blocks"`
708+ }
709+
710+ // TSDBBlocksBlockMetadata contains the metadata for a single tsdb block.
711+ type TSDBBlocksBlockMetadata struct {
712+ Ulid string `json:"ulid"`
713+ MinTime int64 `json:"minTime"`
714+ MaxTime int64 `json:"maxTime"`
715+ Stats TSDBBlocksStats `json:"stats"`
716+ Compaction TSDBBlocksCompaction `json:"compaction"`
717+ Version int `json:"version"`
718+ }
719+
720+ // TSDBBlocksStats contains block stats for a single tsdb block.
721+ type TSDBBlocksStats struct {
722+ NumSamples int `json:"numSamples"`
723+ NumSeries int `json:"numSeries"`
724+ NumChunks int `json:"numChunks"`
725+ }
726+
727+ // TSDBBlocksCompaction contains block compaction details for a single block.
728+ type TSDBBlocksCompaction struct {
729+ Level int `json:"level"`
730+ Sources []string `json:"sources"`
731+ }
732+
696733// WalReplayStatus represents the wal replay status.
697734type WalReplayStatus struct {
698735 Min int `json:"min"`
@@ -1350,6 +1387,24 @@ func (h *httpAPI) TSDB(ctx context.Context, opts ...Option) (TSDBResult, error)
13501387 return res , err
13511388}
13521389
1390+ func (h * httpAPI ) TSDBBlocks (ctx context.Context ) (TSDBBlocksResult , error ) {
1391+ u := h .client .URL (epTSDBBlocks , nil )
1392+
1393+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
1394+ if err != nil {
1395+ return TSDBBlocksResult {}, err
1396+ }
1397+
1398+ _ , body , _ , err := h .client .Do (ctx , req )
1399+ if err != nil {
1400+ return TSDBBlocksResult {}, err
1401+ }
1402+
1403+ var res TSDBBlocksResult
1404+ err = json .Unmarshal (body , & res )
1405+ return res , err
1406+ }
1407+
13531408func (h * httpAPI ) WalReplay (ctx context.Context ) (WalReplayStatus , error ) {
13541409 u := h .client .URL (epWalReplay , nil )
13551410
0 commit comments