git ssb

0+

dangerousbeans / scuttle_god



Commit 463242ac532f246d79720b819e6d3ed4aac5e22e

Inital commit

Joran committed on 4/13/2017, 10:36:03 PM

Files changed

Readme.mdadded
sbot.godadded
sbot_notifier.rbadded
Readme.mdView
@@ -1,0 +1,30 @@
1 +Scuttle God
2 +================
3 +
4 +A god process monitor setup for the Secure Scuttlebutt Server (pub)
5 +
6 +### Things
7 +
8 +- **Notifications:** webhook, email, twitter etc
9 +- CPU and memory **boundaries**
10 +- **Lifecycle management** with restarts, cool off periods and 'flapping' detection
11 +
12 +
13 +### Install
14 +
15 + git clone ssb://%p2XzNsMYEWAVdZg0uIHJMp7JWoZe1ezcAc4IaeSYe08=.sha256 scuttle_god
16 + cd scuttle_god
17 + gem install god
18 +
19 +### Setup
20 +
21 + # Setup accounts etc
22 + vim sbot.god
23 +
24 +### Run
25 +
26 + # detached
27 + god -c sbot.god
28 +
29 + # attached
30 + god -c sbot.god -D
sbot.godView
@@ -1,0 +1,56 @@
1 +require './sbot_notifier.rb'
2 +
3 +# Webhook to send notification events
4 +God.contact(:webhook) do |c|
5 + c.name = 'god'
6 + c.group = 'chatroom'
7 + c.url = "http://donkey.project-entropy.com:3000/"
8 + c.format = :json
9 +end
10 +
11 +# SSB notifier to send events
12 +God.contact(:sbot_notifier) do |c|
13 + c.name = 'god'
14 + c.group = 'chatroom'
15 + c.channel = "#test"
16 +end
17 +
18 +God.watch do |w|
19 + w.name = "Secure Scuttlebutt Server"
20 + w.start = "sbot server"
21 + w.keepalive
22 +
23 + # restart if memory or cpu is too high
24 + w.transition(:up, :restart) do |on|
25 + on.condition(:memory_usage) do |c|
26 + c.interval = 20
27 + c.above = 900.megabytes
28 + c.times = [3, 5]
29 + end
30 +
31 + on.condition(:cpu_usage) do |c|
32 + c.interval = 10
33 + c.above = 98.percent
34 + c.times = [3, 5]
35 + end
36 + end
37 +
38 + # Handle the process lifecycle
39 + w.lifecycle do |on|
40 +
41 + # If this watch is started or restarted five times withing 5 minutes, then unmonitor it
42 + # then after ten minutes, monitor it again to see if it was just a temporary problem;
43 + # if the process is seen to be flapping five times within two hours, then give up completely.
44 + on.condition(:flapping) do |c|
45 + c.to_state = [:start, :restart]
46 + c.times = 5
47 + c.within = 5.minute
48 + c.transition = :unmonitored
49 + c.retry_in = 10.minutes
50 + c.retry_times = 5
51 + c.retry_within = 2.hours
52 +
53 + c.notify = {:contacts => ['chatroom'], :priority => 1, :category => 'flapping'}
54 + end
55 + end
56 +end
sbot_notifier.rbView
@@ -1,0 +1,40 @@
1 +# Send a notice to ssb as current user.
2 +#
3 +
4 +module God
5 + module Contacts
6 +
7 + class SbotNotifier < Contact
8 +
9 + class << self
10 + attr_accessor :channel
11 + end
12 +
13 + def valid?
14 + valid = true
15 + valid &= complain("Attribute 'channel' must be specified", self) unless arg(:channel)
16 + valid
17 + end
18 +
19 + attr_accessor :url, :format
20 +
21 + def notify(message, time, priority, category, host)
22 + data = {
23 + :message => message,
24 + :time => time,
25 + :priority => priority,
26 + :category => category,
27 + :host => host
28 + }
29 +
30 + `sbot publish --type post --text "#{message}" --channel #{arg(:channel)}`
31 +
32 + rescue Object => e
33 + applog(nil, :info, "failed to send sbot: #{e.message}")
34 + applog(nil, :debug, e.backtrace.join("\n"))
35 + end
36 +
37 + end
38 +
39 + end
40 +end

Built with git-ssb-web