initial monitoring ability
This commit is contained in:
parent
82f7e86a39
commit
ef8439342b
5 changed files with 75 additions and 2 deletions
3
deps.edn
3
deps.edn
|
@ -13,7 +13,8 @@
|
|||
orchestra/orchestra {:mvn/version "2021.01.01-1"}
|
||||
aero/aero {:mvn/version "1.1.6"}
|
||||
cheshire/cheshire {:mvn/version "5.13.0"}
|
||||
com.widdindustries/cljc.java-time {:mvn/version "0.1.21"}}
|
||||
com.widdindustries/cljc.java-time {:mvn/version "0.1.21"}
|
||||
org.babashka/http-client {:mvn/version "0.3.11"}}
|
||||
;; ---------------------------------------------------------
|
||||
|
||||
;; ---------------------------------------------------------
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns dda.backup.infrastructure
|
||||
(:require [orchestra.core :refer [defn-spec]]
|
||||
[babashka.tasks :as t]
|
||||
[babashka.http-client :as http]
|
||||
[dda.backup.core.domain :as core]))
|
||||
|
||||
(defn-spec execute-out! string?
|
||||
|
@ -31,3 +32,8 @@
|
|||
(println c))
|
||||
(when-not dry-run
|
||||
(apply t/shell c)))))
|
||||
|
||||
(defn-spec post! nil?
|
||||
[url string?
|
||||
content string?]
|
||||
(http/post url {:body content}))
|
23
src/dda/backup/monitoring.clj
Normal file
23
src/dda/backup/monitoring.clj
Normal file
|
@ -0,0 +1,23 @@
|
|||
(ns dda.backup.monitoring
|
||||
(:require
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[dda.backup.monitoring.domain :as domain]
|
||||
[dda.backup.infrastructure :as i]))
|
||||
|
||||
(def default {:url "http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job"
|
||||
:namespace "default"
|
||||
:metrics {:kube_job_status_active 0
|
||||
:kube_job_status_failed 1
|
||||
:kube_job_status_succeeded 0}})
|
||||
|
||||
(defn- config-w-defaults
|
||||
[config]
|
||||
(merge default config))
|
||||
|
||||
(defn-spec send-metrics! nil?
|
||||
[config ::domain/config]
|
||||
(let [config-2-use (config-w-defaults config)
|
||||
{:keys [url name]} config-2-use]
|
||||
(try
|
||||
(i/post! (str url "/" name) (domain/collect-metrics config-2-use))
|
||||
(catch Exception e (println (str "Warn: unable to send log" (.getMessage e)))))))
|
23
src/dda/backup/monitoring/domain.clj
Normal file
23
src/dda/backup/monitoring/domain.clj
Normal file
|
@ -0,0 +1,23 @@
|
|||
(ns dda.backup.monitoring.domain
|
||||
(:require
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as st]))
|
||||
|
||||
(s/def ::url string?)
|
||||
(s/def ::name string?)
|
||||
(s/def ::namespace string?)
|
||||
(s/def ::metrics map?)
|
||||
|
||||
(s/def ::config (s/keys :req-un [::url ::name ::metrics ::namespace]))
|
||||
|
||||
(defn-spec collect-metrics string?
|
||||
[config ::config]
|
||||
(let [{:keys [metrics namespace]} config]
|
||||
(str
|
||||
(->> metrics
|
||||
(map (fn [entry] (str (name (key entry))
|
||||
"{namespace=" namespace "}" " "
|
||||
(val entry))))
|
||||
(st/join "\n"))
|
||||
"\n")))
|
20
test/dda/backup/monitoring/domain_test.clj
Normal file
20
test/dda/backup/monitoring/domain_test.clj
Normal file
|
@ -0,0 +1,20 @@
|
|||
(ns dda.backup.monitoring.domain-test
|
||||
(:require
|
||||
[clojure.test :refer [deftest is are testing run-tests]]
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[dda.backup.monitoring.domain :as cut]))
|
||||
|
||||
(st/instrument `cut/collect-metrics)
|
||||
|
||||
(deftest should-collect-metrics
|
||||
(is (= "\n"
|
||||
(cut/collect-metrics {:url "url"
|
||||
:name "name"
|
||||
:namespace "default"
|
||||
:metrics {}})))
|
||||
(is (= "metric1{namespace=default} 1\nmetric2{namespace=default} text\n"
|
||||
(cut/collect-metrics {:url "url"
|
||||
:name "name"
|
||||
:namespace "default"
|
||||
:metrics {:metric1 1
|
||||
:metric2 "text"}}))))
|
Loading…
Reference in a new issue