欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

prometheus安裝和使用過(guò)程

 更新時(shí)間:2023年06月20日 09:01:35   作者:輝子t1  
Prometheus是一個(gè)開(kāi)源的系統(tǒng)監(jiān)控和報(bào)警系統(tǒng),通常會(huì)搭配prometheus進(jìn)行監(jiān)控,同時(shí)也支持多種exporter采集數(shù)據(jù),還支持pushgateway進(jìn)行數(shù)據(jù)上報(bào),Prometheus性能足夠支撐上萬(wàn)臺(tái)規(guī)模的集群,這篇文章主要介紹了prometheus安裝和使用記錄,需要的朋友可以參考下

一、Prometheus介紹

Prometheus是一個(gè)開(kāi)源的系統(tǒng)監(jiān)控和報(bào)警系統(tǒng),現(xiàn)在已經(jīng)加入到CNCF基金會(huì),成為繼k8s之后第二個(gè)在CNCF托管的項(xiàng)目,在kubernetes容器管理系統(tǒng)中,通常會(huì)搭配prometheus進(jìn)行監(jiān)控,同時(shí)也支持多種exporter采集數(shù)據(jù),還支持pushgateway進(jìn)行數(shù)據(jù)上報(bào),Prometheus性能足夠支撐上萬(wàn)臺(tái)規(guī)模的集群。

二、Prometheus特點(diǎn)

2.1、prometheus特點(diǎn)

1)多維度數(shù)據(jù)模型

每一個(gè)時(shí)間序列數(shù)據(jù)都由metric度量指標(biāo)名稱(chēng)和它的標(biāo)簽labels鍵值對(duì)集合唯一確定:這個(gè)metric度量指標(biāo)名稱(chēng)指定監(jiān)控目標(biāo)系統(tǒng)的測(cè)量特征(如:http_requests_total- 接收http請(qǐng)求的總計(jì)數(shù))。labels開(kāi)啟了Prometheus的多維數(shù)據(jù)模型:對(duì)于相同的度量名稱(chēng),通過(guò)不同標(biāo)簽列表的結(jié)合, 會(huì)形成特定的度量維度實(shí)例。(例如:所有包含度量名稱(chēng)為/api/tracks的http請(qǐng)求,打上method=POST的標(biāo)簽,則形成了具體的http請(qǐng)求)。這個(gè)查詢(xún)語(yǔ)言在這些度量和標(biāo)簽列表的基礎(chǔ)上進(jìn)行過(guò)濾和聚合。改變?nèi)魏味攘可系娜魏螛?biāo)簽值,則會(huì)形成新的時(shí)間序列圖。

2)靈活的查詢(xún)語(yǔ)言(PromQL):可以對(duì)采集的metrics指標(biāo)進(jìn)行加法,乘法,連接等操作;

3)可以直接在本地部署,不依賴(lài)其他分布式存儲(chǔ);

4)通過(guò)基于HTTP的pull方式采集時(shí)序數(shù)據(jù);

5)可以通過(guò)中間網(wǎng)關(guān)pushgateway的方式把時(shí)間序列數(shù)據(jù)推送到prometheus server端;

6)可通過(guò)服務(wù)發(fā)現(xiàn)或者靜態(tài)配置來(lái)發(fā)現(xiàn)目標(biāo)服務(wù)對(duì)象(targets)。

7)有多種可視化圖像界面,如Grafana等。

8)高效的存儲(chǔ),每個(gè)采樣數(shù)據(jù)占3.5 bytes左右,300萬(wàn)的時(shí)間序列,30s間隔,保留60天,消耗磁盤(pán)大概200G。

9)做高可用,可以對(duì)數(shù)據(jù)做異地備份,聯(lián)邦集群,部署多套prometheus,pushgateway上報(bào)數(shù)據(jù)

2.2、什么是樣本

樣本:在時(shí)間序列中的每一個(gè)點(diǎn)稱(chēng)為一個(gè)樣本(sample),樣本由以下三部分組成:

  • 指標(biāo)(metric):指標(biāo)名稱(chēng)和描述當(dāng)前樣本特征的 labelsets;
  • 時(shí)間戳(timestamp):一個(gè)精確到毫秒的時(shí)間戳;
  • 樣本值(value): 一個(gè) folat64 的浮點(diǎn)型數(shù)據(jù)表示當(dāng)前樣本的值。

表示方式:通過(guò)如下表達(dá)方式表示指定指標(biāo)名稱(chēng)和指定標(biāo)簽集合的時(shí)間序列:<metric name>{<label name>=<label value>, ...}

例如,指標(biāo)名稱(chēng)為 api_http_requests_total,標(biāo)簽為 method="POST" 和 handler="/messages" 的時(shí)間序列可以表示為:api_http_requests_total{method="POST", handler="/messages"}

prometheus安裝和使用記錄

Getting started | Prometheus

Configuration | Prometheus

Download | Prometheus

Download Grafana | Grafana Labs

# prometheus
mkdir -m=777 -p /data/{download,app_logs,app/prometheus}
cd /data/download
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0-rc.0/prometheus-2.45.0-rc.0.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
ln -s /data/download/prometheus-2.45.0-rc.0.linux-amd64/prometheus /usr/bin/prometheus
cp /data/download/prometheus-2.45.0-rc.0.linux-amd64/prometheus.yml /data/app/prometheus/prometheus.yml 
prometheus --config.file=/data/app/prometheus/prometheus.yml --web.listen-address=:9090 --web.enable-lifecycle --storage.tsdb.path=/data/app/prometheus/data >>/data/app_logs/prometheus.log 2>&1 &
# node_exporter 在需要監(jiān)控的服務(wù)器里安裝
mkdir -m=777 -p /data/{download,app_logs,app/prometheus}
cd /data/download
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz
tar xvfz node_exporter*
ln -s /data/download/node_exporter-1.6.0.linux-amd64/node_exporter /usr/bin/node_exporter
# 啟動(dòng)node_exporter,服務(wù)器暴露的端口是8080,同時(shí)服務(wù)器里有其他服務(wù)占用了8080端口,可以使用nginx將node_exporter獲取指標(biāo)的api暴露出去
# location /metrics {
#     proxy_pass http://127.0.0.1:9000/metrics;
# }
node_exporter --web.listen-address 127.0.0.1:9000 >>/data/app_logs/node_exporter.log 2>&1 &
# 添加node_exporter之后,需要更新prometheus.xml添加targets,然后運(yùn)行:curl -X PUT http://server_address:port/-/reload重新加載配置文件
# alert_manager可以和prometheus安裝到同一臺(tái)服務(wù)器
cd /data/download
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-amd64.tar.gz
tar xvfz alertmanager*
ln -s /data/download/alertmanager-0.25.0.linux-amd64/alertmanager /usr/bin/alertmanager
cp /data/download/alertmanager-0.25.0.linux-amd64/alertmanager.yml /data/app/prometheus/alertmanager.yml
alertmanager --config.file=/data/app/prometheus/alertmanager.yml --web.listen-address 127.0.0.1:9001 >>/data/app_logs/node_exporter.log 2>&1 &
# 將alert_manager的地址添加到prometheus.yml里的alertmanagers的targets里,然后運(yùn)行:curl -X PUT http://server_address:port/-/reload重新加載配置文件

測(cè)試報(bào)警郵件功能:設(shè)置如果安裝exporter的服務(wù)器內(nèi)存占用率超過(guò)50%或者tcp timewait超過(guò)10的時(shí)候就發(fā)郵件(在實(shí)際工作中需要設(shè)置一個(gè)合適的條件):

prometheus.yml里添加rule_files的路徑:

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          - 127.0.0.1:9001
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
  - "/data/app/prometheus/alert.rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    scrape_interval: 5s
    static_configs:
            - targets: ["node1_ip:8080"]
            - targets: ["node2_ip:8080"]
              labels:
                groups: 'container'

alert.rules.yml里添加具體的rule,node_socket_TCP_tw這些具體的指標(biāo)通過(guò)http://node_exporter_ip:port/metrics可以獲取到

groups:
- name: tcp-alert-group
  rules:
  - alert: TcpTimeWait
    expr: node_sockstat_TCP_tw > 10
    for: 10m
    labels:
      severity: warning
    annotations:
      summary: tcp time wait more than 10
      description: please check node_sockstat_TCP_tw metric
  - alert: MemoryUse
    expr: (node_memory_MemTotal_bytes-node_memory_MemFree_bytes-node_memory_Buffers_bytes-node_memory_Cached_bytes)/node_memory_MemTotal_bytes > 0.5
    for: 10m
    labels:
      severity: warning
    annotations:
      summary: memory use more than 50% for 10 min
      description: please check memory use

alertmanager.yml里配置告警郵件的信息:

global:
  resolve_timeout: 5m
  smtp_smarthost: your_smpt_host:port
  smtp_from: alertmanager@your_email_domain
  smtp_require_tls: false
route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 10m
  receiver: 'email'
receivers:
  - name: 'email'
    email_configs:
    - to: 'receiver_email'
      send_resolved: true

yml文件一旦更新,需要重新加載配置:curl -X PUT http://server_address:port/-/reload

在Prometheus的界面可以看到添加的alert:

 當(dāng)alert的條件滿(mǎn)足后,alertmanager就會(huì)發(fā)郵件

grafana的安裝和啟動(dòng):

# grafana可以和prometheus里安裝到同一臺(tái)服務(wù)器
yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-10.0.0-1.x86_64.rpm
# grafana默認(rèn)啟動(dòng)的端口號(hào)是3000,如果服務(wù)器沒(méi)有暴露3000端口的話(huà),需要修改grafana的配置文件
sed -i 's/3000/8080/g' /usr/share/grafana/conf/defaults.ini
grafana server >> /data/app_logs/grafana.log 2>&1 &
# grafana數(shù)據(jù)保存地址:/var/lib/grafana.db

grafana啟動(dòng)之后就可以在瀏覽器上打開(kāi)對(duì)應(yīng)的地址,初次登錄用戶(hù)名和密碼:admin/admin

Data sources里添加prometheus,grafana和prometheus啟動(dòng)在同一臺(tái)服務(wù)器里的話(huà),地址就可以用localhost

 添加dashboard,在Explore里可以查詢(xún)指標(biāo)并且添加到dashboard

cpu使用率:avg(1-irate(node_cpu_seconds_total{mode="idle"}[1m])) by(instance)

內(nèi)存使用率:(node_memory_MemTotal_bytes-node_memory_MemFree_bytes-node_memory_Buffers_bytes-node_memory_Cached_bytes)/node_memory_MemTotal_bytes

tcp連接數(shù):node_sockstat_TCP_alloc

 dashboard:

注意點(diǎn):

1.prometheus啟動(dòng)的時(shí)候添加--web.enable-lifecycle才允許通過(guò)調(diào)用/-/reload接口重新加載配置文件
2.prometheus啟動(dòng)的時(shí)候指定一個(gè)固定的數(shù)據(jù)存放位置--storage.tsdb.path=/data/app/prometheus/data,如果數(shù)據(jù)存放位置不一致,啟動(dòng)后查不到歷史數(shù)據(jù),歷史數(shù)據(jù)做備份的話(huà),prometheus啟動(dòng)的服務(wù)器還可以變更
3.grafana的數(shù)據(jù)保存地址:/var/lib/grafana.db,定期做備份,服務(wù)器發(fā)生系統(tǒng)錯(cuò)誤無(wú)法使用的時(shí)候,在新的服務(wù)器里同步/var/lib/grafana.db文件之后,啟動(dòng)grafana之前的配置不會(huì)丟失

到此這篇關(guān)于prometheus安裝和使用過(guò)程的文章就介紹到這了,更多相關(guān)prometheus安裝內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論