溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

初玩prometheus

發(fā)布時間:2020-07-19 11:45:14 來源:網(wǎng)絡(luò) 閱讀:300 作者:鐵血軍人 欄目:系統(tǒng)運維

初玩prometheus

安裝Prometheus Server

因為Prometheus是基于GoLang編寫,編譯后的軟件包,不依賴于任何的第三方依賴。用戶只需要下載對應(yīng)平臺的二進制包,并解壓添加基本配置即可正常啟動Prometheus server。

二進制安裝部署

下載頁面:https://prometheus.io/download/
我們選擇對應(yīng)的下載版本,這里我們下載的是最新版本2.13.0 linux版本,下載地址為:https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz

我們在服務(wù)器上安裝部署:

[root@Prometheus ~]# mkdir /usr/local/prometheus
[root@Prometheus ~]# cd /usr/local/prometheus
[root@Prometheus prometheus]# wget  https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz
[root@Prometheus prometheus]# tar xvf prometheus-2.13.0.linux-amd64.tar.gz
prometheus-2.13.0.linux-amd64/
prometheus-2.13.0.linux-amd64/NOTICE
prometheus-2.13.0.linux-amd64/promtool
prometheus-2.13.0.linux-amd64/consoles/
prometheus-2.13.0.linux-amd64/consoles/prometheus.html
prometheus-2.13.0.linux-amd64/consoles/node-overview.html
prometheus-2.13.0.linux-amd64/consoles/node-cpu.html
prometheus-2.13.0.linux-amd64/consoles/node.html
prometheus-2.13.0.linux-amd64/consoles/index.html.example
prometheus-2.13.0.linux-amd64/consoles/prometheus-overview.html
prometheus-2.13.0.linux-amd64/consoles/node-disk.html
prometheus-2.13.0.linux-amd64/LICENSE
prometheus-2.13.0.linux-amd64/console_libraries/
prometheus-2.13.0.linux-amd64/console_libraries/prom.lib
prometheus-2.13.0.linux-amd64/console_libraries/menu.lib
prometheus-2.13.0.linux-amd64/tsdb
prometheus-2.13.0.linux-amd64/prometheus.yml
prometheus-2.13.0.linux-amd64/prometheus

解壓后同級目錄里面會看到prometheus.yml配置文件

# my global config
global:
  scrape_interval:     15s #抓去采樣數(shù)據(jù)的時間間隔,默認15s去被監(jiān)控主機上采取一次
  evaluation_interval: 15s # 每15秒評估一次規(guī)則。 默認值為每1分鐘。 監(jiān)控數(shù)據(jù)規(guī)則的評估頻率(當(dāng)我們設(shè)置硬盤> 80%報警 這條rule規(guī)則 那個prometheus會默認沒15S來執(zhí)行這個rule規(guī)則檢查硬盤使用情況)
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration(如何報警,報警信息)
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.()
rule_files:
  # - "first_rules.yml"
  # - "second_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'.

    static_configs:
    - targets: ['localhost:9090'] #靜態(tài)配置的監(jiān)控主機

啟動prometheus

[root@Prometheus prometheus-2.13.0.linux-amd64]# ./prometheus --config.file=prometheus.yml
level=info ts=2019-10-11T01:53:36.252Z caller=main.go:296 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-10-11T01:53:36.252Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.0, branch=HEAD, revision=6ea4252299f542669aca11860abc2192bdc7bede)"
level=info ts=2019-10-11T01:53:36.252Z caller=main.go:333 build_context="(go=go1.13.1, user=root@f30bdad2c3fd, date=20191004-11:25:34)"
level=info ts=2019-10-11T01:53:36.252Z caller=main.go:334 host_details="(Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 Prometheus (none))"
level=info ts=2019-10-11T01:53:36.252Z caller=main.go:335 fd_limits="(soft=1024, hard=4096)"
level=info ts=2019-10-11T01:53:36.252Z caller=main.go:336 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-10-11T01:53:36.254Z caller=main.go:657 msg="Starting TSDB ..."
level=info ts=2019-10-11T01:53:36.256Z caller=web.go:450 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-10-11T01:53:36.258Z caller=head.go:512 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2019-10-11T01:53:36.265Z caller=head.go:560 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1
level=info ts=2019-10-11T01:53:36.265Z caller=head.go:560 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1
level=info ts=2019-10-11T01:53:36.267Z caller=main.go:672 fs_type=XFS_SUPER_MAGIC
level=info ts=2019-10-11T01:53:36.267Z caller=main.go:673 msg="TSDB started"
level=info ts=2019-10-11T01:53:36.267Z caller=main.go:743 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2019-10-11T01:53:36.285Z caller=main.go:771 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2019-10-11T01:53:36.285Z caller=main.go:626 msg="Server is ready to receive web requests."

我們直接指定配置文件之后就啟動起來了,但是在實際工作中我門不會這樣啟動,還會加上如下一些配置參數(shù)

--config.file="/usr/local/prometheus/prometheus.yml"   #啟動的配置文件
--web.listen-address="0.0.0.0:9090"                #監(jiān)聽的地址端口
--web.max-connections=512                          #最大連接數(shù)       
--storage.tsdb.path="data/"                        #本地存儲的位置
--storage.tsdb.retention=15d                       #數(shù)據(jù)在本地存儲的時間
--storage.tsdb.no-lockfile                        #不允許在數(shù)據(jù)目錄里面創(chuàng)建鎖文件
--query.timeout=2m                                 #查詢超時時間
--query.max-concurrency=20                         #同時查詢的并發(fā)數(shù)

所以在生產(chǎn)中我們一般這樣啟動prometheus

nohup prometheus --config.file="/usr/local/prometheus/prometheus.yml" --web.listen-address="0.0.0.0:9090" --web.max-connections=512 --storage.tsdb.path="data/" --storage.tsdb.retention=15d --query.timeout=2m --query.max-concurrency=20 &

Docker 安裝部署

在當(dāng)前docker這么方便的情況下,我們肯定要來介紹下通過docker是如何來安裝部署prometheus;

mkdir /usr/local/prometheus/data
chmod 777 /usr/local/prometheus/data
docker run  -id --name prometheus -p 9090:9090 -v /etc/localtime:/etc/localtime:ro  -v /usr/local/prometheus/data:/prometheus_data  -v /usr/local/prometheus/prometheus-2.13.0.linux-amd64/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.listen-address=0.0.0.0:9090 --web.max-connections=512 --storage.tsdb.path=/prometheus_data --storage.tsdb.retention=15d --query.timeout=2m --query.max-concurrency=20

這里講訴一個技巧,當(dāng)我第一次啟動prometheus指定啟動的參數(shù)的時候一致啟動不起來報 找不到指定的配置文件, 我們直接啟動的時候他都是能啟動的了的,為什么我加上其余的參數(shù)之后,就提示這個呢?百思不得其解,知道我看了prometheus鏡像的dockerfile的時候,我瞬間明白是為什么了,Prometheus_Dockerfile地址

ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
LABEL maintainer="The Prometheus Authors <prometheus-developers@googlegroups.com>"

ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/prometheus        /bin/prometheus
COPY .build/${OS}-${ARCH}/promtool          /bin/promtool
COPY documentation/examples/prometheus.yml  /etc/prometheus/prometheus.yml
COPY console_libraries/                     /usr/share/prometheus/console_libraries/
COPY consoles/                              /usr/share/prometheus/consoles/

RUN ln -s /usr/share/prometheus/console_libraries /usr/share/prometheus/consoles/ /etc/prometheus/
RUN mkdir -p /prometheus && \
    chown -R nobody:nogroup etc/prometheus /prometheus

USER       nobody
EXPOSE     9090
VOLUME     [ "/prometheus" ]
WORKDIR    /prometheus
ENTRYPOINT [ "/bin/prometheus" ]
CMD        [ "--config.file=/etc/prometheus/prometheus.yml", \
             "--storage.tsdb.path=/prometheus", \
             "--web.console.libraries=/usr/share/prometheus/console_libraries", \
             "--web.console.templates=/usr/share/prometheus/consoles" ]

看到這個dockerfile 前面的我們現(xiàn)在可以不關(guān)心他,主要的就是在最后一行CMD,原來是我們在追加參數(shù)的時候把CMD的參數(shù)給覆蓋掉了,所以找不到配置文件的路徑,我們這個時候再給他加上就OK了。

介紹prometheus web界面

不管我們通過哪種方式來啟動的prometheus service端,我們都通過如下的方式登陸prometheus dashboard界面,登陸方式為http://IP:9090
初玩prometheus

初玩prometheus

初玩prometheus

初玩prometheus

初玩prometheus

初玩prometheus

初玩prometheus

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI