Promethus(普罗米修斯)监控

Johnny21
• 阅读 2043

一、任务背景

某某某公司是一家电商网站,由于公司的业务快速发展,公司要求对现有机器进行业务监控,责成运维部门来实施这个项目。

任务要求

1)部署监控服务器,实现7x24实时监控

2)针对公司的业务及研发部门设计监控系统,对监控项和触发器拿出合理意见

3)做好问题预警机制,对可能出现的问题要及时告警并形成严格的处理机制

4)做好监控告警系统,要求可以实现告警分级

  • 一级报警 电话通知
  • 二级报警 微信通知
  • 三级报警 邮件通知

5)处理好公司服务器异地集中监控问题,K8S内部使用的监控系统就是普罗米修斯

任务分析

为什么要监控?

答: 实时收集数据,通过报警及时发现问题,及时处理。数据为优化也可以提供依据。

监控四要素:

监控对象 [主机状态 服务 资源 页面,url]

用什么监控 [zabbix-server zabbix-agent] => 普罗米修斯监控

什么时间监控 [7x24 5x8]

报警给谁 [管理员]

项目选型:

  • mrtg (Multi Router Traffic Grapher)通过snmp协议得到设备的流量信息,并以包含PNG格式的图形的HTML文档方式显示给用户。
  • cacti (仙人掌) 用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据。官网地址: https://www.cacti.net/
  • ntop 官网地址: https://www.ntop.org/
  • nagios 能够跨平台,插件多,报警功能强大。官网地址: https://www.nagios.org/
  • centreon 底层使用的就是nagios。是一个nagios整合版软件。官网地址:https://www.centreon.com/
  • ganglia 设计用于测量数以千计的节点,资源消耗非常小。官网地址:http://ganglia.info/
  • open-falcon 小米发布的运维监控软件,高效率,高可用。时间较短,用户基数小。官网地址: http://open-falcon.org/
  • zabbix 跨平台,画图,多条件告警,多种API接口。使用基数特别大。官网地址: https://www.zabbix.com/
  • prometheus 基于时间序列的数值数据的容器监控解决方案。官网地址: https://prometheus.io/

综合分析:Prometheus比较适合公司的监控需求

二、普罗米修斯概述

Prometheus是最初在SoundCloud上构建的开源系统监视和警报工具包 。自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发人员和用户社区。现在,它是一个独立的开源项目,并且独立于任何公司进行维护。为了强调这一点并阐明项目的治理结构,Prometheus 于2016年加入了 Cloud Native Computing Foundation,这是继Kubernetes之后的第二个托管项目。

Prometheus 的优点

  • 非常少的外部依赖,安装使用超简单
  • 已经有非常多的系统集成 例如:docker HAProxy Nginx JMX等等
  • 服务自动化发现
  • 直接集成到代码
  • 设计思想是按照分布式、微服务架构来实现的

Prometheus 的特性

  • 一个多维数据模型,其中包含通过度量标准名称和键/值对标识的时间序列数据
  • PromQL,一种灵活的查询语言 ,可利用此维度
  • 不依赖分布式存储;单服务器节点是自治的
  • 时间序列收集通过HTTP上的拉模型进行
  • 通过中间网关支持推送时间序列
  • 通过服务发现或静态配置发现目标
  • 多种图形和仪表板支持模式

组件

Prometheus生态系统包含多个组件,其中许多是可选的:

大多数Prometheus组件都是用Go编写的,因此易于构建和部署为静态二进制文件。

Prometheus原理架构图

下图说明了Prometheus的体系结构及其某些生态系统组件:

Promethus(普罗米修斯)监控

Prometheus直接或通过中介推送网关从已检测作业中删除指标,以处理短暂的作业。它在本地存储所有报废的样本,并对这些数据运行规则,以汇总和记录现有数据中的新时间序列,或生成警报。Grafana或其他API使用者可以用来可视化收集的数据。

什么时候适合?

Prometheus可以很好地记录任何纯数字时间序列。它既适用于以机器为中心的监视,也适用于高度动态的面向服务的体系结构的监视。在微服务世界中,它对多维数据收集和查询的支持是一种特别的优势。

Prometheus的设计旨在提高可靠性,使其成为中断期间要使用的系统,以使您能够快速诊断问题。每个Prometheus服务器都是独立的,而不依赖于网络存储或其他远程服务。当基础结构的其他部分损坏时,您可以依靠它,并且无需设置广泛的基础结构即可使用它。

什么时候不适合?

普罗米修斯重视可靠性。即使在故障情况下,您始终可以查看有关系统的可用统计信息。如果您需要100%的准确性(例如按请求计费),则Prometheus并不是一个好的选择,因为所收集的数据可能不够详细和完整。在这种情况下,最好使用其他系统来收集和分析数据以进行计费,并使用Prometheus进行其余的监视。

三、安装prometheus

3.1、实验环境准备

服务器 IP地址:

  • Prometneus服务器: 192.168.211.101
  • 被监控服务器: 192.168.211.102
  • grafana服务器:192.168.211.103

静态ip(要求能上外网)

主机名:

各自配置好主机名
# hostnamectl set-hostname --static server.cluster.com
三台都互相绑定IP与主机名
# vim /etc/hosts
192.168.211.101 server.cluster.com
192.168.211.102 agent1.cluster.com
192.168.211.103 grafana.cluster.com

时间同步(时间同步一定要确认一下)

yum install -y ntpdate && ntpdate time.windows.com

关闭防火墙,selinux

systemctl status firewalld

# systemctl stop firewalld
# systemctl disable firewalld
# iptables -F

3.2、解压安装

https://prometheus.io/download/ 下载相应版本,安装到服务器上。官网提供的是二进制版,解压就能用,不需要编译

上传prometheus-2.5.0.linux-amd64.tar.gz

[root@server sortware]# tar -zxvf prometheus-2.5.0.linux-amd64.tar.gz -C /opt/data/

tar -zxvf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-2.5.0.linux-amd64/  /usr/local/prometheus 

直接使用默认配置文件启动

/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" & 

[root@server prometheus-2.5.0.linux-amd64]# ./prometheus --help
usage: prometheus []

The Prometheus monitoring server

Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--version Show application version.
--config.file="prometheus.yml"
Prometheus configuration file path.
--web.listen-address="0.0.0.0:9090"
Address to listen on for UI, API, and telemetry.
--web.read-timeout=5m Maximum duration before timing out read of the request, and closing idle connections.
--web.max-connections=512 Maximum number of simultaneous connections.
--web.external-url= The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used
for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to
prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically.
--web.route-prefix= Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.
--web.user-assets= Path to static asset directory, available at /user.
--web.enable-lifecycle Enable shutdown and reload via HTTP request.
--web.enable-admin-api Enable API endpoints for admin control actions.
--web.console.templates="consoles"
Path to the console template directory, available at /consoles.
--web.console.libraries="console_libraries"
Path to the console library directory.
--storage.tsdb.path="data/"
Base path for metrics storage.
--storage.tsdb.retention=15d
How long to retain samples in storage.
--storage.tsdb.no-lockfile
Do not create lockfile in data directory.
--storage.remote.flush-deadline=
How long to wait flushing sample on shutdown or config reload.
--storage.remote.read-sample-limit=5e7
Maximum overall number of samples to return via the remote read interface, in a single query. 0 means no limit.
--storage.remote.read-concurrent-limit=10
Maximum number of concurrent remote read calls. 0 means no limit.
--rules.alert.for-outage-tolerance=1h
Max time to tolerate prometheus outage for restoring 'for' state of alert.
--rules.alert.for-grace-period=10m
Minimum duration between alert and restored 'for' state. This is maintained only for alerts with configured 'for' time
greater than grace period.
--rules.alert.resend-delay=1m
Minimum amount of time to wait before resending an alert to Alertmanager.
--alertmanager.notification-queue-capacity=10000
The capacity of the queue for pending Alertmanager notifications.
--alertmanager.timeout=10s
Timeout for sending alerts to Alertmanager.
--query.lookback-delta=5m The delta difference allowed for retrieving metrics during expression evaluations.
--query.timeout=2m Maximum time a query may take before being aborted.
--query.max-concurrency=20
Maximum number of queries executed concurrently.
--query.max-samples=50000000
Maximum number of samples a single query can load into memory. Note that queries will fail if they would load more samples
than this into memory, so this also limits the number of samples a query can return.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]

确认端口(9090):ss -anltp | grep 9090

Promethus(普罗米修斯)监控

3.3、prometheus界面

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

默认只监控了本机一台,点Status --》点Targets --》可以看到只监控了本 机
Promethus(普罗米修斯)监控
主机数据展示:http://192.168.211.101:9090/metrics 可以查看到监控的数据
Promethus(普罗米修斯)监控
在web主界面可以通过关键字查询监控项
Promethus(普罗米修斯)监控
4、监控远程Linux主机
① 在远程linux主机(被监控端agent1)上安装node_exporter组件,下载地址: https://prometheus.io/download/

上传node_exporter-0.16.0.linux-amd64.tar.gz

[root@node102 software]# tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz -C /opt/data/

tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/node_exporter 

里面就一个启动命令node_exporter,可以直接使用此命令启动

Promethus(普罗米修斯)监控

nohup /opt/data/node_exporter-0.16.0.linux-amd64/node_exporter &

确认端口(9100)

Promethus(普罗米修斯)监控
扩展: nohup命令: 如果把启动node_exporter的终端给关闭,那么进程也会 随之关闭。nohup命令会帮你解决这个问题。

② 通过浏览器访问 http://192.168.211.102:9100/metrics 就可以查看到 node_exporter在被监控端收集的监控信息
Promethus(普罗米修斯)监控
③ 回到prometheus服务器的配置文件里添加被监控机器的配置段

在主配置文件最后加上下面三行

vim /usr/local/prometheus/prometheus.yml

  • job_name: 'node102'
    static_configs:
    • targets: ['192.168.209.128:9100']

Promethus(普罗米修斯)监控

  • job_name: ‘node102’ # 取一个job名称来代 表被监控的机器
    static_configs:
    • targets: [‘192.168.209.128:9100’] # 这里改成被监控机器 的IP,后面端口接9100

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

pkill prometheus

确认端口没有进程占用

./prometheus --config.file="./prometheus.yml" &

确认端口被占用,说 明重启成功
Promethus(普罗米修斯)监控
④ 回到web管理界面 --》点Status --》点Targets --》可以看到多了一台监 控目标Promethus(普罗米修斯)监控

本文转自 https://blog.csdn.net/lixinkuan328/article/details/107744002,如有侵权,请联系删除。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
DevOpSec DevOpSec
3年前
运维,关于监控的那些事,你有必要了解一下
作者|乔克来源|运维开发故事监控是整个运维以及产品整个生命周期最重要的一环,它旨在事前能够及时预警发现故障,事中能够结合监控数据定位问题,事后能够提供数据用于分析问题。一、监控的目的监控贯穿应用的整个生命周期。即从程序设计、开发、部署、下线。其主要的服务对象有:技术业务技术通过监控系统可以了解技术的环
zabbix5.0安装以及配置中文
zabbix监控服务作用:1.当出现一些突发情况能及时响应。2.及时捕捉证据,追溯相关问题。监控工具的作用:1.及时定位问题无需认为干预,大大减少人力成本2.通过技术角度,实现实时监控业务,当出现问题及时定位并告警到相关管理人员3.记录并以图形化的方式展示出来,方便管理员进行系统运行性能评估4.出现故障,针对某一个性能指标,自动化执行一个指定操作。监控系统
Stella981 Stella981
2年前
Nginx + lua +[memcached,redis]
精品案例1、Nginxluamemcached,redis实现网站灰度发布2、分库分表/基于Leaf组件实现的全球唯一ID(非UUID)3、Redis独立数据监控,实现订单超时操作/MQ死信操作SelectPollEpollReactor模型4、分布式任务调试Quartz应用
Stella981 Stella981
2年前
CODING DevOps 系列第六课:IT 运维之智能化告警实践
IT运维告警现状目前IT运维领域保证服务运行正常的主要方法是对相关运维指标进行实时监控,并根据经验设定一些规则,通过将实时监控的数据与规则进行对比,当某个指标监控值不符合设定的规则时,则判定为异常的状况,这样的话就会发送对应的告警到告警平台。告警平台收到通知后,会分配给对应的运维人员进行处理,运维人员去根据告警信息来排查,最终定
Stella981 Stella981
2年前
Linux运维常见面试题之精华收录
Linux运维常见面试题之精华收录1、什么是运维?什么是游戏运维?1)运维是指大型组织已经建立好的网络软硬件的维护,就是要保证业务的上线与运作的正常,在他运转的过程中,对他进行维护,他集合了网络、系统、数据库、开发、安全、监控于一身的技术运维又包括很多种,有DBA运维、网站运维、虚
Wesley13 Wesley13
2年前
UAVStack的慢SQL数据库监控功能及其实现
!(https://oscimg.oschina.net/oscnet/4d6e0c184a1cee4f0acc5a7e689fc556ec7.png)UAVStack是一个全维监控与应用运维平台。UAV.Monitor具备监控功能,包含基础监控、应用/服务性能监控、日志监控、业务监控等。在应用监控中,UAV可以根据应用实例画像;其中应用实例
Stella981 Stella981
2年前
DevOps运维系统:监控管理
ITIL4的监控管理在DevOps风行的当下,人们越来越关注自动化运维。其中,监控预告警、监控自愈越发流行起来。在《DevOps实践指南》和《持续交付发布可靠软件的系统方法》两本书中(DevOps的教科书级别),都有涉及讲解监控管理和实施。其实,监控早不是什么新概念,运维界无论在理论还是工具中,一直在不断探索。监控管理虽然在I
Stella981 Stella981
2年前
Prometheus监控告警浅析
前言最近有个新项目需要搞一套完整的监控告警系统,我们使用了开源监控告警系统Prometheus;其功能强大,可以很方便对其进行扩展,并且可以安装和使用简单;本文首先介绍Prometheus的整个监控流程;然后介绍如何收集监控数据,如何展示监控数据,如何触发告警;最后展示一个业务系统监控的demo。监控架构Prometheus的整个
云监控告警2.0:革新传统告警机制,引领智能化监控新时代
云监控告警机制是云监控体系的核心组成部分,它负责在云服务出现异常或故障时,及时发出告警通知,以便运维人员迅速采取措施解决问题。传统的云监控告警机制虽然能够在一定程度上实现告警功能,但在告警准确性、实时性、智能化等方面存在诸多不足。云监控告警2.0则通过引入先进的技术和算法,对传统告警机制进行了全面升级,大大提高了告警的效率和准确性。