Giriş
Burada sorgulanacak sunucuların bilgileri tanımlı. Açıklaması şöyle
The attribute job_name is used to define the name of the target we monitor, here we set it as “prometheus”.The targets attribute is used to define the address of the target, which will be an array of addresses.The default configuration of Prometheus is to monitor itself, when you run Prometheus it will listen on port 9090 and provide a path /metrics for us to get its metrics.
static_configs Alanı
Sorgulanacak sunucuların adreslerini belirtir.
Örnek
Şöyle yaparız
global: scrape_interval: 15s scrape_configs: - job_name: 'darwin-service-1' scrape_interval: 5s static_configs: - targets: ['darwin-service-1:80'] relabel_configs: - source_labels: [job] target_label: job replacement: 'darwin-new-service' - job_name: 'darwin-service-2' scrape_interval: 10s static_configs: - targets: ['darwin-service-2:80']
Açıklaması şöyle
In this example, two separate static_configs blocks are defined, each with a different job_name. The first block scrapes a single target, darwin-service-1:80, every 5 seconds, while the second block scrapes a single target, darwin-service-2:80, every 10 seconds.
Örnek - Jenkins
Jenkins'e Prometheus eklentisi kurulur. Kurduktan sonra adres şöyledir "<Public-
IP:8080/prometheus>"
Şöyle yaparız
- job_name: "Jenkins Job" static_configs: - targets: ["<Public IP of Jenkins Node:8080"]
Örnek
Şöyle yaparız.
global:scrape_interval: 5s scrape_configs: - job_name: prometheus honor_labels: true static_configs: - targets: [ "localhost:9090" ] - job_name: 'spring_micrometer' metrics_path: '/actuator/prometheus' scrape_interval: 5s static_configs: - targets: ['your_host_ip:8080']
metrics_path Alanı
Örnek
Şöyle yaparız
scrape_configs: - job_name: 'Spring Boot Application input' metrics_path: '/actuator/prometheus' scrape_interval: 2s static_configs: - targets: ['localhost:8000'] labels: application: "My Spring Boot Application"
Örnek
Şöyle yaparız. Bu bir spring uygulamasını sorgular
scrape_configs:- job_name: 'spring-actuator'metrics_path: '/actuator/prometheus'scrape_interval: 5sstatic_configs:- targets: ['127.0.0.1:8080']
Örnek
Şöyle yaparız. Bu bir spring uygulamasını sorgular
global:scrape_interval: 15sexternal_labels:monitor: 'quiz-server-monitoring'scrape_configs:- job_name: 'quiz-server'scrape_interval: 10smetrics_path: '/actuator/prometheus'static_configs:- targets: ['app:8080']labels:application: 'quiz-server'
Örnek
Şöyle yaparız. Bu bir spring uygulamasını sorgular
global: scrape_interval: 10s scrape_configs: - job_name: 'spring_micrometer' metrics_path: '/actuator/prometheus' scrape_interval: 5s static_configs: - targets: ['192.168.2.8:8080']
relabel_configs Alanı - Relabeling
Açıklaması şöyle
Relabeling allows you to transform or modify the scraped data labels before storing them in the time-series database. This is useful for modifying labels to match your naming conventions or adding additional metadata to the scraped data.
Örnek
Açıklaması şöyle
For instance, if you want to modify the job label of darwin-service-1 and save the scraped metrics to a new value, say darwin-new-service, you relabel the prometheus.yml configuration file as follows.
Şöyle yaparız
global: scrape_interval: 15s scrape_configs: - job_name: 'darwin-service-1' scrape_interval: 5s static_configs: - targets: ['darwin-service-1:80'] relabel_configs: - source_labels: [job] target_label: job replacement: 'darwin-new-service' - job_name: 'darwin-service-2' scrape_interval: 10s static_configs: - targets: ['darwin-service-2:80']
resources Alanı
Açıklaması şöyle
In a default Prometheus configuration, you deploy containers without resource limits, consequently leading to suboptimal performance of the operating cluster. Instead, you can configure resource consumption at the job, instance, or global level by explicitly defining the limit in the prometheus.yml configuration file.
Şöyle yaparız
global: scrape_interval: 15s scrape_configs: - job_name: 'darwin-service-1' scrape_interval: 5s static_configs: - targets: ['darwin-service-1:80'] relabel_configs: - source_labels: [job] target_label: job replacement: 'darwin-new-service' resources: requests: memory: 2Gi cpu: 1 limits: memory: 4Gi cpu: 2 - job_name: 'darwin-service-2' scrape_interval: 10s static_configs: - targets: ['darwin-service-2:80'] resources: requests: memory: 1Gi cpu: 0.5 limits: memory: 2Gi cpu: 1
alerting Alanı
Açıklaması şöyle. Yani alert olursa hangi kanala gönderileceği burada tanımlı
The alerting section contains the configuration of the tool that we will send an alert to if there is a problem with our system
Açıklaması şöyle
Alerting rules are used to define conditions under which alerts are triggered. As an essential part of monitoring and reliability engineering, you can set up notifications via various channels such as email, Slack, or Squadcast to help detect and resolve issues before they become critical.In this case, the rule_files field points to a directory containing alert rules, which define the conditions under which alerts are triggered. Triggered alerts get sent to the specified Alertmanager targets, which you can further configure to send notifications to various channels, such as email or the Squadcast platform.
Örnek
Şöyle yaparız
global: scrape_interval: 15s evaluation_interval: 1m rule_files: - /etc/prometheus/rules/*.rules scrape_configs: - job_name: 'darwin-service-1' scrape_interval: 5s static_configs: - targets: ['darwin-service-1:80'] relabel_configs: - source_labels: [job] target_label: job replacement: 'darwin-new-service' resources: requests: memory: 2Gi cpu: 1 limits: memory: 4Gi cpu: 2 alerting: alertmanagers: - static_configs: - targets: - alertmanager:9093 - job_name: 'darwin-service-2' scrape_interval: 10s static_configs: - targets: ['darwin-service-2:80'] resources: requests: memory: 1Gi cpu: 0.5 limits: memory: 2Gi cpu: 1 alerting: alertmanagers: - static_configs: - targets: - alertmanager:9093