概述:
Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数据库的组合。适合监控docker容器。因为kubernetes(俗称k8s)的流行带动了prometheus的发展。时间序列数据特点:1.性能好2.存储成本低,高效的压缩算法,节省存储空间,有效降低IO。Prometheus有着非常高效的时间序列数据存储方法,每个采样数据仅仅占用3.5byte左右空间,上百万条时间序列,30秒间隔,保留60天,大概花了200多G(来自官方数据)特征:
1.多维度数据模型2.灵活的查询语言3.不依赖分布式存储,单个服务器节点是自主的4.以HTTP方式,通过pull模型拉去时间序列数据5.也可以通过中间网关支持push模型6.通过服务发现或者静态配置,来发现目标服务对象7.支持多种多样的图表和界面展示
官网下载地址:https://prometheus.io/download///下载wgt https://github.com/prometheus/prometheus/releases/download/v2.35.0/prometheus-2.35.0.linux-amd64.tar.gz//解压tar -xf prometheus-2.35.0.linux-amd64.tar.gz -C /usr/local//改名mv prometheus-2.35.0.linux-amd64 prometheus//默认启动nohup ./prometheus --config.file="/usr/local/prometheus/prometheus.yml" &//端口检查lsof -i:9090ss -naltp |grep 9090 //浏览器访问192.168.0.215:9090//浏览器访问192.168.0.215:9090默认监控本机


console_libraries目录:consoles目录:LICENSE问价:NOTICE文件:prometheus文件:默认启动的可执行文件prometheus.yml配置文件:默认配置文件promtool文件:vi prometheus.yml
global: scrape_interval: 60s # 拉取时间间隔 evaluation_interval: 60s # 告警时间间隔- job_name: "prometheus" #监控名称取名字 static_configs: - targets: ["localhost:9090"] #被监控机器的ip和端口指标配置下载:https://prometheus.io/download/在其他机器安装node_exporter,端口9100
第一步:下载安装node_exporter
//下载wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz//解压tar -xf node_exporter-1.3.1.linux-amd64.tar.gz -C /usr/local///改名mv node_exporter-1.3.1.linux-amd64 node_exporter//启动nohup /usr/local/node_exporter/node_exporter &//浏览器输入,监控数据,端口9100http://192.168.0.216:9100/metrics第二步:配置到prometheus
vi /usr/local/prometheus/prometheus.yml - job_name: "node" static_configs: - targets: ["192.168.0.216:9100"] labels: instance: 192.168.0.216 group: node - targets: ["192.168.0.247:9100"] labels: instance: 192.168.0.247 group: node - targets: ["192.168.0.235:9100"] labels: instance: 192.168.0.235 group: node - targets: ["192.168.0.236:9100"] labels: instance: 192.168.0.236 group: node//重启prometheuslsof -i:9090kill -9 xxxxnohup ./prometheus &查看:


第一步:下载安装mysqld_exporter
端口:9104
//下载wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz//解压tar -xf mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local///改名mv mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter//创建mysqld_exporter需要使用mysql的用户名和密码,文件需要手动创建vi /usr/local/mysqld_exporter/my.cnf[client]host=192.168.0.215user=rootpassword=123456port=3306//启动mysqld_exporternohup ./mysqld_exporter --config.my-cnf=./my.cnf &//检查端口lsof -i:9104第二步:配置到prometheus
vi /usr/local/prometheus/prometheus.yml- job_name: "sg-215-mysql" static_configs: - targets: ["192.168.0.215:9104"]//重启prometheuslsof -i:9090kill -9 xxxxnohup ./prometheus &查看:

第一步:下载安装postgres_exporter
//下载wget https://github.com/prometheus-community/postgres_exporter/releases/download/v0.10.1/postgres_exporter-0.10.1.linux-386.tar.gz//解压tar -xf postgres_exporter-0.10.1.linux-386.tar.gz -C /usr/local///改名mv postgres_exporter-0.10.1.linux-386 postgres_exporter//添加环境变量export DATA_SOURCE_NAME="postgresql://postgres:iLoveShark@192.168.0.247:32432/postgres?sslmode=disable"//启动nohup ./postgres_exporter &//浏览器输入:http://192.168.0.215:9187/metrics第二步:配置到prometheus
- job_name: "postgreSql" static_configs: - targets: ["192.168.0.215:9187"] labels: instance: 192.168.0.247:32432 group: postgreSql - targets: ["192.168.0.216:9187"] labels: instance: hk-center.pg.rds.aliyuncs.com:5432 group: postgreSql第一步:下载安装redis_exporter
//下载wget https://github.com/oliver006/redis_exporter/releases/download/v1.37.0/redis_exporter-v1.37.0.linux-386.tar.gz//解压tar -xf redis_exporter-v1.37.0.linux-386.tar.gz -C /usr/local///改名mv redis_exporter-v1.37.0.linux-386 redis_exporter//启动./redis_exporter -help //查看参数nohup ./redis_exporter -redis.addr 192.168.0.247:30279 & //无密码nohup ./redis_exporter -redis.addr 192.168.0.247:30279 -redis.password 123456 & //有密码//浏览器输入:http://192.168.0.215:9121/metrics第二步:配置到prometheus
- job_name: "redis" static_configs: - targets: ["192.168.0.215:9121"] labels: instance: 192.168.0.247:30279 group: redisHTTP 测试: 定义 Request Header 信息、判断 Http status / Http Respones Header / Http Body 内容TCP 测试: 业务组件端口状态监听、应用层协议定义与监听ICMP 测试: 主机探活机制POST 测试: 接口联通性SSL证书过期时间https://prometheus.io/download/
//下载wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.20.0/blackbox_exporter-0.20.0.linux-amd64.tar.gz//解压tar -xf blackbox_exporter-0.20.0.linux-amd64.tar.gz -C /usr/local///改名mv blackbox_exporter-0.20.0.linux-amd64 blackbox_exporter//启动nohup ./blackbox_exporter &//浏览器输入http://192.168.0.215:9115/vi /usr/local/prometheus/prometheus.yml
//重启prometheus
lsof -i:9090
kill -9 xxxx
nohup ./prometheus &
网站监控:
- job_name: 'http_status' metrics_path: /probe params: module: [http_2xx] static_configs: - targets: ['https://admin.d.blueshark.com'] labels: instance: admin.d.blueshark.com group: web - targets: ['https://admin.k.blueshark.com'] labels: instance: admin.k.blueshark.com group: web relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.0.215:9115ping检测:
- job_name: 'ping_status' metrics_path: /probe params: module: [icmp] static_configs: - targets: ['192.168.0.249'] labels: instance: 'ping_status' group: 'icmp' relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.0.215:9115端口检测:
- job_name: 'port_status' metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: ['192.168.0.215:80', '192.168.0.216:80', '192.168.0.217:80'] labels: instance: 'port_status' group: 'port' relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.0.215:9115