Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the "metrics_server_pod_cpu_usage"data #1363

Open
mayanshun opened this issue Nov 14, 2023 · 3 comments
Open

How to get the "metrics_server_pod_cpu_usage"data #1363

mayanshun opened this issue Nov 14, 2023 · 3 comments
Assignees
Labels
kind/support Categorizes issue or PR as a support question. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@mayanshun
Copy link

metrics_server v0.5.2 in my cluster K8s v1.25.0
I wan to get the datas "metrics_server_pod_cpu_usage " from prometheus , the prometheus can not search the data

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 14, 2023
@mayanshun
Copy link
Author

curl --cert /etc/kubernetes/pki/apiserver-kubelet-client.crt --key /etc/kubernetes/pki/apiserver-kubelet-client.key -k https://172.16.121.131:6443/metrics
this datas have no "metrics_server*"

@mayanshun
Copy link
Author

`[root@172-16-104-15 prometheus]# cat prometheus.yml

my global config

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=<job_name> to any timeseries scraped from this config.

  • job_name: "prometheus"

    metrics_path defaults to '/metrics'

    scheme defaults to 'http'.

    static_configs:

    • targets: ["localhost:9090"]

#配置k8s API-Server 服务发现

  • job_name: 'kubernetes-apiserver'
    kubernetes_sd_configs:
    • role: endpoints
      api_server: https://172.16.121.131:6443
      tls_config:
      insecure_skip_verify: true
      bearer_token_file: /usr/local/prometheus/k8s.token
      scheme: https
      tls_config:
      insecure_skip_verify: true
      bearer_token_file: /usr/local/prometheus/k8s.token
      relabel_configs:
    • source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
      action: keep
      regex: default;kubernetes;https
      #自定义替换发现的服务器端口、协议等.
      #配置k8s node服务发现
  • job_name: 'kubernetes-nodes-monitor'
    scheme: http
    tls_config:
    insecure_skip_verify: true
    bearer_token_file: /usr/local/prometheus/k8s.token
    kubernetes_sd_configs:
    • role: node
      api_server: https://172.16.121.131:6443
      tls_config:
      insecure_skip_verify: true
      bearer_token_file: /usr/local/prometheus/k8s.token
      #node标签重写
      relabel_configs:
      • source_labels: [address]
        regex: '(.*):10250'
        replacement: '${1}:9100'
        target_label: address
        action: replace

#配置namespace下的pod服务发现

  • job_name: 'kubernetes-pods'
    kubernetes_sd_configs:
    • role: pod
      api_server: https://172.16.121.131:6443
      tls_config:
      insecure_skip_verify: true
      bearer_token_file: /usr/local/prometheus/k8s.token
      namespaces:
      names:
      • kube-system
      • default
      • monitoring
      • pixiu-system
        relabel_configs:
      • 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

#指定Pod发现条件

  • job_name: 'kubernetes-conditions-pod'
    kubernetes_sd_configs:
    • role: pod
      api_server: https://172.16.121.131:6443
      tls_config:
      insecure_skip_verify: true
      bearer_token_file: /usr/local/prometheus/k8s.token
      relabel_configs:
    • 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`

@dgrisonnet
Copy link
Member

/assign
/triage accepted
/kind support

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/support Categorizes issue or PR as a support question. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

3 participants