1 ;;;; ============LICENSE_START==========================================
2 ;;;; ===================================================================
3 ;;;; Copyright (c) 2017 AT&T
5 ;;;; Licensed under the Apache License, Version 2.0 (the "License");
6 ;;;; you may not use this file except in compliance with the License.
7 ;;;; You may obtain a copy of the License at
9 ;;;; http://www.apache.org/licenses/LICENSE-2.0
11 ;;;; Unless required by applicable law or agreed to in writing, software
12 ;;;; distributed under the License is distributed on an "AS IS" BASIS,
13 ;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ;;;; See the License for the specific language governing permissions and
15 ;;;; limitations under the License.
16 ;;;;============LICENSE_END============================================
18 (where (service #"{{service_selector}}")
19 #(info "got event: " %)
21 (where (not (expired? event))
22 (moving-time-window {{moving_window_size}}
30 (if (nil? (@hostmap (m :host)))
32 (swap! hostmap assoc (m :host) (m :metric))
33 (swap! hostcnt assoc (m :host) 1)
36 (swap! hostmap assoc (m :host) (+ (m :metric) (@hostmap (m :host))))
37 (swap! hostcnt assoc (m :host) (inc (@hostcnt (m :host))))
41 (doseq [entry @hostmap]
42 (swap! hostmap assoc (key entry) (/ (val entry) (@hostcnt (key entry))))
46 [ hostcnt (count @hostmap)
47 conns (/ (apply + (map (fn [a] (val a)) @hostmap)) hostcnt)
48 cooling (not (nil? (riemann.index/lookup index "scaling" "suspended")))]
51 (info "cooling=" cooling " scale_direction={{scale_direction}} hostcnt=" hostcnt " scale_threshold={{scale_threshold}} conns=" conns)
52 (if (and (not cooling) ({{scale_direction}} hostcnt {{scale_limit}}) ({{scale_direction}} {{scale_threshold}} conns))
54 (info "=== SCALE ===" "{{scale_direction}}")
55 (process-policy-triggers {})
56 (riemann.index/update index {:host "scaling" :service "suspended" :time (unix-time) :description "cooldown flag" :metric 0 :ttl {{cooldown_time}} :state "ok"})