我想计算kubernetes集群中所有pod的cpu使用情况.我在prometheus中发现了两个指标可能很有用:
container_cpu_usage_seconds_total: Cumulative cpu time consumed per cpu in seconds.
process_cpu_seconds_total: Total user and system CPU time spent in seconds.
Cpu Usage of all pods = increment per second of sum(container_cpu_usage_seconds_total{id="/"})/increment per second of sum(process_cpu_seconds_total)
Run Code Online (Sandbox Code Playgroud)
但是,我发现每秒的增量都container_cpu_usage{id="/"}
大于增量sum(process_cpu_seconds_total)
.因此使用量可能大于1 ...
假设我编写一个像这样的基本 PromQL 查询
询问:
kube_deployment_spec_replicas{}
结果:
kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",instance="myinstance",job="myjob",namespace="default",pod="mypod",service="myservice"}
Run Code Online (Sandbox Code Playgroud)
有没有一种干净的方法可以从结果时间序列中省略instance
和?pod
期望:
kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",job="myjob",namespace="default",service="myservice"}
Run Code Online (Sandbox Code Playgroud) 我正在制作Grafana仪表板,并希望有一个面板报告我们应用的最新版本.该版本在app_version
(比如)度量标准中报告为标签,如下所示:
app_version_updated{instance="eu99",version="1.5.0-abcdefg"}
Run Code Online (Sandbox Code Playgroud)
我尝试了一些Prometheus查询,将版本标签从这个时间序列的最新成员中提取为字符串,无效.
例如,查询
count(app_version_updated) by (version)
Run Code Online (Sandbox Code Playgroud)
返回{version="1.5.0-abcdefg"}
值为的元素1
.当在单个值面板中放入Grafana仪表板时,这不会显示版本字符串,而是显示计数值(1
).
如何构造返回版本字符串的Prometheus查询?
我不知道在使用Prometheus创建图形时在Grafana中“即时”选项的含义。
有任何想法吗?
我的抓取间隔和评估间隔相差很远,如下所示(15 秒与 4 米)。当我向端点提供指标时,我发现规则每 4m 评估一次,这是预期的。但是,我不明白的是,它不会评估过去 4 分钟提供的所有指标的规则。我很难理解两个时钟(抓取和评估)的工作原理。此外,与此相关的文档非常稀疏。任何指示都会有很大帮助。我毫不犹豫地将抓取时间和评估时间更改为各 15 秒。但我需要了解将时钟分开的后果。
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 4m # 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:
- testmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- …
Run Code Online (Sandbox Code Playgroud) 我们正在尝试使用Grafana和Prometheus Operator监视K8S,
大多数指标都按预期工作,并且我能够看到具有正确值的仪表板,我们的系统包含10个节点,总共500个Pod,现在当我重新启动Prometheus时,所有数据已被删除(我希望将其存储两周)我的问题是,如何定义Prometheus卷以将数据保留两周或100GB DB
。我发现以下内容(我们使用Prometheus运算符)
https://github.com/coreos/prometheus-operator/blob/master/Documentation/user-guides/storage.md
这是Prometheus运算符的配置
apiVersion: apps/v1beta2
kind: Deployment
metadata:
labels:
k8s-app: prometheus-operator
name: prometheus-operator
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
k8s-app: prometheus-operator
template:
metadata:
labels:
k8s-app: prometheus-operator
spec:
containers:
- args:
- --kubelet-service=kube-system/kubelet
- --logtostderr=true
- --config-reloader-image=quay.io/coreos/configmap-reload:v0.0.1
- --prometheus-config-reloader=quay.io/coreos/prometheus-config-reloader:v0.29.0
image: quay.io/coreos/prometheus-operator:v0.29.0
name: prometheus-operator
ports:
- containerPort: 8080
name: http
Run Code Online (Sandbox Code Playgroud)
这是Prometheus的配置
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
namespace: monitoring
labels:
prometheus: prometheus
spec:
replica: 2
serviceAccountName: prometheus
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector:
matchLabels: …
Run Code Online (Sandbox Code Playgroud) amazon-web-services google-cloud-platform kubernetes prometheus prometheus-operator
我确实有一个普罗米修斯时间序列,其中包含如下示例:
a_metric{band="1", state="A"} 1
a_metric{band="2", state="C"} 1
a_metric{band="1", state="A"} 1
a_metric{band="2", state="C"} 1
a_metric{band="1", state="B"} 1
a_metric{band="1", state="B"} 1
...
Run Code Online (Sandbox Code Playgroud)
我想在状态时间线面板中可视化该时间序列,以便band
s 成为水平带,而state
s 成为这些带内的离散状态。为此,我必须从标签中提取值state
(并使用它们而不是值 1)。
这可能吗?这样的可视化可以实现吗?
如果我理解正确的话,普罗米修斯label_values()
不能在这里服务,因为它仅限于模板。我怀疑 Grafana 转换可能会发挥作用,但我还没有这方面的经验。由于 Prometheus 没有字符串类型的指标,因此也出现了复杂性。
更新这是一个基本图像,应@JanGaray 的要求。
我很好奇普罗米修斯的工作原理。使用 Prometheus 界面,我可以看到一个下拉列表,我认为其中包含所有可用的指标。但是,我无法访问列出所有抓取的指标的指标端点。该http://targethost:9090/metrics
端点只显示有关普罗米修斯服务器本身的指标。是否可以访问列出所有可用指标的类似端点。我可以基于以下执行查询,{__name__=~".+"}
但我更愿意避免使用此选项。也许我还应该补充一点,访问目标部分中列出的端点对我不起作用,因为“无法建立连接”。
我正在使用flexlm_exporter将许可证使用情况导出到 Prometheus,并从 Prometheus 导出到自定义服务(不是 Grafana)。
如您所知,普罗米修斯隐藏了缺失的值。
但是,我的指标值中需要这些缺失值,因此我将其添加到我的舞会查询中or vector(0)
例如:
flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} or vector(0)
Run Code Online (Sandbox Code Playgroud)
此查询添加一个值为零的空指标。
我的问题是是否有办法将零向量与每个度量值合并?
编辑:
我需要分组,至少对于用户和名称标签,所以向量(0)可能不是这里的最佳选择?
我在不同的 StackOverflow 线程中尝试了多种解决方案,但是没有任何效果。
请协助。
关于 Spring Boot、一些有用的默认指标以及如何在 Grafana 中正确使用它们的小问题。
目前,Spring Boot 2.5.1+(适用于 2.xx 的问题)具有 Actuator + Micrometer + Prometheus 依赖项,有许多开箱即用的非常方便的默认指标。
我看到很多很多都有图案_max _count _sum
。
举几个例子:
spring_data_repository_invocations_seconds_max
spring_data_repository_invocations_seconds_count
spring_data_repository_invocations_seconds_sum
reactor_netty_http_client_data_received_bytes_max
reactor_netty_http_client_data_received_bytes_count
reactor_netty_http_client_data_received_bytes_sum
http_server_requests_seconds_max
http_server_requests_seconds_count
http_server_requests_seconds_sum
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不知道如何处理它们,如何正确使用它们,并且感觉我的无知让我错过了一些很棒的应用程序见解。
在网上搜索时,我看到一些使用这样的方法来计算 Grafana 的平均值:
irate(http_server_requests_seconds::sum{exception="None", uri!~".*actuator.*"}[5m]) / irate(http_server_requests_seconds::count{exception="None", uri!~".*actuator.*"}[5m])
Run Code Online (Sandbox Code Playgroud)
但不确定这是否是使用它们的正确方法。
请问在处理 type 的指标时通常会使用什么类型的查询_max _count _sum
?
谢谢