由于docker容器的特殊性,传统的zabbix无法对k8s集群内的docker状态进行监控,所以需要使用prometheus来进行监控:

什么是Prometheus?

Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。

2016年由Google发起Linux基金会旗下的原生云基金会(Cloud Native Computing Foundation), 将Prometheus纳入其下第二大开源项目。

Prometheus目前在开源社区相当活跃。

Prometheus和Heapster(Heapster是K8S的一个子项目,用于获取集群的性能数据。)相比功能更完善、更全面。Prometheus性能也足够支撑上万台规模的集群。

Prometheus的特点

    • 多维度数据模型。
    • 灵活的查询语言。
    • 不依赖分布式存储,单个服务器节点是自主的。
    • 通过基于HTTP的pull方式采集时序数据。
    • 可以通过中间网关进行时序列数据推送。
    • 通过服务发现或者静态配置来发现目标服务对象。
    • 支持多种多样的图表和界面展示,比如Grafana等。

基本原理

Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控。不需要任何SDK或者其他的集成过程。这样做非常适合做虚拟化环境监控系统,比如VM、Docker、Kubernetes等。输出被监控组件信息的HTTP接口被叫做exporter 。目前互联网公司常用的组件大部分都有exporter可以直接使用,比如Varnish、Haproxy、Nginx、MySQL、Linux系统信息(包括磁盘、内存、CPU、网络等等)。

服务过程

  • Prometheus Daemon负责定时去目标上抓取metrics(指标)数据,每个抓取目标需要暴露一个http服务的接口给它定时抓取。Prometheus支持通过配置文件、文本文件、Zookeeper、Consul、DNS SRV Lookup等方式指定抓取目标。Prometheus采用PULL的方式进行监控,即服务器可以直接通过目标PULL数据或者间接地通过中间网关来Push数据。
  • Prometheus在本地存储抓取的所有数据,并通过一定规则进行清理和整理数据,并把得到的结果存储到新的时间序列中。
  • Prometheus通过PromQL和其他API可视化地展示收集的数据。Prometheus支持很多方式的图表可视化,例如Grafana、自带的Promdash以及自身提供的模版引擎等等。Prometheus还提供HTTP API的查询方式,自定义所需要的输出。
  • PushGateway支持Client主动推送metrics到PushGateway,而Prometheus只是定时去Gateway上抓取数据。
  • Alertmanager是独立于Prometheus的一个组件,可以支持Prometheus的查询语句,提供十分灵活的报警方式。

三大套件

  • Server 主要负责数据采集和存储,提供PromQL查询语言的支持。
  • Alertmanager 警告管理器,用来进行报警。
  • Push Gateway 支持临时性Job主动推送指标的中间网关。

prometheus不同于zabbix,没有agent,使用的是针对不同服务的exporter:

prometheus官网:官网地址

正常情况下,监控k8s集群及node,pod,常用的exporter有四个:

  • kube-state-metrics -- 收集k8s集群master&etcd等基本状态信息
  • node-exporter -- 收集k8s集群node信息
  • cadvisor -- 收集k8s集群docker容器内部使用资源信息
  • blackbox-exporte -- 收集k8s集群docker容器服务是否存活

接下来逐一创建以上exporter:

老套路,下载docker镜像,准备资源配置清单,应用资源配置清单:

一、kube-state-metrics

  1. # docker pull quay.io/coreos/kube-state-metrics:v1.5.0
  1. # docker tag 91599517197a harbor.od.com/public/kube-state-metrics:v1.5.0
  2. # docker push harbor.od.com/public/kube-state-metrics:v1.5.0

准备资源配置清单:

1、rbac.yaml

  1. # mkdir /data/k8s-yaml/kube-state-metrics && cd /data/k8s-yaml/kube-state-metrics
  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. labels:
  5. addonmanager.kubernetes.io/mode: Reconcile
  6. kubernetes.io/cluster-service: "true"
  7. name: kube-state-metrics
  8. namespace: kube-system
  9. ---
  10. apiVersion: rbac.authorization.k8s.io/v1
  11. kind: ClusterRole
  12. metadata:
  13. labels:
  14. addonmanager.kubernetes.io/mode: Reconcile
  15. kubernetes.io/cluster-service: "true"
  16. name: kube-state-metrics
  17. rules:
  18. - apiGroups:
  19. - ""
  20. resources:
  21. - configmaps
  22. - secrets
  23. - nodes
  24. - pods
  25. - services
  26. - resourcequotas
  27. - replicationcontrollers
  28. - limitranges
  29. - persistentvolumeclaims
  30. - persistentvolumes
  31. - namespaces
  32. - endpoints
  33. verbs:
  34. - list
  35. - watch
  36. - apiGroups:
  37. - policy
  38. resources:
  39. - poddisruptionbudgets
  40. verbs:
  41. - list
  42. - watch
  43. - apiGroups:
  44. - extensions
  45. resources:
  46. - daemonsets
  47. - deployments
  48. - replicasets
  49. verbs:
  50. - list
  51. - watch
  52. - apiGroups:
  53. - apps
  54. resources:
  55. - statefulsets
  56. verbs:
  57. - list
  58. - watch
  59. - apiGroups:
  60. - batch
  61. resources:
  62. - cronjobs
  63. - jobs
  64. verbs:
  65. - list
  66. - watch
  67. - apiGroups:
  68. - autoscaling
  69. resources:
  70. - horizontalpodautoscalers
  71. verbs:
  72. - list
  73. - watch
  74. ---
  75. apiVersion: rbac.authorization.k8s.io/v1
  76. kind: ClusterRoleBinding
  77. metadata:
  78. labels:
  79. addonmanager.kubernetes.io/mode: Reconcile
  80. kubernetes.io/cluster-service: "true"
  81. name: kube-state-metrics
  82. roleRef:
  83. apiGroup: rbac.authorization.k8s.io
  84. kind: ClusterRole
  85. name: kube-state-metrics
  86. subjects:
  87. - kind: ServiceAccount
  88. name: kube-state-metrics
  89. namespace: kube-system

2、dp.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. deployment.kubernetes.io/revision: "2"
  6. labels:
  7. grafanak8sapp: "true"
  8. app: kube-state-metrics
  9. name: kube-state-metrics
  10. namespace: kube-system
  11. spec:
  12. selector:
  13. matchLabels:
  14. grafanak8sapp: "true"
  15. app: kube-state-metrics
  16. strategy:
  17. rollingUpdate:
  18. maxSurge: 25%
  19. maxUnavailable: 25%
  20. type: RollingUpdate
  21. template:
  22. metadata:
  23. labels:
  24. grafanak8sapp: "true"
  25. app: kube-state-metrics
  26. spec:
  27. containers:
  28. - name: kube-state-metrics
  29. image: harbor.od.com/public/kube-state-metrics:v1.5.0
  30. imagePullPolicy: IfNotPresent
  31. ports:
  32. - containerPort: 8080
  33. name: http-metrics
  34. protocol: TCP
  35. readinessProbe:
  36. failureThreshold: 3
  37. httpGet:
  38. path: /healthz
  39. port: 8080
  40. scheme: HTTP
  41. initialDelaySeconds: 5
  42. periodSeconds: 10
  43. successThreshold: 1
  44. timeoutSeconds: 5
  45. serviceAccountName: kube-state-metrics

应用资源配置清单:

  1. # kubectl apply -f http://k8s-yaml.od.com/kube-state-metrics/rbac.yaml
  2. # kubectl apply -f http://k8s-yaml.od.com/kube-state-metrics/dp.yaml

测试一下:

  1. # kubectl get pod -n kube-system -o wide

  1. # curl http://172.7.22.10:8080/healthz

已经成功运行。

二、node-exporter

由于node-exporter是监控node的,所有需要每个节点启动一个,所以使用ds控制器

  1. # docker pull prom/node-exporter:v0.15.0
  1. # docker tag 12d51ffa2b22 harbor.od.com/public/node-exporter:v0.15.0
  2. # docker push harbor.od.com/public/node-exporter:v0.15.0

准备资源配置清单:

1、ds.yaml

  1. # mkdir node-exporter && cd node-exporter
  1. kind: DaemonSet
  2. apiVersion: extensions/v1beta1
  3. metadata:
  4. name: node-exporter
  5. namespace: kube-system
  6. labels:
  7. daemon: "node-exporter"
  8. grafanak8sapp: "true"
  9. spec:
  10. selector:
  11. matchLabels:
  12. daemon: "node-exporter"
  13. grafanak8sapp: "true"
  14. template:
  15. metadata:
  16. name: node-exporter
  17. labels:
  18. daemon: "node-exporter"
  19. grafanak8sapp: "true"
  20. spec:
  21. volumes:
  22. - name: proc
  23. hostPath:
  24. path: /proc
  25. type: ""
  26. - name: sys
  27. hostPath:
  28. path: /sys
  29. type: ""
  30. containers:
  31. - name: node-exporter
  32. image: harbor.od.com/public/node-exporter:v0.15.0
  33. imagePullPolicy: IfNotPresent
  34. args:
  35. - --path.procfs=/host_proc
  36. - --path.sysfs=/host_sys
  37. ports:
  38. - name: node-exporter
  39. hostPort: 9100
  40. containerPort: 9100
  41. protocol: TCP
  42. volumeMounts:
  43. - name: sys
  44. readOnly: true
  45. mountPath: /host_sys
  46. - name: proc
  47. readOnly: true
  48. mountPath: /host_proc
  49. hostNetwork: true

应用资源配置清单:

  1. # kubectl apply -f http://k8s-yaml.od.com/node-exporter/ds.yaml
  1. # kubectl get pod -n kube-system -o wide

我们有两个node,每个node节点启动一个:

三、cadvisor

  1. # docker pull google/cadvisor:v0.28.3
  1. # docker tag 75f88e3ec333 harbor.od.com/public/cadvisor:0.28.3
  1. # docker push harbor.od.com/public/cadvisor:0.28.3

准备资源配置清单:

  1. # mkdir cadvisor && cd cadvisor

1、ds.yaml  标红部分是k8s资源配置清单中一个重要的高级属性,下一篇博客着重介绍

  1. apiVersion: apps/v1
  2. kind: DaemonSet
  3. metadata:
  4. name: cadvisor
  5. namespace: kube-system
  6. labels:
  7. app: cadvisor
  8. spec:
  9. selector:
  10. matchLabels:
  11. name: cadvisor
  12. template:
  13. metadata:
  14. labels:
  15. name: cadvisor
  16. spec:
  17. hostNetwork: true
  18. tolerations:
  19. - key: node-role.kubernetes.io/master
  20. effect: NoSchedule
  21. containers:
  22. - name: cadvisor
  23. image: harbor.od.com/public/cadvisor:v0.28.3
  24. imagePullPolicy: IfNotPresent
  25. volumeMounts:
  26. - name: rootfs
  27. mountPath: /rootfs
  28. readOnly: true
  29. - name: var-run
  30. mountPath: /var/run
  31. - name: sys
  32. mountPath: /sys
  33. readOnly: true
  34. - name: docker
  35. mountPath: /var/lib/docker
  36. readOnly: true
  37. ports:
  38. - name: http
  39. containerPort: 4194
  40. protocol: TCP
  41. readinessProbe:
  42. tcpSocket:
  43. port: 4194
  44. initialDelaySeconds: 5
  45. periodSeconds: 10
  46. args:
  47. - --housekeeping_interval=10s
  48. - --port=4194
  49. terminationGracePeriodSeconds: 30
  50. volumes:
  51. - name: rootfs
  52. hostPath:
  53. path: /
  54. - name: var-run
  55. hostPath:
  56. path: /var/run
  57. - name: sys
  58. hostPath:
  59. path: /sys
  60. - name: docker
  61. hostPath:
  62. path: /data/docker

针对挂载资源,做一些调整:

  1. # mount -o remount,rw /sys/fs/cgroup/
  2. # ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu

应用资源配置清单:

  1. # kubectl apply -f http://k8s-yaml.od.com/cadvisor/ds.yaml

检查:

四、blackbox-exporter

  1. # docker pull prom/blackbox-exporter:v0.15.1
  1. # docker tag 81b70b6158be harbor.od.com/public/blackbox-exporter:v0.15.1
  2. # docker push harbor.od.com/public/blackbox-exporter:v0.15.1

创建资源配置清单:

1、cm.yaml

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. labels:
  5. app: blackbox-exporter
  6. name: blackbox-exporter
  7. namespace: kube-system
  8. data:
  9. blackbox.yml: |-
  10. modules:
  11. http_2xx:
  12. prober: http
  13. timeout: 2s
  14. http:
  15. valid_http_versions: ["HTTP/1.1", "HTTP/2"]
  16. valid_status_codes: [200,301,302]
  17. method: GET
  18. preferred_ip_protocol: "ip4"
  19. tcp_connect:
  20. prober: tcp
  21. timeout: 2s

2、dp.yaml

  1. kind: Deployment
  2. apiVersion: extensions/v1beta1
  3. metadata:
  4. name: blackbox-exporter
  5. namespace: kube-system
  6. labels:
  7. app: blackbox-exporter
  8. annotations:
  9. deployment.kubernetes.io/revision: 1
  10. spec:
  11. replicas: 1
  12. selector:
  13. matchLabels:
  14. app: blackbox-exporter
  15. template:
  16. metadata:
  17. labels:
  18. app: blackbox-exporter
  19. spec:
  20. volumes:
  21. - name: config
  22. configMap:
  23. name: blackbox-exporter
  24. defaultMode: 420
  25. containers:
  26. - name: blackbox-exporter
  27. image: harbor.od.com/public/blackbox-exporter:v0.15.1
  28. imagePullPolicy: IfNotPresent
  29. args:
  30. - --config.file=/etc/blackbox_exporter/blackbox.yml
  31. - --log.level=info
  32. - --web.listen-address=:9115
  33. ports:
  34. - name: blackbox-port
  35. containerPort: 9115
  36. protocol: TCP
  37. resources:
  38. limits:
  39. cpu: 200m
  40. memory: 256Mi
  41. requests:
  42. cpu: 100m
  43. memory: 50Mi
  44. volumeMounts:
  45. - name: config
  46. mountPath: /etc/blackbox_exporter
  47. readinessProbe:
  48. tcpSocket:
  49. port: 9115
  50. initialDelaySeconds: 5
  51. timeoutSeconds: 5
  52. periodSeconds: 10
  53. successThreshold: 1
  54. failureThreshold: 3

3、svc.yaml

  1. kind: Service
  2. apiVersion: v1
  3. metadata:
  4. name: blackbox-exporter
  5. namespace: kube-system
  6. spec:
  7. selector:
  8. app: blackbox-exporter
  9. ports:
  10. - name: blackbox-port
  11. protocol: TCP
  12. port: 9115

4、ingress.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: blackbox-exporter
  5. namespace: kube-system
  6. spec:
  7. rules:
  8. - host: blackbox.od.com
  9. http:
  10. paths:
  11. - path: /
  12. backend:
  13. serviceName: blackbox-exporter
  14. servicePort: blackbox-port

这里用到了一个域名,添加解析:

  1. # vi /var/named/od.com.zone
  1. blackbox A 10.4.7.10

应用资源配置清单:

  1. # kubectl apply -f http://k8s-yaml.od.com/blackbox-exporter/cm.yaml
  2. # kubectl apply -f http://k8s-yaml.od.com/blackbox-exporter/dp.yaml
  3. # kubectl apply -f http://k8s-yaml.od.com/blackbox-exporter/svc.yaml
  4. # kubectl apply -f http://k8s-yaml.od.com/blackbox-exporter/ingress.yaml

访问域名测试:

访问到以下界面,表示blackbox已经运行成功

 接下来部署prometheus server:

  1. # docker pull prom/prometheus:v2.14.0
  1. # docker tag 7317640d555e harbor.od.com/infra/prometheus:v2.14.0
  2. # docker push harbor.od.com/infra/prometheus:v2.14.0

准备资源配置清单:

1、rbac.yaml

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. labels:
  5. addonmanager.kubernetes.io/mode: Reconcile
  6. kubernetes.io/cluster-service: "true"
  7. name: prometheus
  8. namespace: infra
  9. ---
  10. apiVersion: rbac.authorization.k8s.io/v1
  11. kind: ClusterRole
  12. metadata:
  13. labels:
  14. addonmanager.kubernetes.io/mode: Reconcile
  15. kubernetes.io/cluster-service: "true"
  16. name: prometheus
  17. rules:
  18. - apiGroups:
  19. - ""
  20. resources:
  21. - nodes
  22. - nodes/metrics
  23. - services
  24. - endpoints
  25. - pods
  26. verbs:
  27. - get
  28. - list
  29. - watch
  30. - apiGroups:
  31. - ""
  32. resources:
  33. - configmaps
  34. verbs:
  35. - get
  36. - nonResourceURLs:
  37. - /metrics
  38. verbs:
  39. - get
  40. ---
  41. apiVersion: rbac.authorization.k8s.io/v1
  42. kind: ClusterRoleBinding
  43. metadata:
  44. labels:
  45. addonmanager.kubernetes.io/mode: Reconcile
  46. kubernetes.io/cluster-service: "true"
  47. name: prometheus
  48. roleRef:
  49. apiGroup: rbac.authorization.k8s.io
  50. kind: ClusterRole
  51. name: prometheus
  52. subjects:
  53. - kind: ServiceAccount
  54. name: prometheus
  55. namespace: infra

2、dp.yaml

加上--web.enable-lifecycle启用远程热加载配置文件

调用指令是curl -X POST http://localhost:9090/-/reload

storage.tsdb.min-block-duration=10m #只加载10分钟数据到内

storage.tsdb.retention=72h #保留72小时数据

  1.  
  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. deployment.kubernetes.io/revision: "5"
  6. labels:
  7. name: prometheus
  8. name: prometheus
  9. namespace: infra
  10. spec:
  11. progressDeadlineSeconds: 600
  12. replicas: 1
  13. revisionHistoryLimit: 7
  14. selector:
  15. matchLabels:
  16. app: prometheus
  17. strategy:
  18. rollingUpdate:
  19. maxSurge: 1
  20. maxUnavailable: 1
  21. type: RollingUpdate
  22. template:
  23. metadata:
  24. labels:
  25. app: prometheus
  26. spec:
  27. containers:
  28. - name: prometheus
  29. image: harbor.od.com/infra/prometheus:v2.14.0
  30. imagePullPolicy: IfNotPresent
  31. command:
  32. - /bin/prometheus
  33. args:
  34. - --config.file=/data/etc/prometheus.yml
  35. - --storage.tsdb.path=/data/prom-db
  36. - --storage.tsdb.min-block-duration=10m
  37. - --storage.tsdb.retention=72h
  38. - --web.enable-lifecycle
  39. ports:
  40. - containerPort: 9090
  41. protocol: TCP
  42. volumeMounts:
  43. - mountPath: /data
  44. name: data
  45. resources:
  46. requests:
  47. cpu: "1000m"
  48. memory: "1.5Gi"
  49. limits:
  50. cpu: "2000m"
  51. memory: "3Gi"
  52. imagePullSecrets:
  53. - name: harbor
  54. securityContext:
  55. runAsUser: 0
  56. serviceAccountName: prometheus
  57. volumes:
  58. - name: data
  59. nfs:
  60. server: hdss7-200
  61. path: /data/nfs-volume/prometheus

3、svc.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: prometheus
  5. namespace: infra
  6. spec:
  7. ports:
  8. - port: 9090
  9. protocol: TCP
  10. targetPort: 9090
  11. selector:
  12. app: prometheus

4、ingress.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. annotations:
  5. kubernetes.io/ingress.class: traefik
  6. name: prometheus
  7. namespace: infra
  8. spec:
  9. rules:
  10. - host: prometheus.od.com
  11. http:
  12. paths:
  13. - path: /
  14. backend:
  15. serviceName: prometheus
  16. servicePort: 9090

这里用到一个域名,添加解析:

  1. prometheus A 10.4.7.10

记得重启named服务

创建需要的目录:

  1. # mkdir -p /data/nfs-volume/prometheus/{etc,prom-db}

修改prometheus配置文件:别问为啥这么写,问就是不懂~

  1. # vi /data/nfs-volume/prometheus/etc/prometheus.yml
  1. global:
  2. scrape_interval: 15s
  3. evaluation_interval: 15s
  4. scrape_configs:
  5. - job_name: 'etcd'
  6. tls_config:
  7. ca_file: /data/etc/ca.pem
  8. cert_file: /data/etc/client.pem
  9. key_file: /data/etc/client-key.pem
  10. scheme: https
  11. static_configs:
  12. - targets:
  13. - '10.4.7.12:2379'
  14. - '10.4.7.21:2379'
  15. - '10.4.7.22:2379'
  16. - job_name: 'kubernetes-apiservers'
  17. kubernetes_sd_configs:
  18. - role: endpoints
  19. scheme: https
  20. tls_config:
  21. ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  22. bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  23. relabel_configs:
  24. - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
  25. action: keep
  26. regex: default;kubernetes;https
  27. - job_name: 'kubernetes-pods'
  28. kubernetes_sd_configs:
  29. - role: pod
  30. relabel_configs:
  31. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  32. action: keep
  33. regex: true
  34. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
  35. action: replace
  36. target_label: __metrics_path__
  37. regex: (.+)
  38. - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
  39. action: replace
  40. regex: ([^:]+)(?::\d+)?;(\d+)
  41. replacement: $1:$2
  42. target_label: __address__
  43. - action: labelmap
  44. regex: __meta_kubernetes_pod_label_(.+)
  45. - source_labels: [__meta_kubernetes_namespace]
  46. action: replace
  47. target_label: kubernetes_namespace
  48. - source_labels: [__meta_kubernetes_pod_name]
  49. action: replace
  50. target_label: kubernetes_pod_name
  51. - job_name: 'kubernetes-kubelet'
  52. kubernetes_sd_configs:
  53. - role: node
  54. relabel_configs:
  55. - action: labelmap
  56. regex: __meta_kubernetes_node_label_(.+)
  57. - source_labels: [__meta_kubernetes_node_name]
  58. regex: (.+)
  59. target_label: __address__
  60. replacement: ${1}:10255
  61. - job_name: 'kubernetes-cadvisor'
  62. kubernetes_sd_configs:
  63. - role: node
  64. relabel_configs:
  65. - action: labelmap
  66. regex: __meta_kubernetes_node_label_(.+)
  67. - source_labels: [__meta_kubernetes_node_name]
  68. regex: (.+)
  69. target_label: __address__
  70. replacement: ${1}:4194
  71. - job_name: 'kubernetes-kube-state'
  72. kubernetes_sd_configs:
  73. - role: pod
  74. relabel_configs:
  75. - action: labelmap
  76. regex: __meta_kubernetes_pod_label_(.+)
  77. - source_labels: [__meta_kubernetes_namespace]
  78. action: replace
  79. target_label: kubernetes_namespace
  80. - source_labels: [__meta_kubernetes_pod_name]
  81. action: replace
  82. target_label: kubernetes_pod_name
  83. - source_labels: [__meta_kubernetes_pod_label_grafanak8sapp]
  84. regex: .*true.*
  85. action: keep
  86. - source_labels: ['__meta_kubernetes_pod_label_daemon', '__meta_kubernetes_pod_node_name']
  87. regex: 'node-exporter;(.*)'
  88. action: replace
  89. target_label: nodename
  90. - job_name: 'blackbox_http_pod_probe'
  91. metrics_path: /probe
  92. kubernetes_sd_configs:
  93. - role: pod
  94. params:
  95. module: [http_2xx]
  96. relabel_configs:
  97. - source_labels: [__meta_kubernetes_pod_annotation_blackbox_scheme]
  98. action: keep
  99. regex: http
  100. - source_labels: [__address__, __meta_kubernetes_pod_annotation_blackbox_port, __meta_kubernetes_pod_annotation_blackbox_path]
  101. action: replace
  102. regex: ([^:]+)(?::\d+)?;(\d+);(.+)
  103. replacement: $1:$2$3
  104. target_label: __param_target
  105. - action: replace
  106. target_label: __address__
  107. replacement: blackbox-exporter.kube-system:9115
  108. - source_labels: [__param_target]
  109. target_label: instance
  110. - action: labelmap
  111. regex: __meta_kubernetes_pod_label_(.+)
  112. - source_labels: [__meta_kubernetes_namespace]
  113. action: replace
  114. target_label: kubernetes_namespace
  115. - source_labels: [__meta_kubernetes_pod_name]
  116. action: replace
  117. target_label: kubernetes_pod_name
  118. - job_name: 'blackbox_tcp_pod_probe'
  119. metrics_path: /probe
  120. kubernetes_sd_configs:
  121. - role: pod
  122. params:
  123. module: [tcp_connect]
  124. relabel_configs:
  125. - source_labels: [__meta_kubernetes_pod_annotation_blackbox_scheme]
  126. action: keep
  127. regex: tcp
  128. - source_labels: [__address__, __meta_kubernetes_pod_annotation_blackbox_port]
  129. action: replace
  130. regex: ([^:]+)(?::\d+)?;(\d+)
  131. replacement: $1:$2
  132. target_label: __param_target
  133. - action: replace
  134. target_label: __address__
  135. replacement: blackbox-exporter.kube-system:9115
  136. - source_labels: [__param_target]
  137. target_label: instance
  138. - action: labelmap
  139. regex: __meta_kubernetes_pod_label_(.+)
  140. - source_labels: [__meta_kubernetes_namespace]
  141. action: replace
  142. target_label: kubernetes_namespace
  143. - source_labels: [__meta_kubernetes_pod_name]
  144. action: replace
  145. target_label: kubernetes_pod_name
  146. - job_name: 'traefik'
  147. kubernetes_sd_configs:
  148. - role: pod
  149. relabel_configs:
  150. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme]
  151. action: keep
  152. regex: traefik
  153. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
  154. action: replace
  155. target_label: __metrics_path__
  156. regex: (.+)
  157. - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
  158. action: replace
  159. regex: ([^:]+)(?::\d+)?;(\d+)
  160. replacement: $1:$2
  161. target_label: __address__
  162. - action: labelmap
  163. regex: __meta_kubernetes_pod_label_(.+)
  164. - source_labels: [__meta_kubernetes_namespace]
  165. action: replace
  166. target_label: kubernetes_namespace
  167. - source_labels: [__meta_kubernetes_pod_name]
  168. action: replace
  169. target_label: kubernetes_pod_name

拷贝配置文件中用到的证书:

  1. # cd /data/nfs-volume/prometheus/etc/
    # cp /opt/certs/ca.pem ./
  2. # cp /opt/certs/client.pem ./
  3. # cp /opt/certs/client-key.pem ./

应用资源配置清单:

  1. # kubectl apply -f http://k8s-yaml.od.com/prometheus-server/rbac.yaml
  2. # kubectl apply -f http://k8s-yaml.od.com/prometheus-server/dp.yaml
  3. # kubectl apply -f http://k8s-yaml.od.com/prometheus-server/svc.yaml
  4. # kubectl apply -f http://k8s-yaml.od.com/prometheus-server/ingress.yaml

浏览器验证:prometheus.od.com

这里点击status-targets,这里展示的就是我们在prometheus.yml中配置的job-name,这些targets基本可以满足我们收集数据的需求。

点击status-configuration就是我们的配置文件

我们在配置文件中,除了etcd使用的静态配置以外,其他job都是使用的自动发现。

静态配置:

  1. global:
  2. scrape_interval: 15s
  3. evaluation_interval: 15s
  4. scrape_configs:
  5. - job_name: 'etcd'
  6. tls_config:
  7. ca_file: /data/etc/ca.pem
  8. cert_file: /data/etc/client.pem
  9. key_file: /data/etc/client-key.pem
  10. scheme: https
  11. static_configs:
  12. - targets:
  13. - '10.4.7.12:2379'
  14. - '10.4.7.21:2379'
  15. - '10.4.7.22:2379'

自动发现:自动发现资源是pod

  1. - job_name: 'blackbox_http_pod_probe'
  2. metrics_path: /probe
  3. kubernetes_sd_configs:
  4. - role: pod
  5. params:
  6. module: [http_2xx]
  7. relabel_configs:

这里还有很多数据没有收集到,是因为我们在启动服务的时候,没有添加annotations,下面给需要收集数据的服务添加annotations

1、traefik:

修改traefik的yaml:

从dashboard里找到traefik的yaml,跟labels同级添加annotations

  1. "annotations": {
  2. "prometheus_io_scheme": "traefik",
  3. "prometheus_io_path": "/metrics",
  4. "prometheus_io_port": "8080"
  5. }

等待pod重启以后,在去prometheus上去看

2、blackbox:

这个是检测容器内服务存活性的,也就是端口健康状态检查,分为tcp和http

首先准备两个服务,将dubbo-demo-service和dubbo-demo-consumer都调整为使用master镜像,不依赖apollo的(节省资源)

等两个服务起来以后,首先在dubbo-demo-service资源中添加一个TCP的annotation:

  1. "annotations": {
  2. "blackbox_port": "20880",
  3. "blackbox_scheme": "tcp"
  4. }

这里会自动发现我们服务中,运行tcp port端口为20880的服务,并监控其状态

接下来在dubbo-demo-consumer资源中添加一个HTTP的annotation:

  1. "annotations": {
  2. "blackbox_path": "/hello?name=health",
  3. "blackbox_port": "8080",
  4. "blackbox_scheme": "http"
  5. }

去检查blackbox.od.com

http://blackbox.od.com/

接下来添加监控jvm信息的annotation:

  1. "annotations": {
  2. "prometheus_io_scrape": "true",
  3. "prometheus_io_port": "12346",
  4. "prometheus_io_path": "/"
  5. }

dubbo-demo-service和dubbo-demo-consumer都添加:

匹配规则,要去prometheus.yml中去看。

接下来部署炫酷的dashboard工具grafana:

下载镜像:

  1. # docker pull grafana/grafana:5.4.2
  1. # docker tag 6f18ddf9e552 harbor.od.com/infra/grafana:v5.4.2
  1. # docker push harbor.od.com/infra/grafana:v5.4.2

准备资源配置清单:

1、rbac.yaml

  1. apiVersion: rbac.authorization.k8s.io/v1
  2. kind: ClusterRole
  3. metadata:
  4. labels:
  5. addonmanager.kubernetes.io/mode: Reconcile
  6. kubernetes.io/cluster-service: "true"
  7. name: grafana
  8. rules:
  9. - apiGroups:
  10. - "*"
  11. resources:
  12. - namespaces
  13. - deployments
  14. - pods
  15. verbs:
  16. - get
  17. - list
  18. - watch
  19. ---
  20. apiVersion: rbac.authorization.k8s.io/v1
  21. kind: ClusterRoleBinding
  22. metadata:
  23. labels:
  24. addonmanager.kubernetes.io/mode: Reconcile
  25. kubernetes.io/cluster-service: "true"
  26. name: grafana
  27. roleRef:
  28. apiGroup: rbac.authorization.k8s.io
  29. kind: ClusterRole
  30. name: grafana
  31. subjects:
  32. - kind: User
  33. name: k8s-node

2、dp.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. labels:
  5. app: grafana
  6. name: grafana
  7. name: grafana
  8. namespace: infra
  9. spec:
  10. progressDeadlineSeconds: 600
  11. replicas: 1
  12. revisionHistoryLimit: 7
  13. selector:
  14. matchLabels:
  15. name: grafana
  16. strategy:
  17. rollingUpdate:
  18. maxSurge: 1
  19. maxUnavailable: 1
  20. type: RollingUpdate
  21. template:
  22. metadata:
  23. labels:
  24. app: grafana
  25. name: grafana
  26. spec:
  27. containers:
  28. - name: grafana
  29. image: harbor.od.com/infra/grafana:v5.4.2
  30. imagePullPolicy: IfNotPresent
  31. ports:
  32. - containerPort: 3000
  33. protocol: TCP
  34. volumeMounts:
  35. - mountPath: /var/lib/grafana
  36. name: data
  37. imagePullSecrets:
  38. - name: harbor
  39. securityContext:
  40. runAsUser: 0
  41. volumes:
  42. - nfs:
  43. server: hdss7-200
  44. path: /data/nfs-volume/grafana
  45. name: data
  1. # mkdir /data/nfs-volume/grafana

3、svc.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: grafana
  5. namespace: infra
  6. spec:
  7. ports:
  8. - port: 3000
  9. protocol: TCP
  10. targetPort: 3000
  11. selector:
  12. app: grafana

4、ingress.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: grafana
  5. namespace: infra
  6. spec:
  7. rules:
  8. - host: grafana.od.com
  9. http:
  10. paths:
  11. - path: /
  12. backend:
  13. serviceName: grafana
  14. servicePort: 3000

域名解析:

  1. grafana A 10.4.7.10

应用资源配置清单:

  1. # kubectl apply -f http://k8s-yaml.od.com/grafana/rbac.yaml
  2. # kubectl apply -f http://k8s-yaml.od.com/grafana/dp.yaml
  3. # kubectl apply -f http://k8s-yaml.od.com/grafana/svc.yaml
  4. # kubectl apply -f http://k8s-yaml.od.com/grafana/ingress.yaml

浏览器访问验证:

grafana.od.com

默认用户名密码admin

进入容器安装插件:

  1. # kubectl exec -it grafana-d6588db94-xr4s6 /bin/bash -n infra
  1. grafana-cli plugins install grafana-kubernetes-app
  2. grafana-cli plugins install grafana-clock-panel
  3. grafana-cli plugins install grafana-piechart-panel
  4. grafana-cli plugins install briangann-gauge-panel
  5. grafana-cli plugins install natel-discrete-panel

配置数据源:选择prometheus,把三个证书添加进来

重启grafana

找到我们刚才安装的插件里面的kubernetes,启用,然后新建cluster

添加完需要稍等几分钟,在没有取到数据之前,会报http forbidden,没关系,等一会就好。大概2-5分钟。

配置alert告警插件:

  1. # docker pull docker.io/prom/alertmanager:v0.14.0
  2. # docker tag 30594e96cbe8 harbor.od.com/infra/alertmanager:v0.14.0
  3. # docker push harbor.od.com/infra/alertmanager:v0.14.0

资源配置清单:

1、cm.yaml

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: alertmanager-config
  5. namespace: infra
  6. data:
  7. config.yml: |-
  8. global:
  9. # 在没有报警的情况下声明为已解决的时间
  10. resolve_timeout: 5m
  11. # 配置邮件发送信息
  12. smtp_smarthost: 'smtp.163.com:25'
  13. smtp_from: 'xxx@163.com'
  14. smtp_auth_username: 'xxx@163.com'
  15. smtp_auth_password: 'xxxxxx'
  16. smtp_require_tls: false
  17. # 所有报警信息进入后的根路由,用来设置报警的分发策略
  18. route:
  19. # 这里的标签列表是接收到报警信息后的重新分组标签,例如,接收到的报警信息里面有许多具有 cluster=A 和 alertname=LatncyHigh 这样的标签的报警信息将会批量被聚合到一个分组里面
  20. group_by: ['alertname', 'cluster']
  21. # 当一个新的报警分组被创建后,需要等待至少group_wait时间来初始化通知,这种方式可以确保您能有足够的时间为同一分组来获取多个警报,然后一起触发这个报警信息。
  22. group_wait: 30s
  23.  
  24. # 当第一个报警发送后,等待'group_interval'时间来发送新的一组报警信息。
  25. group_interval: 5m
  26.  
  27. # 如果一个报警信息已经发送成功了,等待'repeat_interval'时间来重新发送他们
  28. repeat_interval: 5m
  29.  
  30. # 默认的receiver:如果一个报警没有被一个route匹配,则发送给默认的接收器
  31. receiver: default
  32.  
  33. receivers:
  34. - name: 'default'
  35. email_configs:
  36. - to: 'xxxx@qq.com'
  37. send_resolved: true

2、dp.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: alertmanager
  5. namespace: infra
  6. spec:
  7. replicas: 1
  8. selector:
  9. matchLabels:
  10. app: alertmanager
  11. template:
  12. metadata:
  13. labels:
  14. app: alertmanager
  15. spec:
  16. containers:
  17. - name: alertmanager
  18. image: harbor.od.com/infra/alertmanager:v0.14.0
  19. args:
  20. - "--config.file=/etc/alertmanager/config.yml"
  21. - "--storage.path=/alertmanager"
  22. ports:
  23. - name: alertmanager
  24. containerPort: 9093
  25. volumeMounts:
  26. - name: alertmanager-cm
  27. mountPath: /etc/alertmanager
  28. volumes:
  29. - name: alertmanager-cm
  30. configMap:
  31. name: alertmanager-config
  32. imagePullSecrets:
  33. - name: harbor

3、svc.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: alertmanager
  5. namespace: infra
  6. spec:
  7. selector:
  8. app: alertmanager
  9. ports:
  10. - port: 80
  11. targetPort: 9093

基础报警规则:

  1. # vi /data/nfs-volume/prometheus/etc/rules.yml
  1. groups:
  2. - name: hostStatsAlert
  3. rules:
  4. - alert: hostCpuUsageAlert
  5. expr: sum(avg without (cpu)(irate(node_cpu{mode!='idle'}[5m]))) by (instance) > 0.85
  6. for: 5m
  7. labels:
  8. severity: warning
  9. annotations:
  10. summary: "{{ $labels.instance }} CPU usage above 85% (current value: {{ $value }}%)"
  11. - alert: hostMemUsageAlert
  12. expr: (node_memory_MemTotal - node_memory_MemAvailable)/node_memory_MemTotal > 0.85
  13. for: 5m
  14. labels:
  15. severity: warning
  16. annotations:
  17. summary: "{{ $labels.instance }} MEM usage above 85% (current value: {{ $value }}%)"
  18. - alert: OutOfInodes
  19. expr: node_filesystem_free{fstype="overlay",mountpoint ="/"} / node_filesystem_size{fstype="overlay",mountpoint ="/"} * 100 < 10
  20. for: 5m
  21. labels:
  22. severity: warning
  23. annotations:
  24. summary: "Out of inodes (instance {{ $labels.instance }})"
  25. description: "Disk is almost running out of available inodes (< 10% left) (current value: {{ $value }})"
  26. - alert: OutOfDiskSpace
  27. expr: node_filesystem_free{fstype="overlay",mountpoint ="/rootfs"} / node_filesystem_size{fstype="overlay",mountpoint ="/rootfs"} * 100 < 10
  28. for: 5m
  29. labels:
  30. severity: warning
  31. annotations:
  32. summary: "Out of disk space (instance {{ $labels.instance }})"
  33. description: "Disk is almost full (< 10% left) (current value: {{ $value }})"
  34. - alert: UnusualNetworkThroughputIn
  35. expr: sum by (instance) (irate(node_network_receive_bytes[2m])) / 1024 / 1024 > 100
  36. for: 5m
  37. labels:
  38. severity: warning
  39. annotations:
  40. summary: "Unusual network throughput in (instance {{ $labels.instance }})"
  41. description: "Host network interfaces are probably receiving too much data (> 100 MB/s) (current value: {{ $value }})"
  42. - alert: UnusualNetworkThroughputOut
  43. expr: sum by (instance) (irate(node_network_transmit_bytes[2m])) / 1024 / 1024 > 100
  44. for: 5m
  45. labels:
  46. severity: warning
  47. annotations:
  48. summary: "Unusual network throughput out (instance {{ $labels.instance }})"
  49. description: "Host network interfaces are probably sending too much data (> 100 MB/s) (current value: {{ $value }})"
  50. - alert: UnusualDiskReadRate
  51. expr: sum by (instance) (irate(node_disk_bytes_read[2m])) / 1024 / 1024 > 50
  52. for: 5m
  53. labels:
  54. severity: warning
  55. annotations:
  56. summary: "Unusual disk read rate (instance {{ $labels.instance }})"
  57. description: "Disk is probably reading too much data (> 50 MB/s) (current value: {{ $value }})"
  58. - alert: UnusualDiskWriteRate
  59. expr: sum by (instance) (irate(node_disk_bytes_written[2m])) / 1024 / 1024 > 50
  60. for: 5m
  61. labels:
  62. severity: warning
  63. annotations:
  64. summary: "Unusual disk write rate (instance {{ $labels.instance }})"
  65. description: "Disk is probably writing too much data (> 50 MB/s) (current value: {{ $value }})"
  66. - alert: UnusualDiskReadLatency
  67. expr: rate(node_disk_read_time_ms[1m]) / rate(node_disk_reads_completed[1m]) > 100
  68. for: 5m
  69. labels:
  70. severity: warning
  71. annotations:
  72. summary: "Unusual disk read latency (instance {{ $labels.instance }})"
  73. description: "Disk latency is growing (read operations > 100ms) (current value: {{ $value }})"
  74. - alert: UnusualDiskWriteLatency
  75. expr: rate(node_disk_write_time_ms[1m]) / rate(node_disk_writes_completedl[1m]) > 100
  76. for: 5m
  77. labels:
  78. severity: warning
  79. annotations:
  80. summary: "Unusual disk write latency (instance {{ $labels.instance }})"
  81. description: "Disk latency is growing (write operations > 100ms) (current value: {{ $value }})"
  82. - name: http_status
  83. rules:
  84. - alert: ProbeFailed
  85. expr: probe_success == 0
  86. for: 1m
  87. labels:
  88. severity: error
  89. annotations:
  90. summary: "Probe failed (instance {{ $labels.instance }})"
  91. description: "Probe failed (current value: {{ $value }})"
  92. - alert: StatusCode
  93. expr: probe_http_status_code <= 199 OR probe_http_status_code >= 400
  94. for: 1m
  95. labels:
  96. severity: error
  97. annotations:
  98. summary: "Status Code (instance {{ $labels.instance }})"
  99. description: "HTTP status code is not 200-399 (current value: {{ $value }})"
  100. - alert: SslCertificateWillExpireSoon
  101. expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 30
  102. for: 5m
  103. labels:
  104. severity: warning
  105. annotations:
  106. summary: "SSL certificate will expire soon (instance {{ $labels.instance }})"
  107. description: "SSL certificate expires in 30 days (current value: {{ $value }})"
  108. - alert: SslCertificateHasExpired
  109. expr: probe_ssl_earliest_cert_expiry - time() <= 0
  110. for: 5m
  111. labels:
  112. severity: error
  113. annotations:
  114. summary: "SSL certificate has expired (instance {{ $labels.instance }})"
  115. description: "SSL certificate has expired already (current value: {{ $value }})"
  116. - alert: BlackboxSlowPing
  117. expr: probe_icmp_duration_seconds > 2
  118. for: 5m
  119. labels:
  120. severity: warning
  121. annotations:
  122. summary: "Blackbox slow ping (instance {{ $labels.instance }})"
  123. description: "Blackbox ping took more than 2s (current value: {{ $value }})"
  124. - alert: BlackboxSlowRequests
  125. expr: probe_http_duration_seconds > 2
  126. for: 5m
  127. labels:
  128. severity: warning
  129. annotations:
  130. summary: "Blackbox slow requests (instance {{ $labels.instance }})"
  131. description: "Blackbox request took more than 2s (current value: {{ $value }})"
  132. - alert: PodCpuUsagePercent
  133. expr: sum(sum(label_replace(irate(container_cpu_usage_seconds_total[1m]),"pod","$1","container_label_io_kubernetes_pod_name", "(.*)"))by(pod) / on(pod) group_right kube_pod_container_resource_limits_cpu_cores *100 )by(container,namespace,node,pod,severity) > 80
  134. for: 5m
  135. labels:
  136. severity: warning
  137. annotations:
  138. summary: "Pod cpu usage percent has exceeded 80% (current value: {{ $value }}%)"

在prometheus.yml中添加配置:

  1. # vi prometheus.yml
  1. alerting:
  2. alertmanagers:
  3. - static_configs:
  4. - targets: ["alertmanager"]
  5. rule_files:
  6. - "/data/etc/rules.yml"

重载配置:

  1. # curl -X POST http://prometheus.od.com/-/reload

以上这些就是我们的告警规则

测试告警:

把app命名空间里的dubbo-demo-service给停掉:

看下blackbox里的信息:

看下alert:

红色的时候就开会发邮件告警:

已经收到告警了,后续上生产,还会更新如何添加微信、钉钉、短信告警

如果需要自己定制告警规则和告警内容,需要研究一下promql,自己修改配置文件。

kubernetes生态--交付prometheus监控及grafana炫酷dashboard到k8s集群的更多相关文章

  1. 基于prometheus监控k8s集群

    本文建立在你已经会安装prometheus服务的基础之上,如果你还不会安装,请参考:prometheus多维度监控容器 如果你还没有安装库k8s集群,情参考: 从零开始搭建基于calico的kuben ...

  2. Kubernetes之利用prometheus监控K8S集群

    prometheus它是一个主动拉取的数据库,在K8S中应该展示图形的grafana数据实例化要保存下来,使用分布式文件系统加动态PV,但是在本测试环境中使用本地磁盘,安装采集数据的agent使用Da ...

  3. 容器编排系统K8s之Prometheus监控系统+Grafana部署

    前文我们聊到了k8s的apiservice资源结合自定义apiserver扩展原生apiserver功能的相关话题,回顾请参考:https://www.cnblogs.com/qiuhom-1874/ ...

  4. Kubernetes学习之路(二十三)之资源指标和集群监控

    目录 1.资源指标和资源监控 2.Weave Scope监控集群 (1)Weave Scope部署 (2)使用 Scope (3)拓扑结构 (4)实时资源监控 (5)在线操作 (6)强大的搜索功能 2 ...

  5. Prometheus 监控K8S集群资源监控

    Prometheus 监控K8S集群中Pod 目前cAdvisor集成到了kubelet组件内,可以在kubernetes集群中每个启动了kubelet的节点使用cAdvisor提供的metrics接 ...

  6. 基于k8s集群部署prometheus监控ingress nginx

    目录 基于k8s集群部署prometheus监控ingress nginx 1.背景和环境概述 2.修改prometheus配置 3.检查是否生效 4.配置grafana图形 基于k8s集群部署pro ...

  7. 基于k8s集群部署prometheus监控etcd

    目录 基于k8s集群部署prometheus监控etcd 1.背景和环境概述 2.修改prometheus配置 3.检查是否生效 4.配置grafana图形 基于k8s集群部署prometheus监控 ...

  8. kubernetes实战-交付dubbo服务到k8s集群(六)使用blue ocean流水线构建dubbo-consumer服务

    我们这里的dubbo-consumer是dubbo-demo-service的消费者: 我们之前已经在jenkins配置好了流水线,只需要填写参数就行了. 由于dubbo-consumer用的gite ...

  9. 如何使用helm优雅安装prometheus-operator,并监控k8s集群微服务

    前言:随着云原生概念盛行,对于容器.服务.节点以及集群的监控变得越来越重要.Prometheus 作为 Kubernetes 监控的事实标准,有着强大的功能和良好的生态.但是它不支持分布式,不支持数据 ...

随机推荐

  1. 攻防世界—pwn—int_overflow

    题目分析 checksec检查文件保护机制 ida分析程序 经典整数溢出漏洞示例 整数溢出原理整数分为有符号和无符号两种类型,有符号数以最高位作为其符号位,即正整数最高位为1,负数为0, 无符号数取值 ...

  2. oracle关闭监听log.xml文件生成步骤

    1.查看sqlnet.ora文件是否存在 cd $ORACLE_HOME/network/admin ls 如果不存在,copy一个过来 cp samples/sqlnet.ora . 2.修改sql ...

  3. 1.5V升3V芯片和电路图,DC-DC升压IC

    1.5V升3V的升压芯片,3V给LED供电,或者单片机模块供电等. PW5200A工作频率为1.4MHZ.轻载时自动PWM/PFM模式切换,提高效率. PW5200A能够提供2.5V和5V之间的可调输 ...

  4. HATEOAS的简单认识

    HATEOAS: 超媒体作为应用程序状态引擎(HATEOAS)是REST应用程序体系结构的一个组件,它将其与其他网络应用程序体系结构区分开来. 使用HATEOAS,客户端与网络应用程序交互,其应用程序 ...

  5. floating point

    记录浮点数的单精度和双精度(IEEE754) 1.单精度(float) ​ 1.定义:单精度占4字节/32位,其中1号位符号位,其次是8位阶码/指数(阶符+阶数),23位尾数(小数). 2.双精度(d ...

  6. java.io.IOException: Could not find resource com/xxx/xxxMapper.xml

    java.io.IOException: Could not find resource com/xxx/xxxMapper.xml 报错内容: org.apache.ibatis.exception ...

  7. node集群(cluster)

    使用例子 为了让node应用能够在多核服务器中提高性能,node提供cluster API,用于创建多个工作进程,然后由这些工作进程并行处理请求. // master.js const cluster ...

  8. SICP 解题集 — SICP 解题集 https://sicp.readthedocs.io/en/latest/

    SICP 解题集 - SICP 解题集 https://sicp.readthedocs.io/en/latest/

  9. High Performance Networking in Google Chrome 进程间通讯(IPC) 多进程资源加载

    小结: 1. 小文件存储于一个文件中: 在内部,磁盘缓存(disk cache)实现了它自己的一组数据结构, 它们被存储在一个单独的缓存目录里.其中有索引文件(在浏览器启动时加载到内存中),数据文件( ...

  10. WPF mvvm 验证,耗时两天的解决方案

    常用类 类名 介绍 ValidationRule 所有自定义验证规则的基类.提供了让用户定义验证规则的入口. ExceptionValidation 表示一个规则,该规则检查在绑定源属性更新过程中引发 ...