掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
Prometheus是一款開(kāi)源的監(jiān)控系統(tǒng),主要用于收集、存儲(chǔ)和查詢時(shí)間序列數(shù)據(jù),以便于對(duì)系統(tǒng)進(jìn)行監(jiān)控和分析。

在豐澤等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作定制開(kāi)發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),全網(wǎng)營(yíng)銷(xiāo)推廣,外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè),豐澤網(wǎng)站建設(shè)費(fèi)用合理。
Prometheus的架構(gòu)由四個(gè)主要組件組成:
同時(shí)Prometheus有以下優(yōu)點(diǎn):
下面就Prometheus基于本地環(huán)境進(jìn)行監(jiān)控報(bào)警進(jìn)行講解。
docker pull prom/prometheus:v2.43.0
創(chuàng)建文件夾data
創(chuàng)建配置文件prometheus.yml,可以根據(jù)需要進(jìn)行調(diào)整:
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# 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=` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090'] 因?yàn)槁窂竭^(guò)長(zhǎng),創(chuàng)建軟鏈目錄/data/prometheus:
ln -s /Users/weizhao.dong/Documents/soft/prometheus /data/prometheus
docker run --name prometheus -d -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/prometheus:/prometheus prom/prometheus:v2.43.0
docker pull grafana/grafana-enterprise:8.5.22
docker run -d --name=grafana -p 3000:3000 grafana/grafana-enterprise:8.5.22
添加prometheus數(shù)據(jù)源:
選擇指定版本,并下載:
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-arm64.tar.gz下載解壓執(zhí)行node_exporter文件暴漏9100端口,即可采集到監(jiān)控信息
由于直接啟動(dòng)node-exporter關(guān)閉窗口此進(jìn)程就會(huì)掛掉,不能滿足需求,因此可以采用systemctl方式進(jìn)行配置。
(1) 在/usr/lib/systemd/system/目錄,創(chuàng)建node_exporter.service文件,內(nèi)容如下,ExecStart指向的就是node_exporter執(zhí)行文件:;
[Unit]
Description=Node Exporter
[Service]
ExecStart=/usr/local/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target(2) 執(zhí)行systemctl daemon-reload
(3) 執(zhí)行systemctl start node_exporter啟動(dòng)node_exporter
(4) 執(zhí)行netstat -aon|grep 9100查看9100是否啟動(dòng)成功
增加以下任務(wù),5s采集一次,這種方式屬于Promethues的Pull 模式,即主動(dòng)發(fā)起請(qǐng)求拉取目標(biāo)數(shù)據(jù):
- job_name: 'linux'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['10.211.55.4:9100']
docker restart prometheus
訪問(wèn)https://grafana.com/grafana/dashboards/,下載node_export配置文件:
點(diǎn)擊右邊的DownloadJson文件進(jìn)行下載:
將下載文件導(dǎo)入到Grafana:
導(dǎo)入完成以后,可以看到相關(guān)數(shù)據(jù)已采集。
在本文中,我們介紹了什么是Prometheus,如何安裝Prometheus,以及使用Prometheus的Pull(拉取)模式來(lái)采集Linux服務(wù)器資源,并在Grafana進(jìn)行展現(xiàn)。

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流