about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-10-09 19:35:14 +0200
committerGitHub <noreply@github.com>2018-10-09 19:35:14 +0200
commit7f9dd92a27e937e3cbc42c1e3c8b844c3583c92b (patch)
tree56d6d6372e912280b72093fe7424cb5e99564df1
parentd4b7d7596806b73b29f08143734257e04fee82c0 (diff)
Track historical space stats in PgHero to determine PostgreSQL growth (#8906)
-rw-r--r--app/workers/scheduler/pghero_scheduler.rb11
-rw-r--r--config/sidekiq.yml3
-rw-r--r--db/migrate/20181007025445_create_pghero_space_stats.rb13
-rw-r--r--db/schema.rb11
4 files changed, 37 insertions, 1 deletions
diff --git a/app/workers/scheduler/pghero_scheduler.rb b/app/workers/scheduler/pghero_scheduler.rb
new file mode 100644
index 000000000..4453bf2cd
--- /dev/null
+++ b/app/workers/scheduler/pghero_scheduler.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Scheduler::PgheroScheduler
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed, retry: 0
+
+  def perform
+    PgHero.capture_space_stats
+  end
+end
diff --git a/config/sidekiq.yml b/config/sidekiq.yml
index 6a09bb6e9..c44af5b6c 100644
--- a/config/sidekiq.yml
+++ b/config/sidekiq.yml
@@ -33,3 +33,6 @@
   backup_cleanup_scheduler:
     cron: '<%= Random.rand(0..59) %> <%= Random.rand(3..5) %> * * *'
     class: Scheduler::BackupCleanupScheduler
+  pghero_scheduler:
+    cron: '0 0 * * *'
+    class: Scheduler::PgheroScheduler
diff --git a/db/migrate/20181007025445_create_pghero_space_stats.rb b/db/migrate/20181007025445_create_pghero_space_stats.rb
new file mode 100644
index 000000000..6198a6f84
--- /dev/null
+++ b/db/migrate/20181007025445_create_pghero_space_stats.rb
@@ -0,0 +1,13 @@
+class CreatePgheroSpaceStats < ActiveRecord::Migration[5.2]
+  def change
+    create_table :pghero_space_stats do |t|
+      t.text :database
+      t.text :schema
+      t.text :relation
+      t.integer :size, limit: 8
+      t.timestamp :captured_at
+    end
+
+    add_index :pghero_space_stats, [:database, :captured_at]
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1458bd70f..bf6ab4e68 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2018_09_29_222014) do
+ActiveRecord::Schema.define(version: 2018_10_07_025445) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -372,6 +372,15 @@ ActiveRecord::Schema.define(version: 2018_09_29_222014) do
     t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true
   end
 
+  create_table "pghero_space_stats", force: :cascade do |t|
+    t.text "database"
+    t.text "schema"
+    t.text "relation"
+    t.bigint "size"
+    t.datetime "captured_at"
+    t.index ["database", "captured_at"], name: "index_pghero_space_stats_on_database_and_captured_at"
+  end
+
   create_table "preview_cards", force: :cascade do |t|
     t.string "url", default: "", null: false
     t.string "title", default: "", null: false