Prometheus監控安裝及使用(一)

原理就很少說了,直接上操做過程吧node

Prometheus Push Gateway 參考: https://github.com/prometheus/pushgatewaymysql

Prometheus Server 參考: https://github.com/prometheus/prometheus#installlinux

Grafana 參考: http://docs.grafana.orggit

 

 

安裝github

wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gzweb

 

tar -zxvf prometheus-2.8.1.linux-amd64.tar.gz -C /usr/local/sql

cd /usr/localjson

mv prometheus-2.8.1.linux-amd64/ prometheusvim

cd prometheus/centos

 ./prometheus --version

 

修改prometheus.yml文件,肯定啓動ip

 

修改prometheus.yml文件,肯定啓動ip

完成修改後,能夠直接啓動

./prometheus

 

# 添加用戶,後期用此帳號啓動服務

[root@localhost prometheus]# groupadd prometheus

[root@localhost prometheus]# useradd -g prometheus -s /sbin/nologin prometheus

# 賦權和建立prometheus運行數據目錄

[root@localhost prometheus]# cd ~

[root@localhost ~]# chown -R prometheus:prometheus /usr/local/prometheus/

[root@localhost ~]# mkdir -p /home/software/prometheus-data

[root@localhost ~]# chown -R prometheus:prometheus /home/software/prometheus-data

 

設置開機啓動

[root@localhost ~]# touch /usr/lib/systemd/system/prometheus.service

[root@localhost ~]# chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service

[root@localhost ~]# vim /usr/lib/systemd/system/prometheus.service

[Unit]

Description=Prometheus

Documentation=https://prometheus.io/

After=network.target

 

[Service]

# Type設置爲notify時,服務會不斷重啓

Type=simple

User=prometheus

# --storage.tsdb.path是可選項,默認數據目錄在運行目錄的./dada目錄中

ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/home/software/prometheus-data

Restart=on-failure

 

[Install]

WantedBy=multi-user.target

 

修改配置文件設置開機啓動

再次修改配置文件

vim prometheus.yml

# my global config

global:

  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

  # 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'.

    scrape_interval: 5s

 

    static_configs:

      - targets: ['192.168.33.134:9090']

        labels:

          instance: prometheus

 

  - job_name: 'centos7-machine1'

    scrape_interval: 10s

    static_configs:

      - targets: ['192.168.33.131:9100']

        labels:

          instance: node1

 

  - job_name: 'centos7-machine2'

    scrape_interval: 10s

    static_configs:

      - targets: ['192.168.33.132:9100']

        labels:

          instance: node2

 

  - job_name: 'centos7-machine3'

    scrape_interval: 10s

    static_configs:

      - targets: ['192.168.33.132:9100']

        labels:

          instance: node3

 

  - job_name: 'centos7-machine4'

    scrape_interval: 10s

    static_configs:

      - targets: ['192.168.33.134:9100']

        labels:

          instance: node4

  - job_name: 'win2012-machine5'

    scrape_interval: 10s

    static_configs:

      - targets: ['192.168.33.135:9182']

        labels:

          instance: node5

[root@prometheus ~]# systemctl enable prometheus

[root@prometheus ~]# systemctl start prometheus

設置iptables或者firewalld(測試環境能夠直接關閉)

 

 

啓動並驗證

1)查看服務狀態

[root@prometheus ~]# systemctl status prometheus

 

 

2web ui

Prometheus自帶有簡單的UI

 

 

Status菜單下,ConfigurationRuleTargets等,

Statu-->Configuration展現prometheus.yml的配置,以下

Statu-->Targets展現監控具體的監控目標

centos尚未監控到,一會安裝插件

繪圖

訪問http://192.168.33.134:9090/metrics  查看從exporter具體能抓到的數據,以下

三.部署node_exporter

Node_exporter收集機器的系統數據,這裏採用prometheus官方提供的exporter,除node_exporter外,官方還提供consulmemcachedhaproxymysqldexporter,具體可查看官網。

 

這裏在prometheus服務和 node節點部署相關服務。

tar -zxvf node_exporter-0.17.0-rc.0.linux-amd64.tar.gz -C /usr/local/

cd /usr/local/

mv node_exporter-0.17.0-rc.0.linux-amd64 node_exporter

設置用戶(節點)

groupadd prometheus

useradd -g prometheus -s /sbin/nologin prometheus

chown -R prometheus:prometheus /usr/local/node_exporter

 

[root@node1 ~]# vim /usr/lib/systemd/system/node_exporter.service

[Unit]

Description=node_exporter

Documentation=https://prometheus.io/

After=network.target

[Service]

Type=simple

User=prometheus

ExecStart=/usr/local/node_exporter/node_exporter

Restart=on-failure

[Install]

WantedBy=multi-user.target

 

[root@node1 ~]# systemctl enable node_exporter

[root@node1 ~]# systemctl start node_exporter

grafana安裝

wget https://dl.grafana.com/oss/release/grafana-6.1.3-1.x86_64.rpm 

 

yum -y localinstall grafana-6.1.3-1.x86_64.rpm

 

配置文件

配置文件位於/etc/grafana/grafana.ini,這裏暫時保持默認配置便可

設置開機啓動

systemctl enable grafana-server

systemctl start grafana-server

防火牆管理(測試環境直接關閉)

 

添加數據

訪問:http://192.168.33.134:3000,默認帳號/密碼:admin/admin

默認登陸後,要求改密碼,能夠選擇先跳過

 

添加數據源

在登錄首頁,點擊"Add data source"按鈕,跳轉到添加數據源頁面,配置以下:

Name: prometheus

Type: prometheus

URL: http://localhost:9090/

Access: proxy

取消Default的勾選,其他默認,點擊"Add",以下:

"Dashboards"頁簽下"import"自帶的模版,以下:

發現是空的

 

導入dashboard

grafana官網下載相關dashboaed到本地,如:https://grafana.com/dashboards/405

Grafana首頁-->左上角圖標-->Dashboard-->import

加入1-node-exporter-0-16-0-17-for-prometheus_rev7.json這個插件

若是出現grafana-piechart-panel這個報錯

1.安裝pie插件

官網:https://grafana.net/plugins/grafana-piechart-panel  

grafana-cli plugins install grafana-piechart-panel

2.重啓grafana-server

便可恢復,效果以下

如今監控正常了,咱們開始把服務加入這個項目中,如今各個節點安裝node_exporter-0.17.0-rc.0.linux-amd64.tar.gz

 部署

[root@node1 src]# tar -zxvf node_exporter-0.17.0-rc.0.linux-amd64.tar.gz -C /usr/local/

[root@node1 src]# cd /usr/local/

[root@node1 local]# mv node_exporter-0.17.0-rc.0.linux-amd64/ node_exporter/

 

2. 設置用戶

groupadd prometheus

useradd -g prometheus -s /sbin/nologin prometheus

chown -R prometheus:prometheus /usr/local/node_exporter/

3. 設置開機啓動

 

[root@node1 ~]# vim /usr/lib/systemd/system/node_exporter.service

[Unit]

Description=node_exporter

Documentation=https://prometheus.io/

After=network.target

[Service]

Type=simple

User=prometheus

ExecStart=/usr/local/node_exporter/node_exporter

Restart=on-failure

[Install]

WantedBy=multi-user.target

 

[root@node1 ~]# systemctl enable node_exporter

[root@node1 ~]# systemctl start node_exporter

 

監控win主機

安裝wmi_exporter-0.3.3-amd64.msi

https://github.com/martinlindhe/wmi_exporter/releases/download/v0.3.3/wmi_exporter-0.3.3-amd64.msi

下載後,安裝插件

訪問http://ip:9182/metrics後,如圖

說明安裝成功

 

 

 

 

telegram報警設置

telegram@BotFather,並加爲好友,而後,建立你的機器人

填入紅色塗鴉的地方

https://api.telegram.org/bot{$token}/getUpdates

token換成你本身剛剛註冊到的那個紅色標註的字符串

 

後鏈接 變成爲https://api.telegram.org/bot690994839:AAGejCWBwy4gKun9B6q7-Il2uooz0OYXlOU/getMe

返回以下則成功

驗證完畢,咱們刪掉這個token,從新申請一個來解決

打開這個選項

而後,將這個機器人拉入報警羣

和它進行交流後,在此刷新下面的命令

https://api.telegram.org/bot887549729:AAFyS949ryyYxbJI3mRS6ScW8qXbd7Yc0Og/getUpdates

而後發現找到了chatid

相關文章
相關標籤/搜索