From 209db7c86ce884685bfb69a15c29284524ac0f83 Mon Sep 17 00:00:00 2001 From: Daniel Magliola Date: Mon, 24 Feb 2020 15:03:01 -0300 Subject: [PATCH] Document how to clean up work dir for DirectFileStore on startup Add an example on how to solve the "files are already there on startup" problem, based on @stefansundin 's proposal in PR #173 Signed-off-by: Daniel Magliola --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 6bcbb698..fd17ce1a 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,19 @@ you store your metric files (specified when initializing the `DirectFileStore`) when your app starts. Otherwise, each app run will continue exporting the metrics from the previous run. +If you have this issue, one way to do this is to run code similar to this as part of you +initialization: + +```ruby +Dir["#{app_path}/tmp/prometheus/*.bin"].each do |file_path| + File.unlink(file_path) +end +``` + +If you are running in pre-fork servers (such as Unicorn or Puma with multiple processes), +make sure you do this **before** the server forks. Otherwise, each child process may delete +files created by other processes on *this* run, instead of deleting old files. + **Large numbers of files**: Because there is an individual file per metric and per process (which is done to optimize for observation performance), you may end up with a large number of files. We don't currently have a solution for this problem, but we're working on it.