-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprometheus.yml.tmpl
More file actions
42 lines (37 loc) · 1.13 KB
/
prometheus.yml.tmpl
File metadata and controls
42 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{{- with service }}
{{- with .Parent }}
{{- $my_stack := .Stack.Name }}
{{- $my_service := .Name }}
{{- $label := printf "%s/%s" $my_stack $my_service }}
{{- if hasKey .Metadata "prometheus.yml" }}
{{ yaml (get .Metadata "prometheus.yml") }}
{{- end }}
scrape_configs:
- job_name: 'Prometheus'
static_configs:
- targets:
- '127.0.0.1:9090'
{{ range $service := services }}
{{- with $service }}
{{- if hasKey .Metadata $label }}
{{- if (gt (len $service.Containers) 0) }}
{{- $hostLabel := default "%{ip}" (get (get .Metadata $label) "address") }}
- job_name: {{ $service.Name }}.{{ $service.Stack.Name }}.rancher.internal
static_configs:
- targets:
{{- $targets := dict "count" 0 }}
{{- range $service.Containers }}
{{- if .Host }}
{{- $targets := set $targets "count" (add (get $targets "count") 1) }}
{{- $host := .Host }}
- "{{ replace "%{host.ip}" $host.AgentIP (replace "%{ip}" .PrimaryIp $hostLabel) }}"
{{- end }}
{{- end }}
{{- if eq (get $targets "count") 0 }} []{{- end }}
{{ indent 2 (yaml (omit (get .Metadata $label) "address")) }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}