(一)、概述
一、什麼是prometheus
Prometheus是由SoundCloud開發的開源監控報警系統和時序列數據庫(TSDB)。Prometheus使用Go語言開發,是Google BorgMon監控系統的開源版本。
2016年由Google發起Linux基金會旗下的原生雲基金會(Cloud Native Computing Foundation), 將Prometheus歸入其下第二大開源項目。
Prometheus目前在開源社區至關活躍。
Prometheus和Heapster(Heapster是K8S的一個子項目,用於獲取集羣的性能數據。)相比功能更完善、更全面。Prometheus性能也足夠支撐上萬臺規模的集羣。
二、Prometheus的特色node
(二)、安裝配置
1、Prometheust Server端安裝和相關配置
1.一、二進制包安裝python
1.一、官網地址https://prometheus.io/download/ 1.二、下載和安裝 wget https://github.com/prometheus/prometheus/releases/download/v2.22.0-rc.0/prometheus-2.22.0-rc.0.linux-386.tar.gz tar xf prometheus-2.22.0-rc.0.linux-386.tar.gz mv prometheus-2.22.0-rc.0.linux-386/prometheus /usr/local/prometheus 1.三、配置系統啓動文件 cat /etc/systemd/system/prometheus.service [Unit] Description=Prometheus Server After=network.target Documentation=https://prometheus.io/docs/introduction/overview/ [Service] Type=simple WorkingDirectory=/data/prometheus/ ExecStart=/usr/local/prometheus/prometheus \ --config.file=/etc/prometheus/prometheus.yml \ --web.read-timeout=5m \ --web.max-connections=512 \ --storage.tsdb.retention=15d \ --storage.tsdb.path=/data/prometheus \ --query.timeout=2m Restart=on-failure [Install] WantedBy=multi-user.target 1.四、把配置文件轉移到標準目錄/etc/prometheus/ mkdir -p /etc/prometheus/ cp /usr/local/prometheus/prometheus.yml /etc/prometheus/ cat /etc/prometheus/prometheus.yml global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: rule_files: scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] 1.四、啓動 systemctl daemon-reload systemctl start prometheus systemctl enable prometheus systemctl status prometheus 1.五、查看經過 ip:9090進行查看。二進制安裝很是方便,沒有依賴,自動查詢的web界面。配置了9090端口,默認prometheus會抓取本身的/metrics接口
1.二、docker安裝linux
一、安裝 docker run \ -p 9090:9090 \ -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \ prom/prometheus 二、查看prometheus服務和狀態 docker start prometheus docker stop prometheus docker stats prometheus
2、安裝node_exporter提供metricsgit
一、下載、解壓和移動 wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz tar xf node_exporter-1.0.1.linux-amd64.tar.gz mv node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/prometheus/ 二、配置啓動文件 cat /etc/systemd/system/node_export.service [Unit] Description=Node Export After=network.target Documentation=https://prometheus.io/docs/guides/node-exporter/ [Service] Type=simple WorkingDirectory=/tmp/ ExecStart=/usr/local/prometheus/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target 三、自啓動 [root@ES-Master2 opt]# systemctl start node_export [root@ES-Master2 opt]# systemctl enable node_export Created symlink from /etc/systemd/system/multi-user.target.wants/node_export.service to /etc/systemd/system/node_export.service. [root@ES-Master2 opt]# systemctl status node_export 四、加入監控 手動加入 prometheus 監控,修改其配置文件,再尾部增長以下內容: - job_name: elasticsearch scrape_interval: 60s scrape_timeout: 30s metrics_path: "/metrics" static_configs: - targets: [172.20.3.201:9100] labels: service: elasticsearch 而後從新載入配置curl -X POST http://localhost:9090/-/reload
五、查看生效的接口github
六、docker安裝更簡單web
docker run -d \ --net="host" \ --pid="host" \ -v "/:/host:ro,rslave" \ quay.io/prometheus/node-exporter \ --path.rootfs=/host
3、安裝grafana進行展現
Grafana是用於可視化大型測量數據的開源程序,它提供了強大和優雅的方式去建立、共享、瀏覽數據。
Dashboard中顯示了你不一樣metric數據源中的數據。
Grafana最經常使用於因特網基礎設施和應用分析,但在其餘領域也有用到,好比:工業傳感器、家庭自動化、過程控制等等。
Grafana支持熱插拔控制面板和可擴展的數據源,目前已經支持Graphite、InfluxDB、OpenTSDB、Elasticsearch、Prometheus等。docker
一、下載地址 https://grafana.com/grafana/download 二、Red Hat, CentOS, RHEL, and Fedora(64 Bit) wget https://dl.grafana.com/oss/release/grafana-7.2.1-1.x86_64.rpm sudo yum install grafana-7.2.1-1.x86_64.rpm -y 三、自啓動 systemctl enable grafana-server systemctl start grafana-server 四、訪問ip:3000端口,默認帳號和密碼都是admin:admin