簡介
Prometheus基於Golang編寫,編譯後的軟件包,不依賴於任何的第三方依賴。只需要下載對應平臺的二進制包,解壓並且添加基本的配置即可正常啓動Prometheus Server
Prometheus安裝
Prometheus官網下載對應軟件包
https://prometheus.io/download/
下載對應平臺的軟件包到服務器
以2.11.1版本,Linux服務器爲例
#下載軟件包
wget https://github.com/prometheus/prometheus/releases/download/v2.11.1/prometheus-2.11.1.linux-amd64.tar.gz
#解壓軟件包
tar -zxvf prometheus-2.11.1.linux-amd64.tar.gz
可以將軟件包移動到服務器存放軟件的目錄,並進入目錄
mv prometheus-2.11.1.linux-amd64 /usr/local/prometheus
cd /usr/local/prometheus
默認配置爲9090端口,可以通過修改prometheus.yml文件,修改配置
vim prometheus.yml
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'.
static_configs:
#可以修改頁面訪問端口
- targets: ['localhost:9090']
配置完畢後,需要檢查防火牆是否將使用到的端口開啓
啓動項目
#在軟件目錄下執行以下命令啓動
./prometheus
執行後會顯示以下內容
level=info ts=2019-08-06T03:01:47.150Z caller=main.go:293 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-08-06T03:01:47.150Z caller=main.go:329 msg="Starting Prometheus" version="(version=2.11.1, branch=HEAD, revision=e5b22494857deca4b806f74f6e3a6ee30c251763)"
level=info ts=2019-08-06T03:01:47.150Z caller=main.go:330 build_context="(go=go1.12.7, user=root@d94406f2bb6f, date=20190710-13:51:17)"
level=info ts=2019-08-06T03:01:47.150Z caller=main.go:331 host_details="(Linux 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 iZj6cd3n7n9equeptskuy9Z (none))"
level=info ts=2019-08-06T03:01:47.150Z caller=main.go:332 fd_limits="(soft=65535, hard=65535)"
level=info ts=2019-08-06T03:01:47.150Z caller=main.go:333 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-08-06T03:01:47.151Z caller=main.go:652 msg="Starting TSDB ..."
level=info ts=2019-08-06T03:01:47.151Z caller=web.go:448 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-08-06T03:01:47.161Z caller=main.go:667 fs_type=EXT4_SUPER_MAGIC
level=info ts=2019-08-06T03:01:47.161Z caller=main.go:668 msg="TSDB started"
level=info ts=2019-08-06T03:01:47.161Z caller=main.go:738 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2019-08-06T03:01:47.162Z caller=main.go:766 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2019-08-06T03:01:47.162Z caller=main.go:621 msg="Server is ready to receive web requests."
訪問 http://服務器ip:9090 即可使用
可以通過守護進程運行,讓程序在後臺運行
nohup ./prometheus &
node_exporter 簡介
node_exporter用來安裝到被監控的主機上,服務器端通過調用默認端口9100 來獲取服務器信息
node_exporter 安裝
Prometheus官網下載對應軟件包
https://prometheus.io/download/
下載對應平臺的軟件包到服務器
下載並解壓文件
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz
將文件移動到軟件安裝目錄
mv node_exporter-0.18.1.linux-amd64.tar.gz /usr/local/node_exporter
cd /usr/local/node_exporter
啓動
#在軟件目錄執行
./node_exporter
#也可以通過守護進程執行
nohup ./node_exporter &
啓動後 可以通過 http://服務器ip:9100 查看到服務器信息
Prometheus 獲取node_exporter信息
通過配置Prometheus下的Prometheus.yml文件 獲取node_exporter信息
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'.
static_configs:
#可以修改頁面訪問端口
- targets: ['localhost:9090']
#添加節點
- job_name: 'node1'
static_configs:
- targets: ['0.0.0.0:9100']
- job_name: 'node2'
static_configs:
- targets: ['0.0.0.0:9100']
通過添加節點 可以在Prometheus服務端獲取到節點信息