prometheus + grafana

prometheus 介绍

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

数据库分类:
关系型 mysql,oracle,sql server,sybase,db2,access等
非关系型(nosql)
key-value memcache redis etcd
文档型 mongodb elasticsearch
列式 hbase
时序 prometheus
图形数据库 Neo4j

时序数据主要的特点:
数据带有时间属性,且数据量随着时间递增
大都为插入操作较多且无更新的需求,插入数据多,每秒钟插入数据可到达千万甚至是上亿条
分析过去时序数据可以做成多纬度报表,揭示其趋势性、规律性、异常性
分析时序数据趋势可以做大数据分析,机器学习,实现预测和预警
能够按照条件筛选数据, 也可以按照时间范围统计,聚合,展示数据

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

部署前期:

时钟同步
[root@node1 ~]# yum -y install chrony
[root@node1 ~]# systemctl restart chronyd
[root@node1 ~]# systemctl enable chronyd
[root@node1 ~]# timedatectl 
               Local time: Fri 2024-08-16 11:26:40 CST
           Universal time: Fri 2024-08-16 03:26:40 UTC
                 RTC time: Fri 2024-08-16 03:26:39
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

修改主机名
[root@node1 ~]# hostnamectl hostname server.example.com
[root@node1 ~]# bash
[root@server ~]# 

[root@node1 ~]# hostnamectl hostname agent1.example.com
[root@node1 ~]# bash
[root@agent1 ~]# 

[root@node1 ~]# hostnamectl hostname grafana.example.com
[root@node1 ~]# bash
[root@grafana ~]# 

添加/etc/hosts
[root@server ~]# systemctl restart chronyd
[root@server ~]# systemctl enable chronyd
[root@server ~]# timedatectl 
               Local time: Fri 2024-08-16 15:52:08 CST
           Universal time: Fri 2024-08-16 07:52:08 UTC
                 RTC time: Fri 2024-08-16 07:52:08
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[root@server ~]# hwclock -w

prometheus 的部署

[root@server ~]# ls
'!'   anaconda-ks.cfg   -e   -i.bak   prometheus-2.54.0.linux-amd64.tar.gz
[root@server ~]# tar -zxvf prometheus-2.54.0.linux-amd64.tar.gz -C  /usr/local/
prometheus-2.54.0.linux-amd64/
prometheus-2.54.0.linux-amd64/NOTICE
prometheus-2.54.0.linux-amd64/LICENSE
prometheus-2.54.0.linux-amd64/prometheus.yml
prometheus-2.54.0.linux-amd64/prometheus
prometheus-2.54.0.linux-amd64/consoles/
prometheus-2.54.0.linux-amd64/consoles/prometheus-overview.html
prometheus-2.54.0.linux-amd64/consoles/node-overview.html
prometheus-2.54.0.linux-amd64/consoles/index.html.example
prometheus-2.54.0.linux-amd64/consoles/node.html
prometheus-2.54.0.linux-amd64/consoles/node-disk.html
prometheus-2.54.0.linux-amd64/consoles/prometheus.html
prometheus-2.54.0.linux-amd64/consoles/node-cpu.html
prometheus-2.54.0.linux-amd64/promtool
prometheus-2.54.0.linux-amd64/console_libraries/
prometheus-2.54.0.linux-amd64/console_libraries/menu.lib
prometheus-2.54.0.linux-amd64/console_libraries/prom.lib
[root@server ~]# cd /usr/local/
[root@server local]# ls
bin  etc  games  include  lib  lib64  libexec  prometheus-2.54.0.linux-amd64  sbin  share  src
[root@server local]# mv prometheus-2.54.0.linux-amd64/  prometheus
[root@server local]# ls
bin  etc  games  include  lib  lib64  libexec  prometheus  sbin  share  src
[root@server local]# 
[root@server ~]#  /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
[root@server ~]# ss -anlt
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        Process        
LISTEN        0             128                         0.0.0.0:22                        0.0.0.0:*                          
LISTEN        0             128                            [::]:22                           [::]:*                          
LISTEN        0             4096                              *:9090                            *:*                          

在这里插入图片描述

监控其他主机

[root@agent1 ~]# tar -zxvf node_exporter-1.8.2.linux-amd64.tar.gz -C /usr/local
node_exporter-1.8.2.linux-amd64/
node_exporter-1.8.2.linux-amd64/NOTICE
node_exporter-1.8.2.linux-amd64/node_exporter
node_exporter-1.8.2.linux-amd64/LICENSE
[root@agent1 ~]# cd /usr/local/
[root@agent1 local]# ls
bin  etc  games  include  lib  lib64  libexec  node_exporter-1.8.2.linux-amd64  sbin  share  src
[root@agent1 local]# mv node_exporter-1.8.2.linux-amd64/ node_exporter
[root@agent1 local]# ls
bin  etc  games  include  lib  lib64  libexec  node_exporter  sbin  share  src
[root@agent1 local]# 
[root@agent1 local]# nohup  /usr/local/node_exporter/node_exporter &
[root@agent1 local]# ss -anlt
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        Process        
LISTEN        0             128                         0.0.0.0:22                        0.0.0.0:*                          
LISTEN        0             4096                              *:9100                            *:*                          
LISTEN        0             128                            [::]:22                           [::]:*                          
[root@agent1 local]# 

在这里插入图片描述
添加到服务器(监控)

[root@server ~]# vim /usr/local/prometheus/prometheus.yml 
  - job_name: "agent1"
    static_configs:
      - targets: ["192.168.100.80:9100"]

[root@server ~]# ps -ef | grep prometheus
root        8837     673  0 20:47 pts/0    00:00:00 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
root       51926     673  0 21:04 pts/0    00:00:00 grep --color=auto prometheus
[root@server ~]# kill -9 8837
[root@server ~]# ps -ef | grep prometheus
root       52528     673  0 21:04 pts/0    00:00:00 grep --color=auto prometheus
[1]+  Killed                  /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"
[root@server ~]# 

[root@server ~]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

[root@server ~]# ss -anlt
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        Process        
LISTEN        0             128                         0.0.0.0:22                        0.0.0.0:*                          
LISTEN        0             128                            [::]:22                           [::]:*                          
LISTEN        0             4096                              *:9090                            *:*                          


监控远程mysql

[root@agent1 ~]# tar -zxvf mysqld_exporter-0.15.1.linux-amd64.tar.gz -C /usr/local
mysqld_exporter-0.15.1.linux-amd64/
mysqld_exporter-0.15.1.linux-amd64/LICENSE
mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter
mysqld_exporter-0.15.1.linux-amd64/NOTICE
[root@agent1 ~]# cd /usr/local/
[root@agent1 local]# ls
bin  games    lib    libexec                             node_exporter  sbin   src
etc  include  lib64  mysqld_exporter-0.15.1.linux-amd64  nohup.out      share
[root@agent1 local]# mv mysqld_exporter-0.15.1.linux-amd64/ mysqld_exporter
[root@agent1 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysqld_exporter  node_exporter  nohup.out  sbin  share  src

[root@agent1 local]# yum -y install  mariadb-server
[root@agent1 local]# systemctl restart mariadb.service 
[root@agent1 local]# systemctl enable mariadb.service 
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@agent1 local]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all ON *.* to 'mysql_monitor'@'localhost' identified by
    -> '123';
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]>  flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]>exit

[root@agent1 local]# vim /usr/local/mysqld_exporter/.my.cnf
[root@agent1 local]# cat /usr/local/mysqld_exporter/.my.cnf 
[client]
user=mysql_monitor
password=123
[root@agent1 local]# 

[root@agent1 local]# nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &
[root@agent1 local]# ss -anlt
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        Process        
LISTEN        0             128                         0.0.0.0:22                        0.0.0.0:*                          
LISTEN        0             80                                *:3306                            *:*                          
LISTEN        0             4096                              *:9100                            *:*                          
LISTEN        0             4096                              *:9104                            *:*                          
LISTEN        0             128                            [::]:22                           [::]:*                          
[root@agent1 local]# 

[root@server ~]# vim /usr/local/prometheus/prometheus.yml 
  - job_name: "agent1_mariadb"
    static_configs:
      - targets: ["192.168.100.80:9104"]

[root@server ~]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

在这里插入图片描述

安装grafana

模板位置:https://grafana.com/grafana/dashboards

[root@grafana ~]# ls
anaconda-ks.cfg  -e  grafana-6.4.2-1.x86_64.rpm  -i.bak
[root@grafana ~]# rpm -ivh grafana-6.4.2-1.x86_64.rpm
warning: grafana-6.4.2-1.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 24098cb6: NOKEY
error: Failed dependencies:
        fontconfig is needed by grafana-6.4.2-1.x86_64
        freetype is needed by grafana-6.4.2-1.x86_64
        urw-fonts is needed by grafana-6.4.2-1.x86_64
[root@grafana ~]# yum -y install  fontconfig freetype urw-fonts
[root@grafana ~]# rpm -ivh grafana-6.4.2-1.x86_64.rpm

[root@grafana ~]# systemctl restart  grafana-server
[root@grafana ~]# systemctl enable  grafana-server
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /usr/lib/systemd/system/grafana-server.service.
[root@grafana ~]# ss -anlt
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        Process        
LISTEN        0             128                         0.0.0.0:22                        0.0.0.0:*                          
LISTEN        0             128                            [::]:22                           [::]:*                          
LISTEN        0             4096                              *:3000                            *:*                          
[root@grafana ~]# 

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

grafana+onealert报警

智能告警平台 – 设置名称领取AppKey – 新建监控策略
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、prometheus简介 Prometheus是一个开源的系统监控和告警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF维护管理的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,prometheus支持多种exporter采集数据,还支持通过pushgateway进行数据上报,Prometheus再性能上可支撑上万台规模的集群。 二、prometheus架构图 三、prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据。 2.Client Library: 客户端库,检测应用程序代码,当Prometheus抓取实例的HTTP端点时,客户端库会将所有跟踪的metrics指标的当前状态发送到prometheus server端。 3.Exporters: prometheus支持多种exporter,通过exporter可以采集metrics数据,然后发送到prometheus server端 4.Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去重,分组,并路由到相应的接收方,发出报警,常见的接收方式有:电子邮件,微信,钉钉, slack等。 5.Grafana:监控仪表盘 6.pushgateway: 各个目标主机可上报数据到pushgatewy,然后prometheus server统一从pushgateway拉取数据。 四、课程亮点 五、效果图展示 六、讲师简介 先超(lucky):高级运维工程师、资深DevOps工程师,在互联网上市公司拥有多年一线运维经验,主导过亿级pv项目的架构设计和运维工作 主要研究方向: 1.云计算方向:容器 (kubernetes、docker),虚拟化(kvm、Vmware vSphere),微服务(istio),PaaS(openshift),IaaS(openstack)等2.系统/运维方向:linux系统下的常用组件(nginx,tomcat,elasticsearch,zookeeper,kafka等),DevOps(Jenkins+gitlab+sonarqube+nexus+k8s),CI/CD,监控(zabbix、prometheus、falcon)等 七、课程大纲
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值