watchfor 0.11.0 → 0.12.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/README.md +8 -0
- data/exe/watchfor +6 -1
- data/lib/watchfor/client.rb +12 -2
- data/lib/watchfor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3d7fc66146ff02aa81bb3517188f14d8ce8c04b9b643b869aba9793610560b6
|
|
4
|
+
data.tar.gz: 19c2c8f08062072d54a90fe7d848b30ae24b5997a6179ba3aac6ddd5e31008be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c53ae17ddbc628f745c8099df3d1425627c1da778e616fd2a4cfc8bfca0680b56ff188881383d8f1f6cc10b68f42f53264b1cbc3ebf5f33cc4f8fb069045a703
|
|
7
|
+
data.tar.gz: b2214618bce3e48a10c5c8bbac5c4ee60f79281445472bde3fe225e82606297b21c7e087d12da41f68a0e20c15d8e6863846608165064add64511a8562940dd2
|
data/README.md
CHANGED
|
@@ -90,6 +90,14 @@ Namespaces: `wf.monitors`, `wf.alert_rules`, `wf.incidents`,
|
|
|
90
90
|
`wf.incident_stats(period)`, `wf.notifications`, `wf.activity`. Errors raise
|
|
91
91
|
`Watchfor::Error` with `#status`, `#code`, `#message`.
|
|
92
92
|
|
|
93
|
+
## Prometheus metrics (Pro plan and above)
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
text = wf.metrics(tag: "production") # Prometheus text format
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Usually you point Prometheus at `https://watchfor.io/api/v1/metrics` directly; this is for scripts and one-off checks. See https://watchfor.io/docs/api/prometheus.
|
|
100
|
+
|
|
93
101
|
## CLI
|
|
94
102
|
|
|
95
103
|
```bash
|
data/exe/watchfor
CHANGED
|
@@ -36,8 +36,13 @@ begin
|
|
|
36
36
|
cursor = args.include?("--cursor") ? args[args.index("--cursor") + 1] : nil
|
|
37
37
|
wf.monitors.checks(monitor_id, cursor: cursor)
|
|
38
38
|
when "report" then wf.report(period: args.include?("--period") ? args[args.index("--period") + 1] : nil)
|
|
39
|
+
when "metrics"
|
|
40
|
+
tag = args.include?("--tag") ? args[args.index("--tag") + 1] : nil
|
|
41
|
+
type = args.include?("--type") ? args[args.index("--type") + 1] : nil
|
|
42
|
+
print wf.metrics(tag: tag, type: type)
|
|
43
|
+
exit 0
|
|
39
44
|
else
|
|
40
|
-
warn "Usage: watchfor [summary|plan|monitors|locations|monitor-types|incidents|checks <monitor_id> [--cursor c]|report [--period 7d|30d]]"
|
|
45
|
+
warn "Usage: watchfor [summary|plan|monitors|locations|monitor-types|incidents|checks <monitor_id> [--cursor c]|report [--period 7d|30d]|metrics [--tag t] [--type t]]"
|
|
41
46
|
exit 2
|
|
42
47
|
end
|
|
43
48
|
puts JSON.pretty_generate(result)
|
data/lib/watchfor/client.rb
CHANGED
|
@@ -51,7 +51,7 @@ module Watchfor
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# Core request. +query+ and +body+ are optional hashes.
|
|
54
|
-
def request(method, path, query: nil, body: nil, idempotency_key: nil)
|
|
54
|
+
def request(method, path, query: nil, body: nil, idempotency_key: nil, text: false)
|
|
55
55
|
uri = URI("#{@base_url}#{path}")
|
|
56
56
|
unless query.nil? || query.empty?
|
|
57
57
|
cleaned = query.reject { |_, v| v.nil? || v == "" }
|
|
@@ -65,7 +65,7 @@ module Watchfor
|
|
|
65
65
|
}.fetch(method)
|
|
66
66
|
req = klass.new(uri)
|
|
67
67
|
req["Authorization"] = "Bearer #{@api_key}"
|
|
68
|
-
req["Accept"] = "application/json"
|
|
68
|
+
req["Accept"] = text ? "text/plain, application/json" : "application/json"
|
|
69
69
|
req["User-Agent"] = "watchfor-ruby/#{Watchfor::VERSION}"
|
|
70
70
|
req["Idempotency-Key"] = idempotency_key if idempotency_key
|
|
71
71
|
unless body.nil?
|
|
@@ -80,6 +80,8 @@ module Watchfor
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
raw = res.body.to_s
|
|
83
|
+
return raw if text && res.code.to_i.between?(200, 299)
|
|
84
|
+
|
|
83
85
|
parsed = raw.empty? ? nil : (JSON.parse(raw) rescue nil)
|
|
84
86
|
unless res.code.to_i.between?(200, 299)
|
|
85
87
|
err = parsed.is_a?(Hash) ? (parsed["error"] || {}) : {}
|
|
@@ -92,6 +94,14 @@ module Watchfor
|
|
|
92
94
|
# Top-level reads
|
|
93
95
|
def me = request("GET", "/me")
|
|
94
96
|
def summary = request("GET", "/summary")
|
|
97
|
+
|
|
98
|
+
# The organization in Prometheus text format (Pro plan and above):
|
|
99
|
+
# status, uptime, response times, expiry, heartbeats, hosts. Cached 60 s.
|
|
100
|
+
def metrics(tag: nil, type: nil, monitor_id: nil, include_hosts: nil)
|
|
101
|
+
query = { tag: tag, type: type, monitor_id: monitor_id,
|
|
102
|
+
include_hosts: include_hosts.nil? ? nil : include_hosts.to_s }
|
|
103
|
+
request("GET", "/metrics", query: query, text: true)
|
|
104
|
+
end
|
|
95
105
|
def plan = request("GET", "/plan")
|
|
96
106
|
def incident_stats(period = nil) = request("GET", "/incidents/stats", query: { period: period })
|
|
97
107
|
|
data/lib/watchfor/version.rb
CHANGED