K8s canal real-time index monitoring based on Prometheus

itread01 2020-11-06 20:52:00
k8s canal real-time real time


[ The article comes from my impression notes , If there is a format problem, you can visit the link to view the original text ](https://app.yinxiang.com/fx/c1c8b0bd-1d81-4b3b-ac75-e05bd0955e6f) ## Deploy canal Of prometheus Monitoring of k8s in 1、grafana Of docker Deployment way ;https://grafana.com/grafana/download?platform=docker 2、prometheus Of docker Deployment way : https://github.com/prometheus/prometheus With ready-made docker After mapping , Direct deployment ; ## k8s Deployment in China prometheus yml Arrange the file as follows : ``` --- apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: '16' k8s.kuboard.cn/displayName: canal-prometheus k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort k8s.kuboard.cn/workload: svc-canal-prometheus creationTimestamp: '2020-11-06T03:09:55Z' generation: 16 labels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: svc-canal-prometheus name: svc-canal-prometheus namespace: canal-ns resourceVersion: '22246892' selfLink: /apis/apps/v1/namespaces/canal-ns/deployments/svc-canal-prometheus uid: 4ad37eec-3b36-4107-8ed9-07456abba5ba spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: svc-canal-prometheus strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: annotations: kubectl.kubernetes.io/restartedAt: '2020-11-06T14:07:33+08:00' labels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: svc-canal-prometheus spec: containers: - image: prom/prometheus imagePullPolicy: Always name: canal-prometheus terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /etc/prometheus/prometheus.yml name: canal-prometheus-volume subPath: etc/prometheus/prometheus.yml dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler terminationGracePeriodSeconds: 30 volumes: - configMap: defaultMode: 420 items: - key: prometheus.yml path: etc/prometheus/prometheus.yml name: canal-prometheus name: canal-prometheus-volume status: availableReplicas: 1 conditions: - lastTransitionTime: '2020-11-06T05:30:16Z' lastUpdateTime: '2020-11-06T05:30:16Z' message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: 'True' type: Available - lastTransitionTime: '2020-11-06T05:55:49Z' lastUpdateTime: '2020-11-06T06:07:43Z' message: >- ReplicaSet "svc-canal-prometheus-6f7d7b66c5" has successfully progressed. reason: NewReplicaSetAvailable status: 'True' type: Progressing observedGeneration: 16 readyReplicas: 1 replicas: 1 updatedReplicas: 1 ``` One interesting point here is ,k8s Use in configMap When you mount a directory , Generally, we directly mount it to the corresponding container directory , At this point, the directory will be covered , At this time, when configuring the file mapping of Prometheus , It's just mounted to a specific file ; The main configuration is :subPath: etc/prometheus/prometheus.yml, Through subPath Can be directly mounted to a specific file ; [ Original announcement : author :Arnold.zhao Blog Park Address :https://www.cnblogs.com/zh94](https://www.cnblogs.com/zh94) The contents of the attached configuration file are as follows : ``` # my global config test global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job= ` to any timeseries scraped from this config. - job_name: 'canal' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['svc-canal-deployer:11112'] ``` It mainly refers to the corresponding configuration canal-deployer The address of ; - targets: ['svc-canal-deployer:11112'] By default canal-deployer The monitoring port is 11112, Of course, if you modify the port , In other words . svc-canal-deployer yes canal-deployer Of server Name , Because of canal-deployer This is also deployed in k8s So use the service name to access directly , from k8s service Automatic forwarding can be done , If this is not in k8s And then , Then directly configure canal-deployer Of ip address , The same . Corresponding configMap The establishment of the yml as follows : ``` --- apiVersion: v1 data: prometheus.yml: >- # my global config test global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job= ` to any timeseries scraped from this config. - job_name: 'canal' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['svc-canal-deployer:11112'] kind: ConfigMap metadata: creationTimestamp: '2020-11-06T03:15:04Z' name: canal-prometheus namespace: canal-ns resourceVersion: '22246778' selfLink: /api/v1/namespaces/canal-ns/configmaps/canal-prometheus uid: 2918cb4e-acd6-4c82-9a2e-19e575ba6cea ``` Create a dedicated Service For the port , Here, the corresponding port is 9090 ``` --- apiVersion: v1 kind: Service metadata: annotations: k8s.kuboard.cn/displayName: canal-prometheus k8s.kuboard.cn/workload: svc-canal-prometheus creationTimestamp: '2020-11-06T03:11:34Z' labels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: svc-canal-prometheus name: svc-canal-prometheus namespace: canal-ns resourceVersion: '22204370' selfLink: /api/v1/namespaces/canal-ns/services/svc-canal-prometheus uid: 6246dafe-f8fd-42ec-8e27-caf38539d35c spec: clusterIP: 10.204.71.228 externalTrafficPolicy: Cluster ports: - name: prometheus-9090 nodePort: 30018 port: 9090 protocol: TCP targetPort: 9090 selector: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: svc-canal-prometheus sessionAffinity: None type: NodePort ``` Okay , Deployment completed , At this time, the port access results are as follows : ![](https://img2020.cnblogs.com/blog/1104472/202011/1104472-20201106162822540-2081171840.png) ## Deploy grafana Deployment Of yml as follows ``` --- apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: '1' k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort k8s.kuboard.cn/workload: web-canal-grafana creationTimestamp: '2020-11-06T06:10:27Z' generation: 1 labels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: web-canal-grafana name: web-canal-grafana namespace: canal-ns resourceVersion: '22247823' selfLink: /apis/apps/v1/namespaces/canal-ns/deployments/web-canal-grafana uid: 484350e4-b408-4361-ac27-633f8d815468 spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: web-canal-grafana strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: web-canal-grafana spec: containers: - image: grafana/grafana imagePullPolicy: Always name: canal-grafana resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsConfig: {} dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: seLinuxOptions: {} terminationGracePeriodSeconds: 30 ``` Do it again server agent ,yml as follows ; The opposite port is 3000 Port ``` --- apiVersion: v1 kind: Service metadata: annotations: k8s.kuboard.cn/workload: web-canal-grafana creationTimestamp: '2020-11-06T06:10:27Z' labels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: web-canal-grafana name: web-canal-grafana namespace: canal-ns resourceVersion: '22247699' selfLink: /api/v1/namespaces/canal-ns/services/web-canal-grafana uid: 8cbde138-6855-4eaf-b9cd-8dae72a2efeb spec: clusterIP: 10.204.195.124 externalTrafficPolicy: Cluster ports: - name: canal-grafana-3000 nodePort: 31010 port: 3000 protocol: TCP targetPort: 3000 selector: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: web-canal-grafana sessionAffinity: None type: NodePort ``` OK, After starting , After accessing the corresponding application , The effect is as shown in the picture : ![](https://img2020.cnblogs.com/blog/1104472/202011/1104472-20201106162836466-246527803.png) It's not going on yet grefana Configuration of , So you can't get canal Monitoring information of ## Greafana To configure canal Monitoring information It's simple , Basically follow the official instructions , Create a new one dataSource, Choice prometheus, Then fill in the corresponding prometheus Of url address . ![](https://img2020.cnblogs.com/blog/1104472/202011/1104472-20201106162851539-1562379402.png) ![](https://img2020.cnblogs.com/blog/1104472/202011/1104472-20201106162906287-392654020.png) When you're done , The last step is ,grafana Import from China canal Monitoring indicators of ![](https://img2020.cnblogs.com/blog/1104472/202011/1104472-20201106162916615-95201631.png) At this point according to URL How to import :https://raw.githubusercontent.com/alibaba/canal/master/deployer/src/main/resources/metrics/Canal_instances_tmpl.json Import the json Just file ; But when I was dealing with it , The url Import is not available , therefore , If you're not available either , Can directly wget https://raw.githubusercontent.com/alibaba/canal/master/deployer/src/main/resources/metrics/Canal_instances_tmpl.json After obtaining the corresponding file content , Fill in the second box ; ## The final monitoring effect picture [ Original announcement : author :Arnold.zhao Blog Park Address :https://www.cnblogs.com/zh94](https://www.cnblogs.com/zh94) ![](https://img2020.cnblogs.com/blog/1104472/202011/1104472-20201106162925338-1996296800.png) The specific meaning of each monitoring indicator , Look directly at github canal File can ; Because of this, my canal client Not directly through tcp And canal -deployer Interact , It's direct access canal-deployer What you spit out kakfa Information , So what's shown here is client The indicator is empty ; Reference link : [ About Prometheus (prometheus) Basic concepts of ](https://www.cnblogs.com/chenqionghe/p/10494868.html) [ About Grafana Basic concepts of ](https://blog.csdn.net/freeking101/article/details/105844927/) [ About canal Install Grafana&prometheus Instructions for monitoring ](https://github.com/alibaba/canal/wiki/Prometheus-QuickStart) [ About k8s The usage of the container's original directory is not covered when the directory is mounted in ](https://www.cnblogs.com/weifeng1463/p/1133231
版权声明
本文为[itread01]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云