-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collect uptime data in daily heartbeat from connect-ng
- Loading branch information
Showing
16 changed files
with
319 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class SystemUptime < ApplicationRecord | ||
belongs_to :system | ||
|
||
validates :system_id, presence: true | ||
validates :online_at_day, presence: true | ||
validates :online_at_hours, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CreateSystemUptimes < ActiveRecord::Migration[6.1] | ||
def change | ||
safety_assured do | ||
create_table :system_uptimes, id: :serial, force: :cascade do |t| | ||
t.bigint :system_id, null: false | ||
t.date :online_at_day, null: false | ||
t.column :online_at_hours, 'binary(24)', null: false | ||
t.timestamps | ||
end | ||
|
||
commit_db_transaction | ||
|
||
add_index :system_uptimes, %i[system_id online_at_day], unique: true, name: 'id_online_day' | ||
|
||
add_foreign_key :system_uptimes, :systems, column: :system_id, validate: false | ||
end | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace :db do | ||
namespace :maintenance do | ||
desc 'Delete all uptime tracking data which are older than 90 days' | ||
task cleanup_uptime_tracking: :environment do | ||
SystemUptime.where("online_at_day < '#{2.days.ago}'").delete_all | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=RMT uptime cleanup service | ||
Requires=mysql.service | ||
Wants=rmt-uptime-cleanup.timer | ||
|
||
[Service] | ||
Type=oneshot | ||
WorkingDirectory=/usr/share/rmt/bin | ||
ExecStart=bundle exec rake db:maintenance:cleanup_uptime_tracking RAILS_ENV=production | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=RMT Uptime Data cleanup timer | ||
|
||
[Timer] | ||
# Run this timer every day at a randomized 24h delay. | ||
OnCalendar=daily | ||
RandomizedDelaySec=24h | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :system_uptime do | ||
association :system | ||
sequence(:online_at_day) { Time.zone.now } | ||
online_at_hours { '111111111111111111111111' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe SystemUptime, type: :model do | ||
it { is_expected.to validate_presence_of(:system_id) } | ||
it { is_expected.to validate_presence_of(:online_at_day) } | ||
it { is_expected.to validate_presence_of(:online_at_hours) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters