Prometheus官方下載
Prometheus開始安裝
Prometheus啟動運行
Prometheus基本配置文件講解
安裝exporter=node_exporter
Prometheus鏈接exporter獲取數(shù)據(jù)
Prometheus命令行入門第一個數(shù)學查詢公式
安裝Prometheus之前 我們必須先安裝ntp時間同步
(Prometheus T_S對系統(tǒng)時間的準確性要求很高护戳,必須保證本機實時同步)
timedatectl set-timezone Asia/Shanghai
* * * * * ntpdate -u cn.pool.ntp.org
1)Prometheus下載
首先我們?nèi)サ絟ttps://prometheus.io官網(wǎng)
下載最新版本prometheus-2.12.0.linux-amd64.tar.gz
wget https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz
2)Prometheus的安裝非常簡單
tar -zcf prometheus-2.12.0.linux-amd64.tar.gz
cp -rf prometheus-2.12.0.linux-amd64 /usr/local/prometheus
3)Prometheus啟動和后臺運行
啟動命令
./prometheus
prometheus無法將自己放在后臺 可以使用screen -ls 放在后臺
prometheus解壓安裝之后伪节,就默認自帶了一個基本的配置文件如下
./prometheus --yml
4)prometheus配置文件
global:
scrape_interval: 15s #默認采集時間間隔
scrape_timeout: 10s
evaluation_interval: 15s #監(jiān)控數(shù)據(jù)規(guī)則的評估頻率
alerting:
alertmanagers:
-static_configs:
- targets:[]
scheme: http
timeout: 10s
scrape_configs: #抓取數(shù)據(jù)的配置
- job_name: prometheus #任務名稱
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets: ['server04:9100','IP:9100','nginx01:9100','web1:9100','redis1:9100']
# - localhost:9090 #定義監(jiān)控的客戶端
定義監(jiān)控的客戶端必須在/etc/hosts,local_dns server 做解析
用逗號隔開,機器名+端口號
端口號:通常用的就是exporters的端口
9100是node_exporter的默認端口
如此prometheus就可以通過配置文件識別監(jiān)控的節(jié)點涮较,持續(xù)開始采集數(shù)據(jù)prometheus到此就算初步的搭建好了
5)搭建好Prometheus_server是不夠的齐饮,我們需要給監(jiān)控系欸但搭建第一個exporter用來采樣數(shù)據(jù)
企業(yè)中最常用的node_exporter插件
node_exporter是以http_server方式運行在后臺落午,并且持續(xù)不斷采集Linux系統(tǒng)中各種才做系統(tǒng)本身相關(guān)的監(jiān)控參數(shù)的程序
采集量很大很全的店茶,往往默認的采集項目遠超過實際需求
先下載node_exporter從官網(wǎng)
https://prometheus.io/download/#node_exporter
下載之后解壓縮然后直接運行即可
./node_exporter
node_exporter的運行更加簡單如上圖所示
運行起來以后我們使用netstats -tnlp 可以看下node_exporter進程的狀態(tài)
這里就可以看出來node_exporter默認工作在9100端口
可以響應prometheus_server發(fā)過來的 HTTP_GET請求
我們自己就可以發(fā)送測試
可以返回一大堆k/v的數(shù)據(jù)
然后復制Key的名稱就可以直接復制粘貼在prometheus的查詢命令行來查看結(jié)果了
復制node_memory_MemFree 空閑內(nèi)存
cpu使用率的計算公式 node_cpu
(1-((sum(increase(node_cpu{mode="idle"}[1m])) by (instance)) /
(sum(increase(node_cpu[1m])) by (instance)))) * 100