{% if not prometheus_receive_only %}
global:
  scrape_interval: 60s

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - node.rules.yml

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - localhost:9093

remote_write:
- url: http://{{ prometheus_domain }}:9090/api/v1/write
  write_relabel_configs:
  - source_labels: [__name__]
    regex: "archive_directory_size_bytes|archive_total_packages|rebuilderd_results|rebuilderd_workers|rebuilderd_queue_length|repository_directory_size_bytes|aur_.+"
    action: keep
  basic_auth:
    username: {{ vault_prometheus_user }}
    password: {{ vault_prometheus_passwd }}

scrape_configs:
  - job_name: prometheus
    static_configs:
    - targets: ['127.0.0.1:9090']
      labels:
        instance: "{{ ansible_fqdn }}"

  - job_name: prometheus-domain
    scheme: http
    basic_auth:
      username: {{ vault_prometheus_user }}
      password: {{ vault_prometheus_passwd }}
    static_configs:
    - targets: ['{{ prometheus_domain }}:9090']
      labels:
        job: prometheus
        instance: "dashboards.archlinux.org"

  - job_name: loki
    static_configs:
    - targets: ['127.0.0.1:3100']
      labels:
        instance: "{{ ansible_fqdn }}"

  - job_name: 'node_exporter'
    static_configs:
    {% for host in groups['node_exporters'] %}

    - targets: ['{{ host }}:{{ prometheus_exporter_port }}']
      labels:
        instance: "{{ host }}"

    {% endfor %}

  - job_name: 'promtail'
    static_configs:
    {% for host in groups['node_exporters'] %}

    - targets: ['{{ hostvars[host]['wireguard_address'] }}:9080']
      labels:
        instance: "{{ host }}"

    {% endfor %}

  - job_name: 'gitlab_runner_exporter'
    static_configs:
    {% for host in groups['gitlab_runners'] %}

    - targets: ['{{ host }}:{{ gitlab_runner_exporter_port }}']
      labels:
        instance: "{{ host }}"

    {% endfor %}

  - job_name: 'keycloak'
    scheme: https
    metrics_path: "/auth/realms/master/metrics"
    basic_auth:
       username: "{{ vault_keycloak_nginx_user }}"
       password: "{{ vault_keycloak_nginx_passwd }}"
    static_configs:
    - targets: ['accounts.archlinux.org:443']
      labels:
        instance: "accounts.archlinux.org"

  - job_name: 'gitlab_exporter'
    scheme: https
    metrics_path: "-/metrics"
    params:
      token: ["{{ vault_gitlab_prometheus_token }}"]
    static_configs:
    - targets: ['gitlab.archlinux.org:443']
      labels:
        instance: "gitlab.archlinux.org"

  - job_name: 'mysqld_exporter'
    static_configs:
    {% for host in groups['mysql_servers'] %}

    - targets: ['{{ host }}:{{ prometheus_mysqld_exporter_port }}']
      labels:
        instance: "{{ host }}"

    {% endfor %}


  - job_name: 'memcached_exporter'
    static_configs:
    {% for host in groups['memcached'] %}

    - targets: ['{{ host }}:{{ prometheus_memcached_exporter_port }}']
      labels:
        instance: "{{ host }}"

    {% endfor %}

  - job_name: hedgedoc
    scheme: https
    authorization:
      credentials: {{ vault_hedgedoc_metrics_token }}
    static_configs:
    - targets: ['md.archlinux.org:443']

  - job_name: grafana
    scheme: https
    authorization:
      credentials: {{ vault_grafana_metrics_token }}
    static_configs:
    - targets: ['monitoring.archlinux.org:443', 'dashboards.archlinux.org:443']

{% for module in blackbox_targets.keys() %}
  - job_name: 'blackbox_{{ module }}'
    metrics_path: /probe
    scrape_interval: 15s
    params:
      module: [{{ module }}]
    static_configs:
    - targets:
    {% for target in blackbox_targets[module] %}
      - {{ target }}
    {% endfor %}

    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115
{% endfor %}
{% for endpoint in matrix_metrics_endpoints %}

  - job_name: 'synapse_{{ endpoint }}'
    scrape_interval: 15s
    metrics_path: "/metrics/synapse.{{ endpoint }}"
    scheme: https
    basic_auth:
      username: {{ vault_matrix_secrets.metrics_user }}
      password: {{ vault_matrix_secrets.metrics_password }}
    static_configs:
      - targets: ["matrix.archlinux.org:443"]
{% endfor %}
{% endif %}
