From 95a76a7e5b9ced920879ff35028a64ac7c55e753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jord=C3=A0=20Polo?= Date: Fri, 9 Aug 2024 14:37:49 -0700 Subject: [PATCH] Script to flush Prometheus WAL data to block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jordà Polo --- tools/prometheus-flush.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tools/prometheus-flush.go diff --git a/tools/prometheus-flush.go b/tools/prometheus-flush.go new file mode 100644 index 00000000..68ab1e9c --- /dev/null +++ b/tools/prometheus-flush.go @@ -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 + } +}