global:scrape_interval:15sscrape_configs:-job_name:'prometheus'scrape_interval:5sstatic_configs:-targets: ['localhost:9090']# Job, for nginx_exporter-job_name:'NginxExporter'openstack_sd_configs:#ต้องทำการเเก้ไขในส่วนนี้-identity_endpoint:https://identity-api.nipa.cloud/region:NCP-THapplication_credential_id:{appcredentialID}application_credential_secret:{appcredentialsecret}role:instancerelabel_configs:-source_labels: [__meta_openstack_tag_cluster_id]action:keepregex:.+target_label:cluster_id# Update the scraping port if required-source_labels:-__address__action:replaceregex: ([^:]+)(?::\d+)replacement: $1:9113target_label:__address__# Scrape IIS instances -job_name:'IIS'openstack_sd_configs:-identity_endpoint:https://identity-api.nipa.cloud/region:NCP-THapplication_credential_id:{appcredentialID}application_credential_secret:{appcredentialsecret}role:instancerelabel_configs:-source_labels: [__meta_openstack_tag_cluster_id]action:keepregex:.+target_label:cluster_id# Update the scraping port if required-source_labels:-__address__action:replaceregex: ([^:]+)(?::\d+)replacement: $1:9182target_label:__address__# Scrape OpenStack instances-job_name:'openstack'openstack_sd_configs:-identity_endpoint:https://identity-api.nipa.cloud/region:NCP-THapplication_credential_id:{appcredentialID}application_credential_secret:{appcredentialsecret}role:instancerelabel_configs:# Keep Senlin instances that have cluster_id-source_labels: [__meta_openstack_tag_cluster_id]action:keepregex:.+target_label:cluster_id# Update the scraping port if required-source_labels:-__address__action:replaceregex: ([^:]+)(?::\d+)replacement: $1:9100target_label:__address__rule_files:-alert.rules.ymlalerting:alertmanagers:-static_configs:-targets:-'localhost:9093'
groups:- name:examplerules:# Define minimum cluster size - record:min_cluster_sizeexpr:2# Change this value to your actual minimum cluster size# Record the count of instances with idle CPU - record:instance_countexpr:count(count by (instance) (node_cpu_seconds_total{mode="idle"})) # Alert for any instance that has average CPU idle < 60% (40% usage) only if instance count is equal or greater than min_cluster_size
- alert:HighUsageexpr:| (instance_count >= min_cluster_size) and ( avg(irate(node_cpu_seconds_total{mode="idle"}[1m])) * 100 < 60 )for:1mannotations:summary:"High usage on {{ $labels.instance }}"description:"{{ $labels.instance }} has an average CPU idle of less than 60% (current value: {{ $value }}%)" # Alert for any instance that has average CPU idle > 75% (25% usage) only if instance count is greater than min_cluster_size
- alert:LowUsageexpr:| (instance_count > min_cluster_size) and ( avg(irate(node_cpu_seconds_total{mode="idle"}[1m])) * 100 > 75 )for:1mannotations:summary:"Low usage on {{ $labels.instance }}"description:"{{ $labels.instance }} has an average CPU idle of more than 75% (current value: {{ $value }}%)"
4.2 กรณีใช้กับ Nginx Exporter
groups:- name:HTTPREQUESTrules:# Record the minimum cluster size (adjust as needed) - record:min_cluster_sizeexpr:1# Adjust this value to your actual minimum cluster size# Record the count of instances (using a different metric if available) - record:instance_countexpr:count(count by (instance) (nginx_http_requests_total))# Adjust based on available metrics# Alert to scale out if current HTTP requests are greater than 200 and instance count is >= min_cluster_size - alert:HighUsageexpr:| (instance_count >= min_cluster_size) and (sum(rate(nginx_http_requests_total[1m]))) > 200for:1mannotations:summary:"Scale out: High number of HTTP requests" description: "Number of HTTP requests exceeds 200 and instance count is greater than or equal to minimum cluster size."
# Alert to scale in if current HTTP requests are less than 200 and instance count is > min_cluster_size - alert:LowUsageexpr:| (instance_count > min_cluster_size) and (sum(rate(nginx_http_requests_total[1m]))) < 200for:1mannotations:summary:"Scale in: Low number of HTTP requests"description:"Number of HTTP requests is less than 200 and instance count is greater than minimum cluster size."
4.3 กรณีใช้กับ Window_Exporter(for IIS)
groups:- name:WINDOWREQUESTrules:# Record the minimum cluster size (adjust as needed) - record:min_cluster_sizeexpr:1# Adjust this value to your actual minimum cluster size# Record the count of instances (using a different metric if available) - record:instance_countexpr:count(count by (instance) (windows_iis_requests_total))# Adjust based on available metrics# Alert to scale out if current HTTP requests are greater than 200 and instance count is >= min_cluster_size - alert:HighUsageexpr:| (instance_count >= min_cluster_size) and (sum(rate(windows_iis_requests_total[1m]))) > 200for:1mannotations:summary:"Scale out: High number of HTTP requests" description: "Number of HTTP requests exceeds 200 and instance count is greater than or equal to minimum cluster size."
# Alert to scale in if current HTTP requests are less than 200 and instance count is > min_cluster_size - alert:LowUsageexpr:| (instance_count > min_cluster_size) and (sum(rate(windows_iis_requests_total[1m]))) < 200for:1mannotations:summary:"Scale in: Low number of HTTP requests"description:"Number of HTTP requests is less than 200 and instance count is greater than minimum cluster size."