Prometheus基于自动服务发现获取peer/orderer监控数据

2019-06-11 19:37:15 浏览数 (1)

Fabric 1.4支持通过pometheus获取到Fabric网络中的一些状态数据。当Fabric部署在K8s环境中的时候,prometheus可以配置成基于自动服务发现获取到所有的Fabric peer和 orderer的状态数据。

具体配置步骤如下 :

1. 配置ClusterRole并设置相应的权限

apiVersion: rbac.authorization.k8s.io/v1

kind: ClusterRole

metadata:

name: fabricprometheus

rules:

- apiGroups: [""]

resources:

- pods

verbs: ["get", "list", "watch"]

2. 创建ServiceAccount

apiVersion: v1

kind: ServiceAccount

metadata:

name: fabricprometheus

namespace: default

3. ServiceAccount ClusterRole绑定

apiVersion: rbac.authorization.k8s.io/v1

kind: ClusterRoleBinding

metadata:

name: fabricprometheus

roleRef:

apiGroup: rbac.authorization.k8s.io

kind: ClusterRole

name: fabricprometheus

subjects:

- kind: ServiceAccount

name: fabricprometheus

namespace: default

4. ConfigMap配置prometheus配置文件

apiVersion: v1

kind: ConfigMap

metadata:

name: fabric-prometheus-config

namespace: default

data:

prometheus.yml: |

global:

scrape_interval: 15s

evaluation_interval: 15s

scrape_configs:

- job_name: 'fabric-kubernetes-pods'

kubernetes_sd_configs:

- role: pod

relabel_configs:

- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]

action: keep

regex: true

- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]

action: replace

target_label: __metrics_path__

regex: (. )

- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]

action: replace

regex: ([^:] )(?::d )?;(d )

replacement: $1:$2

target_label: __address__

- action: labelmap

regex: __meta_kubernetes_pod_label_(. )

- source_labels: [__meta_kubernetes_namespace]

action: replace

target_label: kubernetes_namespace

- source_labels: [__meta_kubernetes_pod_name]

action: replace

target_label: kubernetes_pod_name

- source_labels: [__meta_kubernetes_pod_name]

action: replace

target_label: pod_name

5. Prometheus deploy 配置

apiVersion: apps/v1beta2

kind: Deployment

metadata:

labels:

name: fabric-prometheus-deployment

name: fabric-prometheus

namespace: default

spec:

replicas: 1

selector:

matchLabels:

app: fabric-prometheus

template:

metadata:

labels:

app: fabric-prometheus

spec:

containers:

- image: prom/prometheus:latest

name: fabric-prometheus

command:

- "/bin/prometheus"

args:

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

- "--storage.tsdb.path=/prometheus"

- "--storage.tsdb.retention=24h"

ports:

- containerPort: 9090

protocol: TCP

volumeMounts:

- mountPath: "/prometheus"

name: data

- mountPath: "/etc/prometheus"

name: config-volume

resources:

requests:

cpu: 100m

memory: 100Mi

limits:

cpu: 500m

memory: 2500Mi

serviceAccountName: fabricprometheus

volumes:

- name: data

emptyDir: {}

- name: config-volume

configMap:

name: fabric-prometheus-config

6. Service配置

kind: Service

apiVersion: v1

metadata:

labels:

app: fabric-prometheus

name: fabric-prometheus

namespace: default

spec:

type: ClusterIP

ports:

- port: 9090

protocol: TCP

targetPort: 9090

selector:

app: fabric-prometheus

7. 在需要查询的peer/orderer节点增加如下配置

template:

metadata:

annotations:

prometheus.io/path: /metrics

prometheus.io/port: "9443"

prometheus.io/scrape: "true"

8. 查询prometheus数据

curl http://xx.xx.xx.xx:9090/api/v1/query -X POST -H "application/x-www-form-urlencoded" -d 'query=up'

0 人点赞