Fix log archive in stage3
[osm/devops.git] / installers / docker / osm_pods / ng-prometheus.yaml
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17
18 apiVersion: v1
19 kind: Service
20 metadata:
21   name: prometheus
22 spec:
23   ports:
24   - nodePort: 9091
25     port: 9090
26     protocol: TCP
27     targetPort: 9090
28   selector:
29     app: prometheus
30   type: NodePort
31 ---
32 apiVersion: v1
33 kind: ConfigMap
34 metadata:
35   name: prom
36 data:
37   osm_metric_rules.yml: |
38     groups:
39       - name: osm_metric_rules
40         rules:
41         - record: vm_status_extended
42           expr: (last_over_time(vm_status[1m]) * on (vm_id, vim_id) group_left(ns_id, vnf_id, vdu_id, project_id, job, vdu_name, vnf_member_index) last_over_time(ns_topology[1m])) or (last_over_time(ns_topology[1m]) * -1)
43           labels:
44             job: osm_prometheus
45         - record: vnf_status
46           expr: (0 * (count (vm_status_extended==0) by (ns_id, vnf_id)>=0)) or (min by (ns_id, vnf_id) (vm_status_extended))
47           labels:
48             job: osm_prometheus
49         - record: ns_status
50           expr: (0 * (count (vm_status_extended==0) by (ns_id)>=0)) or (min by (ns_id) (vm_status_extended))
51           labels:
52             job: osm_prometheus
53   osm_alert_rules.yml: |
54     groups:
55       - name: osm_alert_rules
56         rules:
57         - alert: vdu_down
58           expr: vm_status_extended != 1
59           for: 3m
60           annotations:
61             summary: "VDU {{ $labels.vm_id }} in VIM {{ $labels.vim_id }} is down"
62             description: "VDU {{ $labels.vm_id }} in VIM {{ $labels.vim_id }} has been down for more than 3 minutes. NS instance id is {{ $labels.ns_id }}"
63   prometheus.yml: |
64     # Copyright 2018 The Prometheus Authors
65     # Copyright 2018 Whitestack
66     # Copyright 2018 Telefonica Investigacion y Desarrollo, S.A.U.
67     #
68     # Licensed under the Apache License, Version 2.0 (the "License");
69     # you may not use this file except in compliance with the License.
70     # You may obtain a copy of the License at
71     #
72     # http://www.apache.org/licenses/LICENSE-2.0
73     #
74     # Unless required by applicable law or agreed to in writing, software
75     # distributed under the License is distributed on an "AS IS" BASIS,
76     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77     # See the License for the specific language governing permissions and
78     # limitations under the License.
79
80     # my global config
81     global:
82       scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
83       evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
84       # scrape_timeout is set to the global default (10s).
85
86     # Alertmanager configuration
87     alerting:
88       alertmanagers:
89       - static_configs:
90         - targets:
91           - alertmanager:9093
92
93     # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
94     rule_files:
95       - "osm_metric_rules.yml"
96       - "osm_alert_rules.yml"
97
98     # A scrape configuration containing exactly one endpoint to scrape:
99     # Here it's Prometheus itself.
100     scrape_configs:
101       - job_name: 'mon_exporter'
102         static_configs:
103         - targets: ['mon:8000']
104       - job_name: pushgateway
105         honor_labels: true
106         scrape_interval: 30s
107         static_configs:
108         - targets:
109           - pushgateway-prometheus-pushgateway:9091
110 ---
111 apiVersion: apps/v1
112 kind: StatefulSet
113 metadata:
114   name: prometheus
115   labels:
116     app: prometheus
117 spec:
118   replicas: 1
119   serviceName: prometheus
120   selector:
121     matchLabels:
122       app: prometheus
123   template:
124     metadata:
125       labels:
126         app: prometheus
127     spec:
128       initContainers:
129       - name: prometheus-init-config
130         image: busybox
131         command: ["/bin/sh", "-c"]
132         args: ['if [ ! -f "/etc/prometheus/prometheus.yml" ]; then cp /config/prometheus.yml /etc/prometheus; fi; cp /config/osm_metric_rules.yml /config/osm_alert_rules.yml /etc/prometheus']
133         volumeMounts:
134           - name: prom-config
135             mountPath: /etc/prometheus
136           - name: prom-config-base
137             mountPath: /config
138       containers:
139       - name: prometheus
140         image: prom/prometheus:v2.28.1
141         args:
142         - --config.file=/etc/prometheus/prometheus.yml
143         - --web.enable-lifecycle
144         ports:
145         - containerPort: 9090
146           protocol: TCP
147         volumeMounts:
148         - name: prom-config
149           mountPath: /etc/prometheus
150         - name: prom-db
151           mountPath: /prometheus
152       - name: prometheus-config-sidecar
153         image: opensourcemano/prometheus:13
154         env:
155         - name: MONGODB_URL
156           value: mongodb://mongodb-k8s:27017/?replicaSet=rs0
157         - name: PROMETHEUS_CONFIG_FILE
158           value: /etc/prometheus/prometheus.yml
159         - name: PROMETHEUS_BASE_CONFIG_FILE
160           value: /etc/prometheus_base/prometheus.yml
161         - name: TARGET_DATABASE
162           value: osm
163         - name: PROMETHEUS_URL
164           value: http://prometheus:9090
165         volumeMounts:
166         - name: prom-config
167           mountPath: /etc/prometheus
168         - name: prom-config-base
169           mountPath: /etc/prometheus_base
170       volumes:
171       - name: prom-db
172         emptyDir: {}
173       - name: prom-config
174         emptyDir: {}
175       - name: prom-config-base
176         configMap:
177           name: prom