Prometheus cluster monitoring k8s

1, wherein

Prometheus main features are:

  • A multidimensional data model, wherein the data comprises a sequence identified by time metric name and key / value

  • PromQL, one kind of flexible query language , you can use this dimension

  • It does not depend on the distributed storage; single server node is autonomous

  • Collecting time-series by the HTTP pull model

  • Gateway support via an intermediate push time series

  • Static configuration or through service discovery to find the target

  • A variety of graphics and dashboards support mode

2, components

Prometheus ecosystem comprising a plurality of components, many of which are optional:

Most components are used Prometheus Go written, it is easy to build and deploy static binaries.

3, architecture

The following diagram illustrates the architecture of ecosystem and certain components of Prometheus:

architecture.png

        Prometheus deleted from the index operation has been detected directly or through an intermediary push gateway, for short-term operations. It stores all the local scrap samples, and these data operating rules, in summary and record the new time series existing data or generate alerts. Grafana or other user API can be used to visualize the collected data.

4, installation

Premise requires helm environment:

image-20191226101438796.png

helm  install  prometheus   stable/prometheus

image-20191226102249663.png

安装成功,查看pod状态会发现有两个处于pending状态,是因为需要请求pv

image-20191226102456756.png

这里使用hostPath来创建pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: prometheus-pv1
spec:
  capacity:
    storage: 2Gi
  volumeMode: Filesystem
  accessModes:
  -  ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /app/prometheus/pv1

image-20191226104015715.png

查看pod状态会发现有个pod会报错,并查看日志是报错是容器名不同

image-20191226110521033.png

真正的原因是因为使用的hoatPath,pvc请求的权限不够,到worker节点给对应的hostpath加777的权限即可,这是我通过rancher查看到的报错

msg="Error opening query log file" file=/data/queries.active err="open /data/queries.active: permission denied"

5、访问web界面

image-20191226110837974.png

这里还需要修改Prometheus-server的Port类型为NodePort。

image-20191226111719532.png

6、安装grafana

helm  pull  stable/grafana

tar xvf grafana-4.2.2.tgz

vim grafana/values.yaml    #设置admin的密码为admin123

image-20191226123259170.png

helm  install grafana  ./grafana

image-20191226112115185.png

由于grafana没有使用持久存储,根据需求修改为hostpath持久存储,需要注意的是,宿主机目录也需要777的权限

image-20191226112409792.png

Also you need to be diverted to svc grafana type NodePort

image-20191226112700284.png

Access the web interface, user admin, password: admin123

image-20191226112917716.png

7, import Prometheus

image-20191226123838456.png

image-20191226123903143.png

Fill in the address of Prometheus

image-20191226124039501.png

Said verification by

image-20191226124212726.png

Importing templates grafana

image-20191226124257031.png

image-20191226124315485.png

image-20191226124336333.png

Here select Prometheus

image-20191226124409629.png

Gray often to see the gorgeous dashboard

image-20191226124450163.png

Here are a few numbers template:

10000,315,7249,5228,8685,8588

Perfect ending!


Guess you like

Origin blog.51cto.com/14268033/2462243