cronitor 5.2.1 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -0
- data/README.md +3 -1
- data/lib/cronitor/config.rb +2 -2
- data/lib/cronitor/monitor.rb +36 -8
- data/lib/cronitor/version.rb +1 -1
- data/lib/cronitor.rb +12 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d786e1bcc6b048371b5a9ef9e2c9d4d0db9a7e8d65f30cfd1029cbd3409f9e0e
|
4
|
+
data.tar.gz: df00a0cfe1cd458146b892b145b2919caf51f384dbe4c89348a6f03b3afa4a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaf140a231580c70c6653795e4530f792384602e9c1c5ee6da3cc4da4de2f55fa73d4bdb920af72448be5dcce75963a68f2b3e660593334f64482d05198a8d18
|
7
|
+
data.tar.gz: 4b530de67e7d3f2fbb86fece1a9cdae10a01456d6707a9c4d92f76a09004bc0c9a1a907c665fb6e62006a13b3e5394f41b44946e6cc853754330fdb16a4500b3
|
data/.github/workflows/test.yml
CHANGED
data/README.md
CHANGED
@@ -62,7 +62,7 @@ monitor.ping(state: 'complete', metrics: {count: 1000, error_count: 17})
|
|
62
62
|
|
63
63
|
## Configuring Monitors
|
64
64
|
|
65
|
-
###
|
65
|
+
### YAML Configuration File
|
66
66
|
|
67
67
|
You can configure all of your monitors using a single YAML file. This can be version controlled and synced to Cronitor as part of
|
68
68
|
a deployment or build process. For details on all of the attributes that can be set, see the [Monitor API](https://cronitor.io/docs/monitor-api) documentation.
|
@@ -128,6 +128,8 @@ heartbeats:
|
|
128
128
|
events: true # send alert when the event occurs
|
129
129
|
|
130
130
|
```
|
131
|
+
#### Async Uploads
|
132
|
+
If you are working with large YAML files (300+ monitors), you may hit timeouts when trying to sync monitors in a single http request. This workload to be processed asynchronously by adding the key `async: true` to the config file. The request will immediately return a `batch_key`. If a `webhook_url` parameter is included, Cronitor will POST to that URL with the results of the background processing and will include the `batch_key` matching the one returned in the initial response.
|
131
133
|
|
132
134
|
### Using `Cronitor::Monitor.put`
|
133
135
|
|
data/lib/cronitor/config.rb
CHANGED
@@ -9,12 +9,12 @@ module Cronitor
|
|
9
9
|
YAML_KEYS = MONITOR_TYPES.map { |t| "#{t}s" }
|
10
10
|
|
11
11
|
class << self
|
12
|
-
attr_accessor :api_key, :api_version, :environment, :logger, :config, :timeout, :ping_timeout,
|
12
|
+
attr_accessor :api_key, :api_version, :environment, :logger, :config, :timeout, :ping_timeout,
|
13
|
+
:auto_discover_sidekiq, :telemetry_domain
|
13
14
|
|
14
15
|
def configure(&block)
|
15
16
|
block.call(self)
|
16
17
|
end
|
17
|
-
|
18
18
|
end
|
19
19
|
|
20
20
|
self.api_key = ENV.fetch('CRONITOR_API_KEY', nil)
|
data/lib/cronitor/monitor.rb
CHANGED
@@ -5,6 +5,7 @@ module Cronitor
|
|
5
5
|
attr_reader :key, :api_key, :api_version, :env
|
6
6
|
|
7
7
|
PING_RETRY_THRESHOLD = 3
|
8
|
+
MONITOR_API_URL = 'https://cronitor.io/api/monitors'
|
8
9
|
|
9
10
|
module Formats
|
10
11
|
ALL = [
|
@@ -24,13 +25,12 @@ module Cronitor
|
|
24
25
|
})
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
28
|
def self.put(opts = {})
|
29
29
|
rollback = opts[:rollback] || false
|
30
30
|
opts.delete(:rollback)
|
31
31
|
|
32
32
|
monitors = opts[:monitors] || [opts]
|
33
|
-
url =
|
33
|
+
url = MONITOR_API_URL
|
34
34
|
if opts[:format] == Cronitor::Monitor::Formats::YAML
|
35
35
|
url = "#{url}.yaml"
|
36
36
|
monitors['rollback'] = true if rollback
|
@@ -77,12 +77,41 @@ module Cronitor
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
def self.
|
80
|
+
def self.as_yaml(api_key: nil, api_version: nil)
|
81
|
+
timeout = Cronitor.timeout || 10
|
82
|
+
api_key = api_key || Cronitor.api_key
|
83
|
+
|
84
|
+
unless api_key
|
85
|
+
raise Error.new('No API key detected. Set Cronitor.api_key or pass api_key parameter')
|
86
|
+
end
|
87
|
+
|
88
|
+
headers = Cronitor::Monitor::Headers::YAML.dup
|
89
|
+
headers[:'Cronitor-Version'] = api_version if api_version
|
90
|
+
|
91
|
+
resp = HTTParty.get(
|
92
|
+
"#{MONITOR_API_URL}.yaml",
|
93
|
+
basic_auth: {
|
94
|
+
username: api_key,
|
95
|
+
password: ''
|
96
|
+
},
|
97
|
+
headers: headers,
|
98
|
+
timeout: timeout
|
99
|
+
)
|
100
|
+
|
101
|
+
case resp.code
|
102
|
+
when 200
|
103
|
+
resp.body
|
104
|
+
else
|
105
|
+
raise Error.new("Unexpected error #{resp.code}: #{resp.body}")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def delete
|
81
110
|
resp = HTTParty.delete(
|
82
|
-
"#{
|
111
|
+
"#{monitor_api_url}/#{key}",
|
83
112
|
timeout: Cronitor.timeout,
|
84
113
|
basic_auth: {
|
85
|
-
username:
|
114
|
+
username: api_key,
|
86
115
|
password: ''
|
87
116
|
},
|
88
117
|
headers: Cronitor::Monitor::Headers::JSON
|
@@ -187,10 +216,9 @@ module Cronitor
|
|
187
216
|
end
|
188
217
|
|
189
218
|
def monitor_api_url
|
190
|
-
|
219
|
+
MONITOR_API_URL
|
191
220
|
end
|
192
221
|
|
193
|
-
|
194
222
|
private
|
195
223
|
|
196
224
|
def fetch
|
@@ -219,7 +247,7 @@ module Cronitor
|
|
219
247
|
message: params.fetch(:message, nil),
|
220
248
|
series: params.fetch(:series, nil),
|
221
249
|
host: params.fetch(:host, Socket.gethostname),
|
222
|
-
metric: params[:metrics]
|
250
|
+
metric: params[:metrics]&.map { |k, v| "#{k}:#{v}" },
|
223
251
|
stamp: Time.now.to_f,
|
224
252
|
env: params.fetch(:env, env)
|
225
253
|
}
|
data/lib/cronitor/version.rb
CHANGED
data/lib/cronitor.rb
CHANGED
@@ -32,7 +32,7 @@ module Cronitor
|
|
32
32
|
def self.apply_config(rollback: false)
|
33
33
|
conf = read_config
|
34
34
|
# allow a significantly longer timeout on requests that are sending full yaml config. min 30 seconds.
|
35
|
-
timeout = Cronitor.timeout
|
35
|
+
timeout = [Cronitor.timeout, 30].max
|
36
36
|
monitors = Monitor.put(monitors: conf, format: Cronitor::Monitor::Formats::YAML, rollback: rollback,
|
37
37
|
timeout: timeout)
|
38
38
|
count = 0
|
@@ -49,6 +49,17 @@ module Cronitor
|
|
49
49
|
apply_config(rollback: true)
|
50
50
|
end
|
51
51
|
|
52
|
+
def self.generate_config(path = nil)
|
53
|
+
config_path = path || Cronitor.config || './cronitor.yaml'
|
54
|
+
yaml_content = Monitor.as_yaml
|
55
|
+
|
56
|
+
File.open(config_path, 'w') do |file|
|
57
|
+
file.write(yaml_content)
|
58
|
+
end
|
59
|
+
|
60
|
+
puts("Configuration saved to #{config_path}")
|
61
|
+
end
|
62
|
+
|
52
63
|
def self.job(key, &block)
|
53
64
|
monitor = Monitor.new(key)
|
54
65
|
series = Time.now.to_f
|
@@ -62,7 +73,6 @@ module Cronitor
|
|
62
73
|
raise e
|
63
74
|
end
|
64
75
|
end
|
65
|
-
|
66
76
|
end
|
67
77
|
|
68
78
|
Cronitor.read_config(Cronitor.config) unless Cronitor.config.nil?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Byrnes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|