监控神器 Prometheus 安装配置
提示:以下是本篇文章正文内容,下面案例可供参考
一、监控
1.什么是监控?
监控(monitor): 监视我们的服务器或者服务,一旦出现问题,要告诉我们(告警),运维人员及时去处理,将公司的损失减少到最小
2.监控的意义:
监控在公司里非常重要,任何公司都十分重视,都要监控的存在.在后台需要收集数据,分析数据,可以提前预知一些问题,及时发现并处理问题,提醒工程师尽快的去解决问题,减少公司的损失.提升了产品的品质感,增强了用户的信任感.
3.监控的工具: prometheus
(1) 官方网址
(2) prometheus 介绍:
Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project’s governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.
Prometheus collects and stores its metrics as time series data, i.e. metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels.
翻译:
Prometheus是一个开源系统监控和警报工具包,最初是在SoundCloud上构建的。 自从它在2012年成立以来,许多公司和组织已经采用了Prometheus,并且这个项目有一个非常活跃的开发人员和用户社区。 它现在是一个独立的开源项目,并且独立于任何公司进行维护。 为了强调这一点,并澄清项目的治理结构,普罗米修斯在2016年加入了云本地计算基金会,成为继Kubernetes之后的第二个托管项目。
Prometheus以时间序列数据的形式收集和存储度量数据,也就是说,度量信息与记录它的时间戳一起存储,与称为标签的可选键值对一起存储。
二、prometheus
1.什么是prometheus?
在古希腊神话中,普罗米修斯是一个神,为了解除人类没有火种的困苦,勇敢地从诸神那里盗取火种,忍受各种痛苦,为人类造福万代.
但是在Linux中,prometheus 是一个监控工具
云原生: 与k8s相关的技术 ,prometheus 可以用来监控容器
Prometheus于 2016 年加入 云原生计算基金会,作为继Kubernetes之后的第二个托管项目。
Kubernetes --》k8s
2.如何安装和配置?(2种方法)
(1) 使用容器来安装(最简单也是最方便,推荐)
pull
push
数据的实时性–》得到最新鲜的数据 --》push
服务器的负载,网络的负载–》可控性 --》pull
1.启动容器
docker run -d -p 9090:9090 --name sc-prom-1 prom/prometheus
[root@worker-1 ~]# docker run -d -p 9090:9090 --name sc-prom-1 prom/prometheus
Unable to find image 'prom/prometheus:latest' locally
latest: Pulling from prom/prometheus
aa2a8d90b84c: Pull complete
b45d31ee2d7f: Pull complete
71dcff1cfd3f: Pull complete
2da1e2668856: Pull complete
2ba2baa9a21a: Pull complete
5f5f8be9bcf4: Pull complete
ec3160c71979: Pull complete
b5fe1b9dfdaf: Pull complete
6382c577d8fc: Pull complete
4dcc5723b182: Pull complete
0aff4f9499c7: Pull complete
69af68c28748: Pull complete
Digest: sha256:ccc801f38fdac43f0ed3e1b0220777e976828d6558f8ef3baad9028e0d1797ae
Status: Downloaded newer image for prom/prometheus:latest
5ce8d18e293a8eaa5a8f95b345a613f6ced5b24f620fab71a5174e654d431386
2.查看进程
[root@worker-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ce8d18e293a prom/prometheus "/bin/prometheus --c…" 13 seconds ago Up 10 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp sc-prom-1
72a6cb608e41 nginx:latest "/docker-entrypoint.…" 7 hours ago Up 7 hours 80/tcp sc-nfs-web.7.dnxzzk9t9seduvwqzzvg3qf6m
a51f1d89e0e8 nginx:latest "/docker-entrypoint.…" 7 hours ago Up 7 hours 80/tcp sc-nfs-web.10.ozd3ckw2k5uxhzzrkcsnoshok
[root@worker-1 ~]#
3.访问prometheus的容器
http://192.168.0.18:9090/graph --》web界面的
http://192.168.0.18:9090/metrics ---》查看prometheus的各种指标
(2) 源码安装(在单独的一台服务器上安装prometheus)
[root@localhost ~]# hostnamectl set-hostname prometheus
[root@localhost ~]# su
[root@prometheus ~]#
**
1.解压源码包
**(压缩包需要单独下载哈)
[root@prometheus ~]# rz
[root@prometheus ~]# ls
prometheus-2.29.1.linux-amd64.tar.gz
[root@prometheus ~]#
[root@prometheus ~]# mkdir /prometheus
[root@prometheus ~]# mv prometheus-2.29.1.linux-amd64.tar.gz /prometheus/
[root@prometheus ~]#
[root@prometheus prometheus]# PATH=$PATH:/prometheus/prometheus-2.29.1.linux-amd64
[root@prometheus prometheus]# which prometheus
/prometheus/prometheus-2.29.1.linux-amd64/prometheus
[root@prometheus prometheus]#
2.启动prometheus
prometheus 启动程序
prometheus.yml 配置文件
[root@prometheus prometheus-2.29.1.linux-amd64]# ./prometheus --config.file=prometheus.yml
level=info ts=2021-08-25T09:23:53.236Z caller=main.go:390 msg="No time or size retention was set so using the default time retention" duration=15d
level=info ts=2021-08-25T09:23:53.237Z caller=main.go:428 msg="Starting Prometheus" version="(version=2.29.1, branch=HEAD, revision=dcb07e8eac34b5ea37cd229545000b857f1c1637)"
level=info ts=2021-08-25T09:23:53.237Z caller=main.go:433 build_context="(go=go1.16.7, user=root@364730518a4e, date=20210811-14:48:27)"
3.查看进程
[root@prometheus ~]# ps aux|grep prome
root 1716 1.6 4.3 780840 43756 pts/0 Sl+ 17:23 0:00 ./prometheus --config.file=prometheus.yml
root 1743 0.0 0.0 112824 984 pts/1 S+ 17:24 0:00 grep --color=auto prome
[root@prometheus ~]#
[root@prometheus ~]# ss -anplut|grep prome
tcp LISTEN 0 128 [::]:9090 [::]:* users:(("prometheus",pid=1716,fd=7))
[root@prometheus ~]#
4.访问:
ip:9090/metrics
ip:9090/graph
3.prometheus 的专业术语有哪些?
(1)metric (指标)----time series data
metrics are numeric measurements, time series mean that changes are recorded over time.
度量是数值度量,时间序列意味着变化是随时间记录的。
(2)label (标签)----key-value pairs
name:liulf
sex:male
(3)pull----拉数据 **push----推数据
server到client上去拉数据
push和pull 那个更加好?
1.数据的实时性–》得到最新鲜的数据 --》push
2.服务器的负载,网络的负载–》可控性 --》pull
(4)exporter(出口)
理解为植入客户机的一个程序,程序专门收集客户机的数据,发送给prometheus 服务器
相当于一个间谍(地下党),收集情报,发送中央.
(5)PromQL(prometheus query language)
prometheus 时序数据库里的查询语言
(6)timstamp(时间戳)
记录某个时间点
(7)TSDB(time series database)
时间序列的数据库
(8)pushgateway(中间的服务器)
中间临时存放时间的地方
短时间运行的程序可以主动将自己的数据push到pushgateway里存放,然后prometheus server到pushgateway去拉数据
(9)grafana(图形展示的软件)
到prometheus的时序数据库里拿数据,然后展示图形
4.prometheus 的架构图
总结
-
prometheus是各大公司使用的监控工具,是应用场景非常广泛的,和之后的k8s 一样都十分重要,一定要好好理解和掌握哦.
-
对于prometheus 的安装还是比较推荐第一种,比较简单操作,第二种也可以尝试操作一下.