Kubernetes 中部署 kube-state-metrics 及 Prometheus 監控配置實戰

文章目錄

  • Kubernetes 中部署 kube-state-metrics 及 Prometheus 監控配置實戰
  • 環境準備
  • 創建監控命名空間
  • 準備配置文件
  • 創建 ServiceAccount
  • 配置 RBAC 權限
  • 部署 kube-state-metrics
  • 部署node_exporter(可選)
  • 驗證服務賬號 Token
  • Prometheus 配置示例
  • 小結
  • 驗證
  • 增加Grafana面板
    • 增加prometheus監控數據源
    • 添加k8s監控面板(需Grafana這臺有網)
  • 擴展告警規則
  • 總結


Kubernetes 中部署 kube-state-metrics 及 Prometheus 監控配置實戰

本文詳細介紹了如何在 Kubernetes 集群中部署 kube-state-metrics 組件,配置服務賬號(ServiceAccount)、RBAC 授權,并結合 Prometheus 采集 kube-state-metrics 和 node-exporter 指標的全過程,方便你快速搭建集群監控體系。


環境準備

假設你的 Kubernetes 集群節點 IP 為 10.255.101.217,且已經安裝了 kubectl,且配置了訪問權限。

一臺 Master 多節點玩轉 Kubernetes:sealos 一鍵部署實踐

使用 Supervisor 和 Systemd 搭建 Prometheus + Alertmanager + Node Exporter + Grafana 全套監控系統


創建監控命名空間

首先,為監控組件創建一個專用的命名空間 monitor-sa

kubectl create ns monitor-sa

確認命名空間已經創建:

kubectl get ns

在這里插入圖片描述


準備配置文件

  • sa.yaml
  • rbac.yaml
  • clust.yaml
  • jiankong.yaml
  • svc.yaml
  • node.yaml

創建 ServiceAccount

monitor-sa 命名空間中為 kube-state-metrics 創建一個服務賬號 kube-state-metrics,方便后續綁定權限。

sa.yaml 文件內容:

apiVersion: v1
kind: ServiceAccount
metadata:# sa 賬號名稱name: kube-state-metrics# sa 賬號名稱空間namespace: monitor-sa

執行:

# kubectl apply -f sa.yaml serviceaccount/kube-state-metrics created

配置 RBAC 權限

為了讓 kube-state-metrics 能夠訪問 Kubernetes 資源,創建對應的 ClusterRole:

rbac.yaml 文件內容:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:name: kube-state-metrics
rules:
- apiGroups: [""]resources: ["nodes", "pods", "services", "resourcequotas", "replicationcontrollers", "limitranges", "persistentvolumeclaims", "persistentvolumes", "namespaces", "endpoints"]verbs: ["list", "watch"]
- apiGroups: ["extensions"]resources: ["daemonsets", "deployments", "replicasets"]verbs: ["list", "watch"]
- apiGroups: ["apps"]resources: ["statefulsets"]verbs: ["list", "watch"]
- apiGroups: ["batch"]resources: ["cronjobs", "jobs"]verbs: ["list", "watch"]
- apiGroups: ["autoscaling"]resources: ["horizontalpodautoscalers"]verbs: ["list", "watch"]
- apiGroups: [""]resources: ["nodes/proxy"]verbs: ["get"]

創建 ClusterRoleBinding,將 ClusterRole 綁定給前面創建的 ServiceAccount:

clust.yaml 文件內容:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: kube-state-metrics
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: kube-state-metrics
subjects:
- kind: ServiceAccountname: kube-state-metricsnamespace: monitor-sa

應用:

# kubectl apply -f rbac.yamlclusterrole.rbac.authorization.k8s.io/kube-state-metrics created# kubectl apply -f clust.yamlclusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics created

部署 kube-state-metrics

準備 Deployment 配置文件 jiankong.yaml

apiVersion: apps/v1
kind: Deployment
metadata:labels:app.kubernetes.io/name: kube-state-metricsname: kube-state-metricsnamespace: monitor-sa
spec:replicas: 1selector:matchLabels:app.kubernetes.io/name: kube-state-metricstemplate:metadata:labels:app.kubernetes.io/name: kube-state-metricsspec:serviceAccountName: kube-state-metricscontainers:- image: registry.k8s.io/kube-state-metrics/kube-state-metrics::latestimagePullPolicy: IfNotPresentname: kube-state-metricsports:- containerPort: 8080name: http-metricsprotocol: TCP

在準備它的svc.yaml

apiVersion: v1
kind: Service
metadata:name: kube-state-metricsnamespace: monitor-sa
spec:ports:- name: http-metricsport: 8080protocol: TCP#targetPort: 8080targetPort: http-metrics- name: telemetryport: 8081protocol: TCPtargetPort: telemetryselector:app.kubernetes.io/name: kube-state-metricssessionAffinity: Nonetype: NodePort

執行部署:

# kubectl apply -f jiankong.yaml
deployment.apps/kube-state-metrics created
# kubectl apply -f svc.yaml
service/kube-state-metrics created

查看 Pod 狀態:

# kubectl -n monitor-sa get podsNAME                                  READY   STATUS    RESTARTS   AGE
kube-state-metrics-5b7cf967d6-knhww   1/1     Running   0          40m

查看映射的端口

# kubectl -n monitor-sa get svc
NAME                 TYPE       CLUSTER-IP        EXTERNAL-IP   PORT(S)                         AGE
kube-state-metrics   NodePort   192.168.144.178   <none>        8080:32470/TCP,8081:31602/TCP   75m

部署node_exporter(可選)

集群node很多,我們不會跟傳統模式似的,一個一個去部署node_exporter,這個時候我們就再k8s中創建個DaemonSet,讓它自己根據k8S的node節點進行創建

準備node.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:name: node-exporternamespace: monitor-sa
spec:selector:matchLabels:app: node-exportertemplate:metadata:labels:app: node-exporterspec:hostPID: truehostIPC: truehostNetwork: truecontainers:- name: node-exporterimage: quay.io/prometheus/node-exporter:v1.9.1imagePullPolicy: IfNotPresentports:- containerPort: 9100name: metricsresources:requests:cpu: "150m"limits:cpu: "500m"securityContext:privileged: true  # 若非必要,可設為 false 增強安全args:- --path.procfs=/host/proc- --path.sysfs=/host/sys- --collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($|/)volumeMounts:- name: devmountPath: /host/devreadOnly: true- name: procmountPath: /host/procreadOnly: true- name: sysmountPath: /host/sysreadOnly: true- name: rootfsmountPath: /rootfsreadOnly: truetolerations:- key: "node-role.kubernetes.io/control-plane"operator: "Exists"effect: "NoSchedule"volumes:- name: prochostPath:path: /proc- name: devhostPath:path: /dev- name: syshostPath:path: /sys- name: rootfshostPath:path: /

執行部署:

# kubectl apply -f node.yaml
daemonset.apps/node-exporter created

查看pod狀態

# kubectl -n monitor-sa get nodes -o wide NAME             STATUS   ROLES                  AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION               CONTAINER-RUNTIME
10-255-101-152   Ready    <none>                 41d   v1.22.0   10.255.101.152   <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3
10-255-101-216   Ready    <none>                 41d   v1.22.0   10.255.101.216   <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3
10-255-101-217   Ready    control-plane,master   41d   v1.22.0   10.255.101.217   <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3
10-255-101-82    Ready    <none>                 41d   v1.22.0   10.255.101.82    <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3# kubectl -n monitor-sa get pods -o wide NAME                                  READY   STATUS    RESTARTS   AGE   IP               NODE             NOMINATED NODE   READINESS GATES
kube-state-metrics-5b7cf967d6-tk5kr   1/1     Running   0          87m   192.168.154.12   10-255-101-82    <none>           <none>
node-exporter-7sc7c                   1/1     Running   0          72m   10.255.101.152   10-255-101-152   <none>           <none>
node-exporter-d2w2z                   1/1     Running   0          72m   10.255.101.216   10-255-101-216   <none>           <none>
node-exporter-rc6bt                   1/1     Running   0          72m   10.255.101.82    10-255-101-82    <none>           <none>

驗證服務賬號 Token

通過命令查看 default 服務賬號的 token:

# kubectl -n monitor-sa get secrets 
NAME                             TYPE                                  DATA   AGE
default-token-wrbmj              kubernetes.io/service-account-token   3      5m9s
kube-state-metrics-token-bkrsr   kubernetes.io/service-account-token   3      3m41s# kubectl -n monitor-sa describe secrets kube-state-metrics-token-bkrsr

將顯示包含 token 的詳細信息,可用于 Prometheus 授權。
在這里插入圖片描述
!!!把token內容,復制到prometheus的服務器里

/data/app/prometheus/token

[root@10-255-101-216 prometheus]# cat token 
eyJhbGciOiJSUzI1NiIsImtpZCI6IlUyVjJSUGFyMWRDcWlZUUota2F0Q2xVY1pBTU45cW1HNEl2a1R2ajRlRzQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJtb25pdG9yLXNhIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Imt1YmUtc3RhdGUtbWV0cmljcy10b2tlbi1ia3JzciIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlLXN0YXRlLW1ldHJpY3MiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjZjRmODFlYS00Mzg3LTRhOGUtYjdlMC04ZjM1NjM0YjczMTciLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6bW9uaXRvci1zYTprdWJlLXN0YXRlLW1ldHJpY3MifQ.cco-tUhN7SeZL6H40ShY4WPwZ-h3TBQ2fLj1v64W9lCRAf2U0yTFackRO19odYY5YgVhujdaQcmMxfd3EGN_RQuQZv3p0AtRIXstOc9q9jdwFmQtGaPMjN-DuUWHa5Gx72jUXjgdXzEe6oHugjfFikBs13JCSU7uY3DfpDTIGWRorNz2hQCXWGJktydk_5J_mqH7y3DWsGNOLXZpENavVo25DMRgVvIGuRLTqh7atkcGGgke92cSSUJqhQ9RMqtrCApJ_8eZiL4r8vY-aF224yCqbzlMva1Jd2CMhagQbQIBQUeXzfMDRqVIyPv9KNziIKr68cA4XEaIv6yvqMzE8w
[root@10-255-101-216 prometheus]# 

Prometheus 配置示例

將上面獲取到的服務賬號 Token 保存到 Prometheus 服務器 /data/app/prometheus/token 文件中。

Prometheus 配置文件 prometheus.yml 中增加如下內容,實現采集 kube-state-metricsnode-exporter 指標:

global:scrape_interval: 15sevaluation_interval: 15s# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:# - "first_rules.yml"# - "second_rules.yml"scrape_configs:- job_name: "prometheus"static_configs:- targets: ["localhost:9090"]# 上邊查看的svc的端口映射地址- job_name: kube-state-metricsstatic_configs:- targets: ['10.255.101.217:32470']labels:env: test20250528# 采集 node-exporter 指標- job_name: 'k8s-node-exporter'kubernetes_sd_configs:- role: podapi_server: https://10.255.101.217:6443bearer_token_file: /data/app/prometheus/tokentls_config:insecure_skip_verify: truerelabel_configs:- source_labels: [__meta_kubernetes_pod_label_app]regex: node-exporteraction: keep- target_label: envreplacement: test20250528- source_labels: [__meta_kubernetes_pod_ip]target_label: __address__replacement: '${1}:9100'action: replace- source_labels: [__meta_kubernetes_pod_node_name]target_label: nodeaction: replace- source_labels: [__meta_kubernetes_namespace]target_label: kubernetes_namespaceaction: replace- source_labels: [__meta_kubernetes_pod_name]target_label: kubernetes_pod_nameaction: replace# 采集 cadvisor 指標- job_name: test20250528-cadvisorhonor_timestamps: truemetrics_path: /metricsscheme: httpskubernetes_sd_configs:- api_server: https://10.255.101.217:6443role: nodebearer_token_file: /data/app/prometheus/tokentls_config:insecure_skip_verify: truebearer_token_file: /data/app/prometheus/tokentls_config:insecure_skip_verify: truerelabel_configs:- action: labelmapregex: __meta_kubernetes_node_label_(.+)- separator: ;regex: (.*)target_label: __address__replacement: 10.255.101.217:6443action: replace- source_labels: [__meta_kubernetes_node_name]separator: ;regex: (.+)target_label: __metrics_path__replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisoraction: replace- source_labels: [kubernetes_io_hostname]separator: ;regex: (.+)target_label: env_kubernetes_io_hostnamereplacement: test20250528-${1}action: replace- source_labels: [kubernetes_io_hostname]separator: ;regex: (.+)target_label: envreplacement: test20250528action: replace

小結

通過以上步驟,你已經完成了以下工作:

  • 創建專用命名空間 monitor-sa
  • 創建 kube-state-metrics 服務賬號和對應的 RBAC 授權
  • 部署 kube-state-metrics 監控組件
  • 通過 Prometheus 采集 kube-state-metrics 和 node-exporter 指標
  • 配置了 Prometheus 訪問 Kubernetes API Server 的安全 Token

驗證

在這里插入圖片描述

增加Grafana面板

增加prometheus監控數據源

請添加圖片描述
請添加圖片描述
我是只修改了URL,其他沒任何修改
請添加圖片描述
請添加圖片描述

添加k8s監控面板(需Grafana這臺有網)

請添加圖片描述
ID:10000
請添加圖片描述
請添加圖片描述
在這里插入圖片描述
至此面板添加完了,數據未顯示的,需要微調,可自行進行調整


擴展告警規則

# 容器相關報警信息
groups:
- name: "ContainerRules"rules:- alert: "容器異常"expr: kube_pod_container_status_running{env="test20250528",pod !~ "security-inspector-polaris-cronjob.*"} != 1for: 90slabels:severity: Disasterenv: test20250528annotations:summary: "ns:{{ $labels.namespace }} pod: {{ $labels.container }}]"description: "{{ $labels.instance }}: {{ $labels.namespace }} 服務{{ $labels.container }} 容器運行異常"# 容器內存使用率告警(>80%)- alert: "ContainerMemoryUsage"expr: sum by(namespace,pod,container) (container_memory_rss{image!="",env="test20250528"}) / sum by(namespace,pod,container) (container_spec_memory_limit_bytes{image!="",env="test20250528"}) * 100  != +Inf > 80for: 1mlabels:severity: Warningenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] Container memory usage warning"description: "Container memory usage is above 80%.\nVALUE = {{ $value | printf \"%.2f\" }}%\n"# 容器 CPU 使用率告警(>80% - Warning)- alert: ContainerCpuUsageexpr: sum by(container, namespace, pod) (irate(container_cpu_usage_seconds_total{env="test20250528",image!=""}[5m]) * 100) / sum by(container, namespace, pod) (container_spec_cpu_quota{env="test20250528",image!=""} / container_spec_cpu_period{env="test20250528",image!=""}) > 80for: 1mlabels:severity: Warningenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] Container CPU usage warning"description: "Container CPU usage is above 80%.\nVALUE = {{ $value | printf \"%.2f\" }}%\n"# 容器 CPU 使用率告警(>90% - Disaster)- alert: "ContainerCpuUsage"expr: sum by(container, namespace, pod) (irate(container_cpu_usage_seconds_total{env="test20250528",image!=""}[5m]) * 100) / sum by(container, namespace, pod) (container_spec_cpu_quota{env="test20250528",image!=""} / container_spec_cpu_period{env="test20250528",image!=""}) > 90for: 1mlabels:severity: Disasterenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] Container CPU usage critical"description: "Container CPU usage is above 90%.\nVALUE = {{ $value | printf \"%.2f\" }}%\n"- alert: "容器重啟"expr: rate(kube_pod_container_status_restarts_total{env="test20250528"}[15m]) > 0for: 5mlabels:severity: Disasterenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] 容器發生重啟"description: "{{ $labels.namespace }} 命名空間中的容器 {{ $labels.container }}(所屬 Pod: {{ $labels.pod }})在過去 15 分鐘內發生了重啟)"

總結

至此 Kubernetes 監控體系的基礎框架搭建完畢。后續可以根據業務需求增加更多監控項和告警規則。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/84911.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/84911.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/84911.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《重塑認知:Django MVT架構的多維剖析與實踐》

MVT&#xff0c;即Model - View - Template&#xff0c;是Django框架獨特的架構模式。它看似簡單的三個字母&#xff0c;實則蘊含著深刻的設計哲學&#xff0c;如同古老智慧的密碼&#xff0c;解開了Web應用開發的復雜謎題。 模型&#xff0c;是MVT架構中的數據核心&#xff0…

【JVM】初識JVM 從字節碼文件到類的生命周期

初識JVM JVM&#xff08;Java Virtual Machine&#xff09;即 Java 虛擬機&#xff0c;是 Java 技術的核心組件之一。JVM的本質就是運行在計算機上的一個程序&#xff0c;通過軟件模擬實現了一臺抽象的計算機的功能。JVM是Java程序的運行環境&#xff0c;負責加載字節碼文件&a…

人工智能在智能零售中的創新應用與未來趨勢

隨著電子商務的蓬勃發展和消費者需求的不斷變化&#xff0c;零售行業正面臨著前所未有的挑戰和機遇。智能零售作為零售行業的重要發展方向&#xff0c;通過引入人工智能&#xff08;AI&#xff09;、物聯網&#xff08;IoT&#xff09;、大數據和云計算等前沿技術&#xff0c;正…

DeepSeek 賦能智能物流:解鎖倉儲機器人調度的無限可能

目錄 一、智能物流倉儲機器人調度現狀1.1 傳統調度面臨的挑戰1.2 現有智能調度的進展與局限 二、DeepSeek 技術探秘2.1 DeepSeek 核心技術原理2.2 DeepSeek 的獨特優勢 三、DeepSeek 在智能物流倉儲機器人調度中的創新應用3.1 智能任務分配與調度3.2 路徑規劃與避障優化3.3 實時…

Vue CLI創建vue項目,安裝插件

Vue CLI創建vue項目&#xff0c;安裝插件 一、創建項目1. 安裝Vue CLI2. 創建項目 二、安裝插件routerlesssassjquery 一、創建項目 1. 安裝Vue CLI npm install -g vue/cli2. 創建項目 vue create project cd project二、安裝插件 router npm install vue-router # 對于 …

小白成長之路-Linux程序管理(二)

文章目錄 一、源碼包&#xff08;編譯&#xff09;安裝1.安裝前先查看磁盤大小2.壓縮包的位置3.執行編譯 二、二進制安裝三、Linux操作系統啟動流程3.1概述3.2啟動流程核心階段1.電源與固件階段2.引導加載程序3.內核初始化4.systemd初始化進程5. 用戶登錄階段 四、systemd管理機…

Ansible模塊——Ansible的安裝!

Ansible 安裝 Ansible 有三種安裝方式&#xff0c;源碼安裝、發行版安裝和 Python 安裝。 使用發行版安裝或 Python 安裝兩種方式時&#xff0c;Ansible 的安裝包有兩個&#xff0c;區別如下&#xff1a; ? ansible-core&#xff1a;一種極簡語言和運行時包&#xff0c;包含…

《全面解析鴻蒙相關概念:鴻蒙、開源鴻蒙、鴻蒙 Next 有何區別》

大家好&#xff0c;這里是程序員晚楓&#xff0c;最近接了一個和鴻蒙電腦有關的商單&#xff0c;所以專門花時間研究了一下和鴻蒙有關的概念。 鴻蒙系統相關概念主要有以下三個&#xff0c;它們之間存在多方面的區別&#xff0c;以下是具體介紹&#xff1a; OpenHarmony 定義…

C# 數組與字符串:全面解析與應用實踐

在C#編程語言中&#xff0c;數組和字符串是兩種最基礎也是最重要的數據類型。無論是簡單的控制臺應用程序&#xff0c;還是復雜的企業級系統&#xff0c;數組和字符串都扮演著不可或缺的角色。本文將全面深入地探討C#中數組和字符串的特性、使用方法、性能考量以及實際應用場景…

VR 技術在農業領域或許是一抹新曙光?

在科技日新月異的今天&#xff0c;VR(虛擬現實)技術已不再局限于游戲、影視等娛樂范疇&#xff0c;正逐步滲透到各個傳統行業&#xff0c;為其帶來全新的發展契機&#xff0c;農業領域便是其中之一。VR 技術利用計算機生成三維虛擬世界&#xff0c;給予用戶視覺、聽覺、觸覺等多…

SPEAR開源程序是用于逼真演示 AI 研究的模擬器

?一、軟件介紹 文末提供程序和源碼下載 SPEAR開源程序是用于逼真具身 AI 研究的模擬器 二、AI 研究的模擬器 交互式模擬器正在成為訓練具體代理的強大工具&#xff0c;但現有的模擬器存在內容多樣性、物理交互性和視覺保真度有限的問題。我們通過引入 SPEAR&#xff1a;照片…

第1章 Redis 概述

一、Redis 簡介 Redis,Remote Dictionary Server,遠程字典服務,由意大利人Salvatore Sanfilippo(又名Antirez)開發,是一個使用ANSI C 語言編寫&#xff64;支持網絡&#xff64; 可基于內存亦可持久化的日志型&#xff64;NoSQL 開源內存數據庫,其提供多種語言的API&#xff61…

圖論學習筆記 5 - 最小樹形圖

我們不廢話&#xff0c;直接進入正題&#xff1a;最小樹形圖&#xff0c;一個名字看起來很高級的東西。 聲明&#xff1a;為了便于理解&#xff0c;可能圖片數量會有億點點多。圖片尺寸可能有的較大。 概念 最小樹形圖的英文是 Directed Minimum Spanning Tree。 相信懂英文…

力扣面試150題--完全二叉樹的節點個數

Day 51 題目描述 思路 根據完全二叉樹的規律&#xff0c;完全二叉樹的高度可以直接通過不斷地訪問左子樹就可以獲取&#xff0c;判斷左右子樹的高度: 1. 如果相等說明左子樹是滿二叉樹, 然后進一步判斷右子樹的節點數(最后一層最后出現的節點必然在右子樹中&#xff09; 2. 如…

社區造數服務接入MCP|得物技術

一、背景 ? 今年 MCP 的概念非常火&#xff0c;市面上也涌現出了一大批 MCP 相關工具。作為技術一線者&#xff0c;都會按捺不住地去實操一下&#xff0c;很早的時候就有個設想&#xff0c;如果把我們的測試工具都改造為符合 MCP 服務協議標準&#xff0c;然后全部接入 AI A…

Mysql 查詢時間段內的sql優化

Mysql 查詢時間段內的sql優化 一說寫到查詢某個時間段的sql查詢,我們就會使用DATE_FORMAT函數格式化日期字段: 比如查詢某年某月的數據,我們可能常用的方式如下 DATE_FORMAT(pay_time,%Y-%m)=DATE_FORMAT(now(),%Y-%m) 但是這樣做會使索引失效,尤其在數據量越來越多的情況…

用 Deepseek 寫的 html+js 密碼生成器

下面是一個功能完整的密碼生成器HTMLJS實現&#xff0c;包含數字、小寫字母、大寫字母、符號、避免重復字符和密碼長度設置功能。 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport&…

WPF綁定

如何使用綁定去改變事件驅動的關系。 先介紹一下標簽擴展 目錄 控件與控件之間的綁定 代碼分析 綁定語法詳解 1. Binding - 綁定標記 2. ElementName=slider - 綁定源 3. Path=Value - 綁定路徑 不同控件屬性的默認模式: 控件和屬性綁定 1. 數據模型類的作用 2. 窗…

同源“平滑思想”的問題解法:正則化與拉普拉斯平滑

同源“平滑思想”的問題解法&#xff1a;正則化與拉普拉斯平滑 在機器學習和概率模型的實踐中&#xff0c;正則化與拉普拉斯平滑是兩個看似無關的技術&#xff1a;前者用于防止模型過擬合&#xff0c;后者用于解決零概率問題。但如果深入理解它們的核心邏輯&#xff0c;會發現…

用 AI 讓學習更懂你:如何打造自動化個性化學習系統?

用 AI 讓學習更懂你:如何打造自動化個性化學習系統? 在這個信息爆炸的時代,傳統的學習方式已經難以滿足個體化需求。過去,我們依賴固定的教學課程,所有學生按照統一進度進行學習,但每個人的學習節奏、興趣點和理解方式都不盡相同。而人工智能(AI)正在徹底改變這一局面…