Skip to content

Commit

Permalink
Script to flush Prometheus WAL data to block
Browse files Browse the repository at this point in the history
  • Loading branch information
jordap committed Aug 9, 2024
1 parent da9b628 commit 6f73883
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tools/prometheus-flush.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"flag"
"fmt"
"github.com/go-kit/log"
"github.com/prometheus/prometheus/tsdb"
"os"
)

func main() {
path := flag.String("path", "./data", "Path to Prometheus database")
flag.Parse()

sandbox := *path + "-sandbox"
output := *path + "-output"

if _, err := os.Stat(*path); err != nil {
fmt.Printf("Error: Unable to find database directory: %v\n", err)
return
}

logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
db, err := tsdb.OpenDBReadOnly(*path, sandbox, logger)
if err != nil {
fmt.Printf("Error: Unable to open Prometheus database: %v\n", err)
return
}

err = db.FlushWAL(output)
if err != nil {
fmt.Println("Error: Failed to flush WAL: %v\n", err)
return
}
}

0 comments on commit 6f73883

Please sign in to comment.