Prometheus

1.普罗米修斯概述

Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数 据库的组合。适合监控docker容器。因为kubernetes(俗称k8s)的流行带动 了prometheus的发展。

2.时间序列数据

2.1什么是序列数据

时间序列数据(TimeSeries Data) : 按照时间顺序记录系统、设备状态变化 的数据被称为时序数据。
应用的场景很多, 如:

  • 无人驾驶车辆运行中要记录的经度,纬度,速度,方向,旁边物体的距 离等等。每时每刻都要将数据记录下来做分析。
  • 某一个地区的各车辆的行驶轨迹数据
  • 传统证券行业实时交易数据
  • 实时运维监控数据等

2.2时间序列数据特点

  • 性能好
    关系型数据库对于大规模数据的处理性能糟糕。NOSQL可以比较好的处理 大规模数据,让依然比不上时间序列数据库。
  • 存储成本低
    高效的压缩算法,节省存储空间,有效降低IO
    Prometheus有着非常高效的时间序列数据存储方法,每个采样数据仅仅占 用3.5byte左右空间,上百万条时间序列,30秒间隔,保留60天,大概花了 200多G(来自官方数据)

2.3Prometheus的主要特征

多维度数据模型 灵活的查询语言 不依赖分布式存储,单个服务器节点是自主的 以HTTP方式,通过pull模型拉去时间序列数据 也可以通过中间网关支持push模型 通过服务发现或者静态配置,来发现目标服务对象 支持多种多样的图表和界面展示

2.4普罗米修斯原理架构图

在这里插入图片描述

3.Prometheus搭建

服务器ip地址
Prometneus服务器192.168.47.120
被监控服务器192.168.47.121

3.1安装prometheus

从 https://prometheus.io/download/ 下载相应版本,上传到服务器上解压安装

[root@server ~]# ls
anaconda-ks.cfg  prometheus-2.31.1.linux-amd64.tar.gz
[root@server ~]# tar xf prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local/
[root@server ~]# ls /usr/local/prometheus-2.31.1.linux-amd64/
console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool
[root@server ~]# mv /usr/local/prometheus-2.31.1.linux-amd64/ /usr/local/prometheus
[root@server ~]# cd /usr/local/prometheus
[root@server prometheus]# ls
console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool

直接使用默认配置文件启动并确认端口9090

[root@server ~]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
[1] 45978
[root@server ~]# ts=2021-11-25T20:03:12.803Z caller=main.go:406 level=info msg="No time or size retention was set so using the default time retention" duration=15d
ts=2021-11-25T20:03:12.803Z caller=main.go:444 level=info msg="Starting Prometheus" version="(version=2.31.1, branch=HEAD, revision=411021ada9ab41095923b8d2df9365b632fd40c3)"
ts=2021-11-25T20:03:12.803Z caller=main.go:449 level=info build_context="(go=go1.17.3, user=root@9419c9c2d4e0, date=20211105-20:35:02)"
ts=2021-11-25T20:03:12.803Z caller=main.go:450 level=info host_details="(Linux 4.18.0-193.el8.x86_64 #1 SMP Fri Mar 27 14:35:58 UTC 2020 x86_64 server (none))"
ts=2021-11-25T20:03:12.803Z caller=main.go:451 level=info fd_limits="(soft=1024, hard=262144)"
ts=2021-11-25T20:03:12.803Z caller=main.go:452 level=info vm_limits="(soft=unlimited, hard=unlimited)"
ts=2021-11-25T20:03:12.806Z caller=web.go:542 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
ts=2021-11-25T20:03:12.807Z caller=main.go:839 level=info msg="Starting TSDB ..."
ts=2021-11-25T20:03:12.807Z caller=tls_config.go:195 level=info component=web msg="TLS is disabled." http2=false
ts=2021-11-25T20:03:12.809Z caller=head.go:479 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"
ts=2021-11-25T20:03:12.809Z caller=head.go:513 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=1.512µs
ts=2021-11-25T20:03:12.809Z caller=head.go:519 level=info component=tsdb msg="Replaying WAL, this may take a while"
ts=2021-11-25T20:03:12.813Z caller=head.go:590 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1
ts=2021-11-25T20:03:12.813Z caller=head.go:590 level=info component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1
ts=2021-11-25T20:03:12.813Z caller=head.go:596 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=20.866µs wal_replay_duration=4.319378ms total_replay_duration=4.353464ms
ts=2021-11-25T20:03:12.814Z caller=main.go:866 level=info fs_type=XFS_SUPER_MAGIC
ts=2021-11-25T20:03:12.814Z caller=main.go:869 level=info msg="TSDB started"
ts=2021-11-25T20:03:12.814Z caller=main.go:996 level=info msg="Loading configuration file" filename=/usr/local/prometheus/prometheus.yml
ts=2021-11-25T20:03:12.863Z caller=main.go:1033 level=info msg="Completed loading of configuration file" filename=/usr/local/prometheus/prometheus.yml totalDuration=49.131829ms db_storage=897ns remote_storage=1.702µs web_handler=356ns query_engine=1.164µs scrape=48.575476ms scrape_sd=46.7µs notify=75.123µs notify_sd=15.713µs rules=1.657µs
ts=2021-11-25T20:03:12.863Z caller=main.go:811 level=info msg="Server is ready to receive web requests."

[root@server ~]# ss -antlp|grep 9090
LISTEN    0         128                      *:9090                   *:*        users:(("prometheus",pid=45978,fd=8))   

3.2prometheus界面

通过浏览器访问http://服务器IP:9090就可以访问到prometheus的主界面

请添加图片描述

默认只监控了本机一台,点Status --》点Targets --》可以看到只监控了本机

请添加图片描述
请添加图片描述

3.3主机数据展示

通过http://服务器IP:9090/metrics可以查看到监控的数据

请添加图片描述

在web主界面可以通过关键字查询监控项
请添加图片描述

3.4监控远程Linux主机

在远程linux主机(被监控端agent)上安装node_exporter组件
下载地址: https://prometheus.io/download/

[root@agent ~]# ls
anaconda-ks.cfg  node_exporter-1.3.0.linux-amd64.tar.gz
[root@agent ~]# tar xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/
[root@agent ~]# mv /usr/local/node_exporter-1.3.0.linux-amd64/ /usr/local/node_exporter
[root@agent ~]# cd /usr/local/node_exporter/
[root@agent node_exporter]# ls
LICENSE  node_exporter  NOTICE

里面就一个启动命令node_exporter,可以直接使用此命令启动,确认端口9100

[root@agent ~]# nohup /usr/local/node_exporter/node_exporter &
[1] 143355
[root@agent ~]# nohup: 忽略输入并把输出追加到'nohup.out'

[1]+  退出 1                nohup /usr/local/node_exporter/node_exporter
[root@agent ~]# ss -antlp|grep 9100
LISTEN    0         128                      *:9100                   *:*        users:(("node_exporter",pid=76698,fd=3))                                       

通过浏览器访问http://被监控端IP:9100/metrics就可以查看到 node_exporter在被监控端收集的监控信息

请添加图片描述

回到prometheus服务器的配置文件里添加被监控机器的配置段
在主配置文件最后加上下面三行

[root@server ~]# vim /usr/local/prometheus/prometheus.yml 
[root@server ~]# tail /usr/local/prometheus/prometheus.yml 
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
  - job_name: 'tanjie'		# 取一个job名称来代 表被监控的机器
    static_configs:
      - targets: ["192.168.47.121:9100"]		# 这里改成被监控机器 的IP,后面端口接9100

改完配置文件后,重启服务

[root@server ~]# pkill prometheus
[root@server ~]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
[root@server ~]# ss -antlp|grep 9090
LISTEN    0         128                      *:9090                   *:*        users:(("prometheus",pid=74278,fd=8))                                          

回到web管理界面 --》点Status --》点Targets --》可以看到多了一台监 控目标
请添加图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值