加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 云计算 > 正文

借助Prometheus监控Flink

发布时间:2022-07-16 15:33:06 所属栏目:云计算 来源:互联网
导读:为什么选择Prometheus? 随着深入地了解Prometheus,你会发现一些非常好的功能: 服务发现使配置更加容易。Prometheus支持consul,etcd,kubernetes以及各家公有云厂商自动发现。对于监控目标动态发现,这点特别契合Cloud时代,应用动态扩缩的特点。我们无法
  为什么选择Prometheus?
  随着深入地了解Prometheus,你会发现一些非常好的功能:
 
  服务发现使配置更加容易。Prometheus支持consul,etcd,kubernetes以及各家公有云厂商自动发现。对于监控目标动态发现,这点特别契合Cloud时代,应用动态扩缩的特点。我们无法想象,在Cloud时代,需要运维不断更改配置。
   Pushgateway,Alermanager等组件,基本上涵盖了一个完整的监控生命周期。
  Flink官方已经提供了对接Prometheus的jar包,很方便就可以集成。由于本系列文章重点在Flink on Kubernetes, 因此我们所有的操作都是基于这点展开。
  部署Prometheus
  对k8s不熟悉的同学,可以查阅k8s相关文档。由于部署不是本博客的重点,所以我们直接贴出yaml文件:
 
  ---
      apiVersion: v1
      kind: ServiceAccount
      metadata:
   ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRole
      metadata:
        name: monitor
        labels:
          kubernetes.io/cluster-service: "true"
          addonmanager.kubernetes.io/mode: Reconcile
      rules:
        - apiGroups:
            - ""
          resources:
            - pods
          verbs:
            - get
            - list
            - watch
  ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRoleBinding
      metadata:
        name: monitor
        labels:
          kubernetes.io/cluster-service: "true"
          addonmanager.kubernetes.io/mode: Reconcile
      roleRef:
        apiGroup: rbac.authorization.k8s.io
             prometheus.yml: |-
              global:
                  scrape_interval:     10s
                  evaluation_interval: 10s
                
              scrape_configs:
                - job_name: kubernetes-pods
                  kubernetes_sd_configs:
                  - role: pod
                  relabel_configs:
                  - action: keep
                    regex: true
                    source_labels:
                    - __meta_kubernetes_pod_annotation_prometheus_io_scrape
                  - action: replace
                    regex: (.+)
                    source_labels:
                    - __meta_kubernetes_pod_annotation_prometheus_io_path
                    target_label: __metrics_path__
                  - action: replace
                    regex: ([^:]+)(?::d+)?;(d+)
                    replacement: $1:$2
                    source_labels:
                    - __address__
                    - __meta_kubernetes_pod_annotation_prometheus_io_port
                    target_label: __address__
                  - action: labelmap
                    regex: __meta_kubernetes_pod_label_(.+)
                  - action: replace
                    source_labels:
                    - __meta_kubernetes_namespace
                    target_label: kubernetes_namespace
                  - action: replace
                    source_labels:
                    - __meta_kubernetes_pod_name
                    target_label: kubernetes_pod_name
          
  ---
          apiVersion: apps/v1
          kind: StatefulSet
          metadata:
            labels:
              app: monitor
            name: monitor
            namespace: kube-system
          spec:
            serviceName: monitor
            selector:
              matchLabels:
                app: monitor
            replicas: 1
            template:
              metadata:
                labels:
                  app: monitor
              spec:
                containers:
                - args:
                  - --config.file=/etc/prometheus/prometheus.yml
                  - --storage.tsdb.path=/data/prometheus
                  - --storage.tsdb.retention.time=10d
                  image: prom/prometheus:v2.19.0
                  imagePullPolicy: IfNotPresent
                  name: prometheus
                  ports:
                  - containerPort: 9090
                    protocol: TCP
                  readinessProbe:
                    httpGet:
                      path: /-/ready
                      port: 9090
                    initialDelaySeconds: 30
                    timeoutSeconds: 30
                  livenessProbe:
                    httpGet:
                      path: /-/healthy
                      port: 9090
                    initialDelaySeconds: 30
                    timeoutSeconds: 30
                  resources:
                    limits:
                      cpu: 1000m

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读