(一)Prometheus监控--安装和配置

(一)、概述
一、什么是prometheus
Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。
2016年由Google发起Linux基金会旗下的原生云基金会(Cloud Native Computing Foundation), 将Prometheus归入其下第二大开源项目。
Prometheus目前在开源社区至关活跃。
Prometheus和Heapster(Heapster是K8S的一个子项目,用于获取集群的性能数据。)相比功能更完善、更全面。Prometheus性能也足够支撑上万台规模的集群。
二、Prometheus的特色node

  • 多维度数据模型。
  • 灵活的查询语言。
  • 不依赖分布式存储,单个服务器节点是自主的。
  • 经过基于HTTP的pull方式采集时序数据。
  • 能够经过中间网关进行时序列数据推送。
  • 经过服务发现或者静态配置来发现目标服务对象。
  • 支持多种多样的图表和界面展现,好比Grafana等。
    三、基本组件
    Prometheus生态包含多个组件,其中许多的组件都是可选的.
  • Prometheus Server: 用于收集和存储时间序列数据。
  • Client Library: 客户端库,为须要监控的服务生成相应的 metrics 并暴露给 Prometheus server。当 Prometheus server 来 pull 时,直接返回实时状态的 metrics。
  • Push Gateway: 主要用于短时间的 jobs。因为这类 jobs 存在时间较短,可能在 Prometheus 来 pull 以前就消失了。为此,此次 jobs 能够直接向 Prometheus server 端推送它们的 metrics。这种方式主要用于服务层面的 metrics,对于机器层面的 metrices,须要使用 node exporter。
  • Exporters: 用于暴露已有的第三方服务的 metrics 给 Prometheus。
  • Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去除重复数据,分组,并路由到对收的接受方式,发出报警。常见的接收方式有:电子邮件,pagerduty,OpsGenie, webhook 等。
    四、基本原理
    Prometheus的基本原理是经过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就能够接入监控。不须要任何SDK或者其余的集成过程。这样作很是适合作虚拟化环境监控系统,好比VM、Docker、Kubernetes等。输出被监控组件信息的HTTP接口被叫作exporter 。目前互联网公司经常使用的组件大部分都有exporter能够直接使用,好比Varnish、Haproxy、Nginx、MySQL、Linux系统信息(包括磁盘、内存、CPU、网络等等)。
    五、架构图
    (一)Prometheus监控--安装和配置
    六、服务过程
    服务过程
  • Prometheus Daemon负责定时去目标上抓取metrics(指标)数据,每一个抓取目标须要暴露一个http服务的接口给它定时抓取。Prometheus支持经过配置文件、文本文件、Zookeeper、Consul、DNS SRV Lookup等方式指定抓取目标。Prometheus采用PULL的方式进行监控,即服务器能够直接经过目标PULL数据或者间接地经过中间网关来Push数据。
  • Prometheus在本地存储抓取的全部数据,并经过必定规则进行清理和整理数据,并把获得的结果存储到新的时间序列中。
  • Prometheus经过PromQL和其余API可视化地展现收集的数据。Prometheus支持不少方式的图表可视化,例如Grafana、自带的Promdash以及自身提供的模版引擎等等。Prometheus还提供HTTP API的查询方式,自定义所须要的输出。
  • PushGateway支持Client主动推送metrics到PushGateway,而Prometheus只是定时去Gateway上抓取数据。
  • Alertmanager是独立于Prometheus的一个组件,能够支持Prometheus的查询语句,提供十分灵活的报警方式。

(二)、安装配置
1、Prometheust Server端安装和相关配置
1.一、二进制包安装python

1.一、官网地址https://prometheus.io/download/
1.二、下载和安装
wget https://github.com/prometheus/prometheus/releases/download/v2.22.0-rc.0/prometheus-2.22.0-rc.0.linux-386.tar.gz
tar xf prometheus-2.22.0-rc.0.linux-386.tar.gz 
mv prometheus-2.22.0-rc.0.linux-386/prometheus /usr/local/prometheus
1.三、配置系统启动文件
 cat  /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
After=network.target
Documentation=https://prometheus.io/docs/introduction/overview/

[Service]
Type=simple
WorkingDirectory=/data/prometheus/
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --web.read-timeout=5m \
  --web.max-connections=512 \
  --storage.tsdb.retention=15d \
  --storage.tsdb.path=/data/prometheus \
  --query.timeout=2m

Restart=on-failure

[Install]
WantedBy=multi-user.target

1.四、把配置文件转移到标准目录/etc/prometheus/
mkdir -p /etc/prometheus/
cp /usr/local/prometheus/prometheus.yml /etc/prometheus/

cat /etc/prometheus/prometheus.yml
global:
  scrape_interval:     15s 
  evaluation_interval: 15s

alerting:
  alertmanagers:
  - static_configs:
    - targets:

rule_files:

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
1.四、启动
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl status prometheus
1.五、查看经过 ip:9090进行查看。二进制安装很是方便,没有依赖,自动查询的web界面。配置了9090端口,默认prometheus会抓取本身的/metrics接口

1.二、docker安装linux

一、安装
docker run \
    -p 9090:9090 \
    -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus

二、查看prometheus服务和状态
docker start prometheus
docker stop prometheus
docker stats prometheus

2、安装node_exporter提供metricsgit

一、下载、解压和移动
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar xf node_exporter-1.0.1.linux-amd64.tar.gz 
mv node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/prometheus/
二、配置启动文件
cat /etc/systemd/system/node_export.service
[Unit]
Description=Node Export
After=network.target
Documentation=https://prometheus.io/docs/guides/node-exporter/

[Service]
Type=simple
WorkingDirectory=/tmp/
ExecStart=/usr/local/prometheus/node_exporter 

Restart=on-failure

[Install]
WantedBy=multi-user.target

三、自启动
[root@ES-Master2 opt]# systemctl start node_export
[root@ES-Master2 opt]# systemctl enable node_export
Created symlink from /etc/systemd/system/multi-user.target.wants/node_export.service to /etc/systemd/system/node_export.service.
[root@ES-Master2 opt]# systemctl status node_export

四、加入监控
手动加入 prometheus 监控,修改其配置文件,再尾部增长以下内容:
  - job_name: elasticsearch
    scrape_interval: 60s
    scrape_timeout:  30s
    metrics_path: "/metrics"
    static_configs:
    - targets: [172.20.3.201:9100]
      labels:
        service: elasticsearch
而后从新载入配置curl -X POST http://localhost:9090/-/reload

五、查看生效的接口
(一)Prometheus监控--安装和配置github

六、docker安装更简单web

docker run -d \
  --net="host" \
  --pid="host" \
  -v "/:/host:ro,rslave" \
  quay.io/prometheus/node-exporter \
  --path.rootfs=/host

3、安装grafana进行展现
Grafana是用于可视化大型测量数据的开源程序,它提供了强大和优雅的方式去建立、共享、浏览数据。
Dashboard中显示了你不一样metric数据源中的数据。
Grafana最经常使用于因特网基础设施和应用分析,但在其余领域也有用到,好比:工业传感器、家庭自动化、过程控制等等。
Grafana支持热插拔控制面板和可扩展的数据源,目前已经支持Graphite、InfluxDB、OpenTSDB、Elasticsearch、Prometheus等。docker

一、下载和安装
一、下载地址 https://grafana.com/grafana/download
二、Red Hat, CentOS, RHEL, and Fedora(64 Bit)
wget https://dl.grafana.com/oss/release/grafana-7.2.1-1.x86_64.rpm
sudo yum install grafana-7.2.1-1.x86_64.rpm -y
三、自启动
systemctl enable grafana-server
systemctl start grafana-server
四、访问ip:3000端口,默认帐号和密码都是admin:admin
二、配置数据源。设置-配置-数据源-选择prometheus

(一)Prometheus监控--安装和配置
(一)Prometheus监控--安装和配置

三、下载相应的模板https://grafana.com/grafana/dashboards
四、导入模板。+--import,把下载的模板导进去

(一)Prometheus监控--安装和配置

相关文章
相关标签/搜索