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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30416669c4f7bb2b6361e750e035cd588c36911d9a1dea6d4805dd82c90edc0d
4
- data.tar.gz: fbca77d7ef766ebf9b8579a3247935919bc877e966f1fed665d09d79f5437124
3
+ metadata.gz: b3d7fc66146ff02aa81bb3517188f14d8ce8c04b9b643b869aba9793610560b6
4
+ data.tar.gz: 19c2c8f08062072d54a90fe7d848b30ae24b5997a6179ba3aac6ddd5e31008be
5
5
  SHA512:
6
- metadata.gz: c9a3425976be45501efba88d5d777552ad53230ce6db50b30f6e91c26da3d06003b1e6ba3ef0b518350782dc9b0e55a82e17b6368a6fe23d13cdafe3377df53b
7
- data.tar.gz: 87e6389322c82c4cbb9b79ec25a808a9db0c0c4c9e8c4cccd26bd9ad58dc812d2ade6210a3ecd705c418b3d4b9d0c9dc4142198f7608f2b047f2817530ae8347
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)
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchfor
4
- VERSION = "0.11.0"
4
+ VERSION = "0.12.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchfor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - WatchFor