Promethues官网:
Prometheus介绍

一、Prometheus介绍

Prometheus是一个开源的系统监控和报警零碎,当初曾经退出到CNCF基金会,成为继k8s之后第二个在CNCF托管的我的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,同时也反对多种exporter采集数据,还反对pushgateway进行数据上报,Prometheus性能足够撑持上万台规模的集群。

二、Prometheus特点

2.1、prometheus特点
1)多维度数据模型

每一个工夫序列数据都由metric度量指标名称和它的标签labels键值对汇合惟一确定:这个metric度量指标名称指定监控指标零碎的测量特色(如:http_requests_total- 接管http申请的总计数)。labels开启了Prometheus的多维数据模型:对于雷同的度量名称,通过不同标签列表的联合, 会造成特定的度量维度实例。(例如:所有蕴含度量名称为/api/tracks的http申请,打上method=POST的标签,则造成了具体的http申请)。这个查询语言在这些度量和标签列表的根底上进行过滤和聚合。扭转任何度量上的任何标签值,则会造成新的工夫序列图。

2)灵便的查询语言(PromQL):能够对采集的metrics指标进行加法,乘法,连贯等操作;

3)能够间接在本地部署,不依赖其余分布式存储;

4)通过基于HTTP的pull形式采集时序数据;

5)能够通过两头网关pushgateway的形式把工夫序列数据推送到prometheus server端;

6)可通过服务发现或者动态配置来发现指标服务对象(targets)。

7)有多种可视化图像界面,如Grafana等。

8)高效的存储,每个采样数据占3.5 bytes左右,300万的工夫序列,30s距离,保留60天,耗费磁盘大略200G。

9)做高可用,能够对数据做异地备份,联邦集群,部署多套prometheus,pushgateway上报数据

2.2、什么是样本
样本:在工夫序列中的每一个点称为一个样本(sample),样本由以下三局部组成:

指标(metric):指标名称和形容以后样本特色的 labelsets;
工夫戳(timestamp):一个准确到毫秒的工夫戳;
样本值(value): 一个 folat64 的浮点型数据表示以后样本的值。
示意形式:通过如下表达方式示意指定指标名称和指定标签汇合的工夫序列:<metric name>{<label name>=<label value>, ...}

例如,指标名称为 api_http_requests_total,标签为 method="POST" 和 handler="/messages" 的工夫序列能够示意为:api_http_requests_total{method="POST", handler="/messages"}

Metric类型:

Counter: 一种累加的metric,如申请的个数,完结的工作数,呈现的谬误数等

Gauge: 惯例的metric,如温度,可任意加减。其为刹时的,与工夫没有关系的,能够任意变动的数据。

Histogram: 柱状图,用于察看后果采样,分组及统计,如:申请持续时间,响应大小。其次要用于示意一段时间内对数据的采样,并可能对其指定区间及总数进行统计。依据统计区间计算

Summary: 相似Histogram,用于示意一段时间内数据采样后果,其间接存储quantile数据,而不是依据统计区间计算出来的。不须要计算,间接存储后果

PromQL 根本应用
PromQL (Prometheus Query Language) 是 Prometheus 本人开发的数据查问 DSL 语言,语言表现力十分丰盛,内置函数很多,在日常数据可视化以及rule 告警中都会应用到它。在前面章节会介绍

更多请参见详情

三、Prometheus组件介绍

1)Prometheus Server: 用于收集和存储工夫序列数据。

2)Client Library: 客户端库,检测利用程序代码,当Prometheus抓取实例的HTTP端点时,客户端库会将所有跟踪的metrics指标的以后状态发送到prometheus server端。

3)Exporters: prometheus反对多种exporter,通过exporter能够采集metrics数据,而后发送到prometheus server端,所有向promtheus server提供监控数据的程序都能够被称为exporter

4)Alertmanager: 从 Prometheus server 端接管到 alerts 后,会进行去重,分组,并路由到相应的接管方,发出报警,常见的接管形式有:电子邮件,微信,钉钉, slack等。

5)Grafana:监控仪表盘,可视化监控数据

6)pushgateway: 各个指标主机可上报数据到pushgateway,而后prometheus server对立从pushgateway拉取数据。

helm 部署prometheus

从官网仓库搜寻prometheus 并按提醒增加仓库并装置

https://artifacthub.io/

  • 增加仓库
[root@k8s-master prometheus]# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts"prometheus-community" has been added to your repositories[root@k8s-master prometheus]# helm repo update  #更新仓库Hang tight while we grab the latest from your chart repositories......Successfully got an update from the "bitnami" chart repository...Successfully got an update from the "prometheus-community" chart repository...Successfully got an update from the "stable" chart repositoryUpdate Complete. ⎈Happy Helming!⎈[root@k8s-master prometheus]# helm search repo prometheusNAME                                                  CHART VERSION    APP VERSION    DESCRIPTION                                       bitnami/kube-prometheus                               6.1.8            0.50.0         kube-prometheus collects Kubernetes manifests t...bitnami/prometheus-operator                           0.31.1           0.41.0         DEPRECATED The Prometheus Operator for Kubernet...bitnami/wavefront-prometheus-storage-adapter          1.0.7            1.0.3          Wavefront Storage Adapter is a Prometheus integ...prometheus-community/kube-prometheus-stack            18.0.10          0.50.0         kube-prometheus-stack collects Kubernetes manif...prometheus-community/prometheus                       14.6.1           2.26.0         Prometheus is a monitoring system and time seri...prometheus-community/prometheus-adapter               2.17.0           v0.9.0         A Helm chart for k8s prometheus adapter           prometheus-community/prometheus-blackbox-exporter     5.0.3            0.19.0         Prometheus Blackbox Exporter  [root@k8s-master prometheus]#  helm show readme  prometheus-community/prometheus   #装置前看下蕴含的组件是否适合 此版本蕴含的插件比拟全面[root@k8s-master prometheus]# kubectl create ns monitornamespace/monitor created
  • 下载Chart包 依据本人需要批改values.yaml
[root@k8s-master prometheus]#  helm pull prometheus-community/prometheus[root@k8s-master prometheus]# lsprometheus-14.6.1.tgz [root@k8s-master prometheus]# tar -xf prometheus-14.6.1.tgz [root@k8s-master prometheus]# cd prometheus/[root@k8s-master prometheus]# lsChart.lock  charts  Chart.yaml  README.md  templates  values.yaml
  • prometheus-serverprometheus-alertmanager两个字段PVC勾销掉 正式环境须要先
    部署PVC存储卷
[root@k8s-master prometheus]# vim values.yaml   persistentVolume:    ## If true, alertmanager will create/use a Persistent Volume Claim    ## If false, use emptyDir    ##    enabled: false  #批改为false#配置prometheus、alertmanager  ingress hostsingress:    ## If true, pushgateway Ingress will be created    ##    enabled: true    ingressClassName: nginx   #存在多个ingress 指定应用 ingress-nginx    hosts:         - prometheus.com...    hosts:        - alertmanager.com
  • 部署装置
[root@k8s-master prometheus]#  helm install prometheus  prometheus  -n monitorNAME: prometheusLAST DEPLOYED: Sat Sep 18 15:40:47 2021NAMESPACE: monitorSTATUS: deployedREVISION: 1TEST SUITE: NoneNOTES:The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:prometheus-server.monitor.svc.cluster.local[root@k8s-master prometheus]# kubectl get pod  -n monitorNAME                                             READY   STATUS    RESTARTS   AGEprometheus-alertmanager-769488c787-h9s7z         2/2     Running   0          2d21hprometheus-kube-state-metrics-68b6c8b5c5-fgqjg   1/1     Running   0          2d21hprometheus-node-exporter-hfw4c                   1/1     Running   0          2d21hprometheus-node-exporter-rzjzj                   1/1     Running   0          2d21hprometheus-node-exporter-vhr9p                   1/1     Running   0          2d21hprometheus-pushgateway-8655bf87b9-xwzjx          1/1     Running   0          2d21hprometheus-server-7df4f9b485-7pz8j               2/2     Running   0          2d21h[root@k8s-master prometheus]# kubectl get svc -n monitorNAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGEprometheus-alertmanager         ClusterIP   10.96.135.142    <none>        80/TCP     2d21hprometheus-kube-state-metrics   ClusterIP   10.96.153.83     <none>        8080/TCP   2d21hprometheus-node-exporter        ClusterIP   None             <none>        9100/TCP   2d21hprometheus-pushgateway          ClusterIP   10.109.40.211    <none>        9091/TCP   2d21hprometheus-server               ClusterIP   10.104.231.248   <none>        80/TCP     2d21h[root@k8s-master prometheus]# kubectl get ingress -n monitorNAME                      CLASS   HOSTS              ADDRESS           PORTS   AGEprometheus-alertmanager   nginx   alertmanager.com   192.168.103.211   80      2d21hprometheus-server         nginx   prometheus.com     192.168.103.211   80      2d21h[root@k8s-master prometheus]# kubectl get svc -n ingress-nginxNAME                                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGEingress-nginx-controller             NodePort    10.108.78.161    <none>        80:32601/TCP,443:31371/TCP   85dingress-nginx-controller-admission   ClusterIP   10.101.146.205   <none>        443/TCP                      85d
  • 拜访主机增加hosts
    192.168.103.211 prometheus.com
  • 关上浏览器拜访prometheus http://prometheus.com:32601