[buildout]
parts =
  directory
  check-disk-space.py
  check-partition-space.py
  check-cpu-temperature.py
  check-ram-usage.py
  check-network-errors.py
  check-network-transit.py
  check-cpu-load.py
  publish-connection-information

extends = {{ monitor_template }}

eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = {{ slap_connection['computer-id'] }}
partition = {{ slap_connection['partition-id'] }}
url = {{ slap_connection['server-url'] }}
key = {{ slap_connection['key-file'] }}
cert = {{ slap_connection['cert-file'] }}

[directory]
recipe = slapos.cookbook:mkdirectory
software = {{ buildout_directory }}
home = ${buildout:directory}
etc = ${:home}/etc
var = ${:home}/var
etc = ${:home}/etc
bin = ${:home}/bin
run = ${:var}/run
script = ${:etc}/run
service = ${:etc}/service
promise = ${:etc}/promise
log = ${:var}/log

[publish-connection-information]
recipe = slapos.cookbook:publish.serialised
<= monitor-publish

[macro.promise]
<= monitor-promise-base
name = ${:_buildout_section_name_}

[check-disk-space.py]
<= macro.promise
eggs = slapos.toolbox[prediction]
promise = check_free_disk_space
config-collectordb = ${monitor-instance-parameter:collector-db}
config-frequency = {{ slapparameter_dict.get("promise_free_disk_space_frequency", 60) }}
config-threshold = {{ slapparameter_dict.get("promise_free_disk_space_threshold", 0.08) }}
config-nb-days-predicted = {{ slapparameter_dict.get("promise_free_disk_space_nb_days_predicted", 10) }}
config-display-partition = {{ int(slapparameter_dict.get("promise_free_disk_space_display_partition", 1)) }}
config-display-prediction = {{ int(slapparameter_dict.get("promise_free_disk_space_display_prediction", 1)) }}

[check-partition-space.py]
<= macro.promise
eggs = slapos.toolbox[pandas]
promise = monitor_partition_space
config-collectordb = ${monitor-instance-parameter:collector-db}
config-frequency = {{ slapparameter_dict.get("promise_monitor_space_frequency", 60) }}
config-threshold-ratio = {{ slapparameter_dict.get("promise_partition_space_threshold", 0.08) }}

[check-cpu-temperature.py]
<= macro.promise
promise = check_cpu_temperature
config-testing = false
config-frequency = {{ slapparameter_dict.get("promise_cpu_temperature_frequency", 5) }}
config-max-spot-temp = {{ slapparameter_dict.get("promise_cpu_temperature_threshold", 90) }}
config-max-avg-temp = {{ slapparameter_dict.get("promise_cpu_avg_temperature_threshold", 80) }}
config-avg-temp-duration = {{ slapparameter_dict.get("promise_cpu_avg_temperature_threshold_duration", 600) }}
config-last-avg-computation-file = ${directory:var}/promise_cpu_temperature_last_avg_file

[check-ram-usage.py]
<= macro.promise
promise = check_ram_usage
config-frequency = {{ slapparameter_dict.get("promise_ram_available_frequency", 2) }}
config-min-threshold-ram = {{ slapparameter_dict.get("promise_ram_available_threshold", 500) }}
config-min-avg-ram = {{ slapparameter_dict.get("promise_ram_avg_available_threshold", 1e3) }}
config-avg-ram-period = {{ slapparameter_dict.get("promise_ram_avg_available_threshold_duration", 600) }}
config-last-avg-ram-file = ${directory:var}/promise_ram_space_last_avg_file

[check-network-errors.py]
<= macro.promise
promise = check_network_errors_packets
config-frequency = {{ slapparameter_dict.get("promise_network_errors_frequency", 5) }}
config-max-error-messages-per-MB = {{ slapparameter_dict.get("promise_network_errors_threshold", 100) }}
config-max-lost-packets-per-MB = {{ slapparameter_dict.get("promise_network_lost_packets_threshold", 100) }}

[check-network-transit.py]
<= macro.promise
promise = check_network_transit
config-frequency = {{ slapparameter_dict.get("promise_network_transit_frequency", 5) }}
config-max-data-amount = {{ slapparameter_dict.get("promise_network_transit_max_data_threshold", 1e6) }}
config-min-data-amount = {{ slapparameter_dict.get("promise_network_transit_min_data_threshold", 0) }}
config-transit-period = {{ slapparameter_dict.get("promise_network_transit_duration", 600) }}
config-last-transit-file = ${directory:var}/promise_network_last_transit_file

[check-cpu-load.py]
<= macro.promise
promise = check_server_cpu_load
config-frequency = {{ slapparameter_dict.get("promise_cpu_load_frequency", 3) }}
config-cpu-load-threshold = {{ slapparameter_dict.get("promise_cpu_load_threshold", 1.5) }}
