一、相关基础概念

1、Prometheus基于http协议工作

2、http协议:超文本传输协议,服务器传输超文本到本地浏览器的传送协议

https://www.cnblogs.com/ranyonsue/p/5984001.html  详细参看

HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议

HTTP是一个基于TCP/IP通信协议来传递数据(HTML 文件, 图片文件, 查询结果等)。

HTTP是一个属于应用层的面向对象的协议,由于其简捷、快速的方式,适用于分布式超媒体信息系统。

HTTP协议工作于客户端-服务端架构为上。浏览器作为HTTP客户端通过URL向HTTP服务端即WEB服务器发送所有请求。Web服务器根据接收到的请求后,向客户端发送响应信息。

 

HTTP使用统一资源标识符(Uniform Resource Identifiers, URI)来传输数据和建立连接。URL是一种特殊类型的URI,包含了用于查找某个资源的足够的信息

URL,全称是UniformResourceLocator, 中文叫统一资源定位符,是互联网上用来标识某一处资源的地址。

Prometheus的搭建

3、prometheus支持三种类型的途径从目标上抓取指标数据

exporters

  被监控的目标不支持pro的数据格式,通过exporters抽取指标数据,进行格式化处理成pro兼容的数据格式

再响应给pro server。

instrumentation

  测量系统,应用系统内建了pro兼容的指标数据格式,pro server可以直接采集。

pushgateway:  

  pro 采用 pull 模式,可能由于不在一个子网或者防火墙原因,导致 Prometheus 无法直接拉取各个 target 数据。在监控业务数据的时候,需要将不同数据汇总, 由 Prometheus 统一收集。暂存在pushgateway,等待pro server拉取

https://www.cnblogs.com/xiao987334176/p/9933963.html   写得不错

二、安装过程

1、下载包(外网特别慢)

#  tar  -xvf  prometheus-2.16.0.linux-amd64.tar.gz  -C  /usr/local/
#  mv /usr/local/prometheus-2.16.0.linux-amd64/  /usr/local/prometheus
# pwd 
/usr/local/prometheus
# ls
console_libraries  LICENSE  prometheus      promtool
consoles           NOTICE   prometheus.yml  tsdb

#./prometheus --version prometheus, version 2.16.0 (branch: HEAD, revision: b90be6f32a33c03163d700e1452b54454ddce0ec) build user: root@7ea0ae865f12 build date: 20200213-23:50:02 go version: go1.13.8 (此处go语言环境,没提前准备) #./prometheus & 启动

Prometheus的搭建

2、配置说明

Prometheus的搭建

 # cat prometheus.yml

# 全局配置

global:
  scrape_interval:     15s # 设置抓取间隔,默认为1分钟
  evaluation_interval: 15s #估算规则的默认周期,每15秒计算一次规则。默认1分钟
  # scrape_timeout  #默认抓取超时,默认为10s

# Alertmanager相关配置
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# 规则文件列表,使用'evaluation_interval' 参数去抓取
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

#  抓取配置列表
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

三、加入systemd管理

# vi /etc/systemd/system/prometheus.service
 [Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --web.listen-address=:9090

[Install]
WantedBy=multi-user.target     

# systemctl daemon-reload
#systemctl enable prometheus
#systemctl start prometheus  

四、接入grafana

1、下载

# yum install -y  grafana-6.6.2-1.x86_64.rpm (rpm包是提前下好的,yum解决两个依赖)

2、启动:

默认端口3000,用户名admin,密码admin

启动方式:

脚本启动

# service grafana-server start
Starting grafana-server (via systemctl):                   [  确定  ]

systemd 启动

#systemctl daemon-reload

#systemctl start grafana-server

#systemctl status grafana-server

#systemctl enable grafana-server.service 

3、重要文件目录:

二进制文件: /usr/sbin/grafana-server
init.d 脚本: /etc/init.d/grafana-server
环境变量文件: /etc/sysconfig/grafana-server
配置文件: /etc/grafana/grafana.ini
启动项: /sys/fs/cgroup/systemd/system.slice/grafana-server.service   、   /usr/lib/systemd/system/grafana-server.service
日志文件:/var/log/grafana/grafana.log
默认配置的sqlite3数据库:/var/lib/grafana/grafana.db

环境配置文件:

systemd 和 init.d 脚本启动都是加载的 /etc/sysconfig/grafana-server 文件。
可以在 /etc/sysconfig/grafana-server 文件中修改日志目录,数据目录和其他一些环境变量。

数据库:

默认配置指定的数据库 sqlite3 在 /var/lib/grafana/grafana.db 。升级之前记得备份。
也可以用 mysql 或者 postgres,详细配置参考:http://docs.grafana.org/installation/configuration/#database 或者后面的介绍的配置方法

配置文件:

配置文件存放在 /etc/grafana/grafana.ini ,详细的配置选项参考:http://docs.grafana.org/installation/configuration/

添加数据源:

Graphite
InfluxDB
OpenTSDB
Prometheus

服务器端图形渲染:

服务器端映像(png)呈现是一个可选的特性,但在共享可视化时非常有用,例如在警报通知中。
如果图像缺少文本,请确保已经安装了字体包

#yum install fontconfig
#yum install freetype*
#yum install urw-fonts

4、管理

配置:

grafana 后端有许多配置选项,可以在一个配置文件或环境变量中指定。
ini 配置文件以分号为注释 ;
默认配置文件路径:$WORKING_DIR/conf/defaults.ini
自定义配置文件:$WORKING/conf/custom.ini
自定义配置文件路径可以使用 --config 参数覆盖

注意:使用 rpm或者 deb 方式安装的,配置文件默认在 /etc/grafana/grafana.ini
这个路径是由 init.d 脚本 --config 参数指定的。

使用环境变量

下面列出的配置文件中的选项都可以被环境变量覆盖,语法:

    GF_<SectionName>_<KeyName>
     
    配置文件选项:
    # default section
    instance_name = ${HOSTNAME}
     
    [security]
    admin_user = admin
     
    [auth.google]
    client_secret = 0ldS3cretKey
     
    环境变量替换:
    export GF_DEFAULT_INSTANCE_NAME=my-instance
    export GF_SECURITY_ADMIN_USER=true
    export GF_AUTH_GOOGLE_CLIENT_SECRET=newS3cretKey

五、问题记录

Prometheus的搭建

解决:
#timedatectl set-timezone Asia/Shanghai
#ntpdate -u cn.pool.ntp.org
#systemctl restart prometheus.service
#reboot    重启系统(或电脑)

#yum -y install ntpdate ntp
#rm -rf /etc/localtime
#ln -s /usr/share/zoneinfo/Asia/Shanghai    /etc/localtime
#ntpdate us.pool.ntp.org (备用)

六、node_exporter的管理

node-exporter用于采集服务器层面的运行指标,包括机器的loadavg负载、filesystem文件系统、meminfo内存信息等基础监控,类似于传统主机监控维度的zabbix-agent

http://192.168.40.131:9100/metrics   ( node_exporter的url显示)

https://www.mediaat.cn/news/show-4522.html  (node_exporter怎么设置开机自启)

# nohup /root/node_exporter-0.18.1.linux-amd64/node_exporter  & (nohup是不挂断,&后台运行,结合后就是永久在后台运行)

容器监控实践—node-exporter

https://www.jianshu.com/p/e3c9fc929d8a

七、mysqld_exporter

# cat /root/.my.cnf
[client]
user=admin
password=QWer90-=

#mysql  (实现了免密登录,,前提是mysql数据库中已经做过admin用户localhost本地登录授权)

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.29 MySQL Community Server (GPL)
# pwd
/usr/local/mysqld_exporter
# nohup ./mysqld_exporter --config.my-cnf=/root/.my.cnf &  (启动mysqld_exporter

http://192.168.40.132:9104/metrics (查看数据是否收集过来,默认端口9104)

 Prometheus的搭建

http://ip:3000

Prometheus的搭建

http://ip:9090

 Prometheus的搭建

八、prometheus设置快照

1、加上启动参数

--web.enable-admin-api

2、调用api生成快照

curl -XPOST http://storage0002:9090/api/v1/admin/tsdb/snapshot

{"status":"success","data":{"name":"20210421T105410Z-4def1b8d4ac9ad17"}}%

3、同步结果到目标主机

rsync -pgoav --progress root@x.x.x.x:/data/prometheus/prometheus-data/data/snapshots .

 

 https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis

官网下载地址:https://prometheus.io/download/#node_exporter

https://blog.51cto.com/msiyuetian/2369130  (docker版搭建)

https://blog.csdn.net/BianChengNinHao/article/details/80985302

https://www.jianshu.com/p/b2f1b58c8e7f    Prometheus Operator 的安装

https://yasongxu.gitbook.io/container-monitor/yi-.-kai-yuan-fang-an/di-1-zhang-cai-ji/kube-state-metrics

相关文章:

  • 2021-07-13
  • 2021-06-02
  • 2022-01-02
  • 2022-12-23
  • 2021-09-22
  • 2021-07-20
  • 2022-03-14
  • 2021-10-26
猜你喜欢
  • 2021-08-04
  • 2021-08-13
  • 2021-05-21
  • 2021-12-17
  • 2021-08-31
  • 2021-05-26
相关资源
相似解决方案