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