Skip to content

Instantly share code, notes, and snippets.

@mfournier
Created March 18, 2016 21:34
Show Gist options
  • Save mfournier/53c922ecd143307116e6 to your computer and use it in GitHub Desktop.
Save mfournier/53c922ecd143307116e6 to your computer and use it in GitHub Desktop.
(deftest pgsql-xlog_pos
(let [index (:index (inject! [
{:pgsql_master "false"
:host "some_slave"
:service "postgresql-template1/gauge-xlog_pos-absolute/value"
:pgsql_defined_master_address "some_master-public-address"
:plugin "postgresql"
:tags ["collectd"]
:metric 48579391504
:ttl 20
:time 1}
{:pgsql_master "true"
:host "some_master-public-address"
:service "postgresql-template1/gauge-xlog_pos-absolute/value"
:pgsql_master_public_address "some_master-public-address"
:plugin "postgresql"
:tags ["collectd"]
:metric 48579391504
:ttl 20
:time 2}
{:pgsql_master "false"
:host "another_slave"
:service "postgresql-template1/gauge-xlog_pos-absolute/value"
:pgsql_defined_master_address "another_master-public-address"
:plugin "postgresql"
:tags ["collectd"]
:metric 48579391504
:ttl 20
:time 3}
{:pgsql_master "true"
:host "another_master-private-address" ; nb: deliberate private-public mismatch
:service "postgresql-template1/gauge-xlog_pos-absolute/value"
:pgsql_master_public_address "another_master-public-address"
:plugin "postgresql"
:tags ["collectd"]
:metric 48579391514
:ttl 20
:time 4}
{:host "foo"
:service "bar"
:ttl 20
:time 999}
]))]
;(clojure.pprint/pprint index)
;; slave in sync with master
(let [event (lookup index "some_slave" "pgsql write operations behind some_master-public-address")]
(is (= (:state event) "ok"))
(is (= (:metric event) 0))
(is (= (:pgsql_clusterid event) "some_master-public-address"))
(is (= (type (:slave-xlog_pos event)) java.lang.String))
(is (= (type (:master-xlog_pos event)) java.lang.String))
(is (= (count (:tags event)) 1))
(is (= (first (:tags event)) "pgrepl"))
)
;; slave out of sync with master
(let [event (lookup index "another_slave" "pgsql write operations behind another_master-public-address")]
(is (= (:state event) "critical"))
(is (= (:metric event) 10))
(is (= (:pgsql_clusterid event) "another_master-public-address"))
(is (= (count (:tags event)) 1))
(is (= (first (:tags event)) "pgrepl"))
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment