Prometheus
使用 Prometheus 收集度量值数据越来越受欢迎。 借助 Instana ,您可以轻松捕获 Prometheus 指标,并利用其庞大的知识图谱进行关联分析。 典型示例是定制业务度量值。
安装 Instana 主机代理后, Instana Prometheus 传感器将自动安装,但您需要按照 “配置 ”部分中的说明对该传感器进行配置。 然后,您可以在“ Instana ”用户界面中查看与 Prometheus 相关的指标。
Instana 提供了一个 Prometheus Alertmanager Webhook 警报通道,用于发送 HTTP POST 请求,其有效载荷格式为 Prometheus Alertmanager Webhook ,具体说明请参见 Prometheus Alertmanager Webhook 接收器配置。
若要从 Instana 向 Prometheus 实时发送警报通知,请在 Instana 用户界面中创建一个 Prometheus Alertmanager Webhook 警报通道。 然后, HTTP POST 的请求将被转发至 Prometheus。
简介
Instana Prometheus 传感器不需要 Prometheus 服务器。 该传感器直接从受监视系统公开的端点捕获度量值。
对于每个 Instana 主机代理,请使用正则表达式指定要轮询的 Prometheus 端点,以及需要从这些端点收集的指标。 有关更多信息,请参阅 配置 部分。
主题“ Micrometer ”介绍了如何收集 Micrometer 的指标。
主题“ Prometheus -java-client ”介绍了如何从 Prometheus Java client 库或 Micrometer 的 Prometheus 指标注册表中收集指标。
“Jmx ”主题介绍了如何从 JMX bean中收集自定义指标。
正在配置
Kubernetes 环境的配置
您需要在主机代理程序配置文件 configuration.yaml 中将度量标准源定义为端点列表。 当 Instana 主机代理在 Kubernetes 环境中运行时,该代理会自动识别并从正在运行的Pod中收集IP地址和容器端口。 在 Kubernetes 环境中,此配置需要通过 值 agent.configuration_yaml 传递给代理。 如果您通过操作员安装代理 ,请在 YAML 文件 instana-agent.customresource.yaml 下的自定义资源中 spec.agent.configuration_yaml添加配置。 如果您使用 Helm 图表安装代理 ,请通过该标志传递配置 --set agent.configuration_yaml=<config>。 或者,在values.yaml文件中设置配置,并使用-f标志将其传递给helm install命令。
请参阅以下配置示例:
com.instana.plugin.prometheus:
poll_rate: 15 # Global polling interval in seconds (optional, default is 1 second)
username: '' # Global (all) endpoints username/password configuration (optional)
password: ''
podConnectTimeout: 750 # discovery TCP connect timeout in ms used during discovery request (optional, default is 750ms)
podReadTimeout: 2500 # discovery TCP read timeout in ms used during discovery request (optional, default is 2500ms)
customMetricSources:
- url: '/prometheus/endpoint/1' # metrics endpoint, the IP and port are auto-discovered
metricNameIncludeRegex: '^.' # regular expression to filter metrics
username: '' # endpoint specific username/password configuration
password: ''
- url: '/prometheus/endpoint/2'
metricNameIncludeRegex: '^.'
- url: '/metrics' # metrics endpoint, the IP and port are auto-discovered
metricNameIncludeRegex: '^.' # regular expression to filter metrics
labels: # labels are used to limit discovery with pods that match. labels are treated as a boolean AND
planet: "mars"
app: "rover"
如果您希望抓取包含 Prometheus 注解的 Kubernetes 资源(例如 prometheus.io/scrape、 prometheus.io/port 和 prometheus.io/path),只要在 Prometheus strict 配置中将 prometheusAnnotations 字段设置为 ,则无需为该特定资源使用 部分 customMetricsSources 。 例如:
com.instana.plugin.prometheus:
podConnectTimeout: 750 # discovery TCP connect timeout in ms used during discovery request (optional, default is 750ms)
podReadTimeout: 2500 # discovery TCP read timeout in ms used during discovery request (optional, default is 2500ms)
prometheusAnnotations: strict # use prometheus annotations as defined, no metric source is required
注:
对于 Kubernetes 环境,请勿在字
url段中添加主机和端口信息,仅添加指标端点 URL ,例如/prometheus/endpoint/metrics。 Prometheus 传感器未监控那些被指定为完整 URL 的端点,例如https://prod-myapp.server.com/prometheus/metrics.如果不使用 prometheus 注释,则使用Kubernetespod 部署规范中的容器端口(
containerPort)定义来确定度量端点端口。通过在
metricNameIncludeRegex字段中使用正则表达式,您可以定义要针对特定度量端点捕获的度量。Prometheus 传感器具有可以在全局级别 (所有端点) 或每个端点上定义的基本认证支持。
非 Kubernetes 环境的静态配置
静态配置用于非Kubernetes 环境。 如果要从非Kubernetes 环境中的本地或远程端点捕获 Prometheus 度量,请按如下所示配置 <agent_install_dir>/etc/instana/configuration.yaml 文件中的 customMetricSources 部分:
com.instana.plugin.prometheus:
# Global polling interval in seconds (optional)
poll_rate: 15 # Default is 1 second
username: '' # Global (all) endpoints username/password configuration (optional)
password: ''
customMetricSources:
- url: 'http://localhost:8080/metrics'
username: '' # endpoint specific username/password configuration
password: ''
metricNameIncludeRegex: '^sample_app_request'
- url: 'http://223.58.1.10:9100/prometheus'
metricNameIncludeRegex: '^sample_app_request'
labels: # labels are used to limit discovery with pods that match. labels are treated as a boolean AND
planet: "mars"
app: "rover"
远程写入
从 Instana 主机代理软件包 1.1.587 开始,主机代理已支持 端点 remote_write ,这意味着它能够采集指标,且这些指标将以 Prometheus 实体或“进程自定义指标”的一部分的形式显示。
要启用 remote_write 端点,请按如下所示配置 <agent_install_dir>/etc/instana/configuration.yaml 文件:
com.instana.plugin.prometheus:
remote_write:
enabled: true
注:
请按照 Prometheus remote_write 文档中的说明配置发送方(即发送指标的组件)。
remote_write端点在/prometheus/v1/receive路径的端口42699上可用。 因此,您需要在 Prometheus 配置中配置的 URL 是http://<agent_ip>:42699/prometheus/v1/receive。为了让 Instana 正确解析指标,发送方必须发送元数据。 在 Prometheus 中,发件人功能是默认开启的,因此请务必不要将其关闭。
可选的 Instana 代理服务 (通过在 Kubernetes 上使用 Instana 代理 Helm 图表提供)与
remote_writeAPI 结合使用时非常有用。 通过使用 Instana 代理服务,数据会被推送到运行在同一 Kubernetes 节点上的 Instana 代理,从而使 Instana 代理能够正确填写基础设施关联数据。目前,
remote_write端点不支持认证,因此请勿在发送方中配置 Prometheus 的basic_auth和bearer_token(包括bearer_token_file) 选项。
TLS 远程写入加密
您可以在主机代理上启用 TLS 加密功能。 随后,发送到该 remote_write 端点的所有数据均采用 TLS 加密。
有关如何设置 TLS 加密的更多信息,请参阅《 启用 TLS 加密 》。
基础架构相关性
有关在 Linux 主机上进行基础设施关联的信息,请参阅代理的 HTTP API 端点。
变化量计数器
您可以通过将其与上一个值进行比较,来计算计数器的增量。 然而, Prometheus 用户界面中用于此类测量的聚合 increase 功能可能会产生错误结果,因为它会忽略在同一桶内计数器重置后立即发生的增量。 有关的更多信息,请参阅 PrometheusCounter 文档。
Delta counters 通过准确测量价值的增长来解决这一问题,同时容许计数器的重置。 对于每个指标,都会生成一个相应的增量指标。 例如,来自 fooPrometheus 端点的计数器指标会生成以下两个指标:
metrics.counters.foometrics.delta_counters.foo
这些指标的生成可在配置文件中进行 configuration.yaml配置:
com.instana.plugin.prometheus:
---
sendCounterMetrics: true
sendDeltaCounterMetrics: true
和 默认 CountersDelta counters 均已启用。 如果您只需要 Delta counters,可以通过设置以下参数来禁用 Counters :
sendCounterMetrics: false
查看度量值
要查看度量,请完成以下步骤:
- 在 Instana 用户界面的侧边栏中,选择 “基础设施”。
- 单击特定受监视主机。
然后,您可以看到包含所有收集的度量值和受监视流程的主机仪表板。
Prometheus 度量值显示为“Prometheus 应用程序”,这些应用程序与主机或从中收集这些度量值的流程相关联(如果使用remote_write端点)。 您可以使用“动态聚焦”、“事件和警报”以及“ Grafana ” entity.type:prometheus插件查询 Prometheus 的自定义指标。
Prometheus 传感器收集所有核心度量类型,每种类型最多 600 个度量:
- 计数器
- 标尺
- 直方图
- 摘要
- 非类型化
正在发出警报
创建一个 Prometheus Alertmanager Webhook 警报通道
要创建一个 Prometheus Alertmanager Webhook 警报通道,请在 Instana 用户界面中依次点击“设置” > “全局设置” > “事件与警报 ”> “警报通道 ”> “添加警报通道 ”,然后点击 Prometheus Alertmanager Webhook。

Instana 通过此警报通道发送警报,具体方式是向已配置的 Prometheus Alertmanager Webhook 接收器 (例如 Alert Snitch 或 SNMP Notifier )发送 HTTP POST 请求。
SNMP 通知器
SNMP 通知程序项目将 prometheus 警报作为 SNMP 陷阱传递到任何已配置的 SNMP 接收方。
Instana 在 Instana 镜像库中,未提供 SNMP 通知器的镜像。 如需了解更多信息,请按照 SNMP Notifier 中的说明操作。 有关安装 SNMP 通知程序的示例,请参阅 “在 Kubernetes 中运行 SNMP 通知程序 ”一节。
警报频道配置
您需要配置您创建的 Prometheus Alertmanager Webhook 警报通道,并将 Prometheus Alertmanager Webhook 接收器 URL 字段设置为 http://{SNMP-Notifier-Host}:9464/alerts. 如果 SNMP 通知器与 Instana 后端安装在同一个集群中,且位于名为 的命名空间 snmp-notifier内,则 Prometheus Alertmanager Webhook Receiver URL 的配置如下所示 http://snmp-notifier-alertmanager-snmp-notifier.snmp-notifier.svc:9464/alerts。
示例:在 Kubernetes 中运行 SNMP 通知程序
使用您的 Docker 中心凭据,为 SNMP 通知器创建一个命名空间,并为公共 Docker 注册表创建一个密钥:
kubectl create namespace snmp-notifier kubectl -n snmp-notifier create secret docker-registry image-pull-secret \ --docker-server=docker.io \ --docker-username=${YOUR_USERNAME} \ --docker-password=${YOUR_PASSWORD}使用将警报接收为 SNMP 陷阱的服务器 IP 地址,安装 SNMP 通知程序:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm install snmp-notifier prometheus-community/alertmanager-snmp-notifier \ -n snmp-notifier \ --set 'imagePullSecrets={image-pull-secret}' \ --set 'snmpNotifier.snmpDestinations={IP_ADDRESS_OF_SNMP_TRAP_RECEIVER_SERVER:162}'
有关 SNMP 通知程序配置的更多信息,请参阅 SNMP Notifier。 有关所有受支持的图表参数及其默认值的详细信息,请参阅 values.yaml。
故障诊断
远程写入高指标延迟
监控问题类型: prometheus_remote_write_high_delay
正在以高延迟接收从 remote_write 端点摄入的 Prometheus 个度量值。 此问题可能会导致警报延迟,并使来自其他来源的相关度量更加困难。
调整 Prometheus remote_write 配置。 具体来说,按如下所示添加 batch_send_deadline 参数,这会将延迟限制为 1 秒:
remote_write:
- url: "http://xxx.xxx.xxx.xxx:42699/prometheus/v1/receive"
queue_config:
batch_send_deadline: 1s
有关更多配置选项,请参阅 Prometheus 手册。
Prometheus 度量单位解析错误
监控问题类型: prometheus_metric_parse_error
Prometheus 度量包含不符合 prometheus 度量规范的信息。 这个问题有可能导致无法处理来自端点的某些 prometheus 指标。 使用监控问题信息确定问题原因并纠正 prometheus 端点。