Prometheus
使用 Prometheus 收集度量資料越來越受歡迎。 使用 Instana ,很容易擷取 Prometheus 度量值,並使用廣泛的知識圖來使它們產生關聯。 一般範例是自訂商業度量值。
安裝 Instana 主機代理程式之後,會自動安裝 Instana Prometheus 感應器,但您需要依照 配置 小節中的說明來配置感應器。 然後,您可以在 Instana 使用者介面中檢視與 Prometheus 相關的度量值。
Instana 提供 Prometheus Alertmanager Webhook 警示通道,以傳送具有 Prometheus Alertmanager Webhook 有效負載格式的 HTTP POST 要求,如 Prometheus Alertmanager Webhook 接收端配置中所述。
若要即時將警示通知從 Instana 傳送至 Prometheus ,請在 Instana 使用者介面中建立 Prometheus Alertmanager Webhook 警示通道 。 然後, HTTP POST 要求會傳送至 Prometheus。
簡介
Instana Prometheus 感應器不需要 Prometheus 伺服器。 感應器會直接從受監視系統所公開的端點擷取度量。
針對每一個 Instana 主機代理程式,指定您要輪詢哪些 Prometheus 端點,以及需要使用正規表示式從它們收集哪些度量值。 如需相關資訊,請參閱 配置 一節。
附註: 如果您的度量值是由 Java 程式庫公開 (例如 Micrometer、 Prometheus Java 用戶端程式庫或 jmx_exporter) ,則不需要透過 HTTP 公開它們,因為 Instana Java 外掛程式可以直接從這些程式庫收集度量值:
主題 Micrometer 顯示如何收集 Micrometer 度量。
Prometheus-java-client 主題顯示如何從 Prometheus Java 用戶端程式庫 或從 Micrometer 的 Prometheus Meter Registry收集度量。
Jmx 主題顯示如何從 JMX Bean 收集自訂度量值。
配置
Kubernetes 環境的配置
您需要在主機代理程式配置檔 <agent_install_dir>/etc/instana/configuration.yaml 中定義度量來源作為端點清單。 當 Instana 主機代理程式在 Kubernetes 環境中執行時,代理程式會自動辨識並從執行中 Pod 收集 IP 及容器埠。
請參閱下列配置範例:
com.instana.plugin.prometheus:
# Global polling interval in seconds (optional)
poll_rate: 15 # Default is 1 second
# Global (all) endpoints username/password configuration (optional)
username: ''
password: ''
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: '.*'
附註:
若為 Kubernetes 環境,請不要將主機和埠資訊新增至
url欄位,只新增度量值端點 URL (例如/prometheus/endpoint/metrics)。 Prometheus 感應器不是監視指定為完整 URL 的端點,例如https://prod-myapp.server.com/prometheus/metrics。透過在
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
# Global (all) endpoints username/password configuration (optional)
username: ''
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'
附註: 如果未定義 metricNameIncludeRegex ,則 Prometheus 感應器會收集 所有度量類型 ,且每個度量類型的定義限制為 600 個度量 。
遠端寫入
從 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端點位於埠42699上的/prometheus/v1/receive路徑。 因此,您需要在 Prometheus 配置中配置的 URL 是http://<agent_ip>:42699/prometheus/v1/receive。如果要使 Instana 剖析度量值正確,傳送者 必須 傳送 meta 資料。 寄件者是 Prometheus中的預設值,因此請確保不要關閉它。
Kubernetes 上使用 Instana 代理程式 Helm 圖表所提供的選用 Instana 代理程式服務,在與
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 端點。
檢視度量值
若要檢視度量值,請完成下列步驟:
- 在 Instana 使用者介面的資訊看板中,選取 基礎架構。
- 按一下特定的受監視主機。
然後,您可以查看包含所有已收集度量及受監視處理程序的主機儀表板。
Prometheus 度量值顯示為與主機或從中收集它們的處理程序相關聯的 "Prometheus Apps" (如果使用 remote_write 端點)。 您可以使用「動態焦點」、「事件及警示」及「Grafana 外掛程式」與 entity.type:prometheus搭配,來查詢 Prometheus 自訂度量值。
Prometheus 感應器會收集所有核心度量類型,每種類型最多 600 個度量:
- 計數器
- 量規
- 直方圖
- 摘要
- 未指定類型
警示
建立 Prometheus Alertmanager Webhook 警示通道
若要建立 Prometheus Alertmanager Webhook 警示通道,請按一下 Instana 使用者介面中的 設定 > 團隊設定 > 事件與警示 > 警示通道 > 新增警示通道 ,然後按一下 Prometheus Alertmanager Webhook。

Instana 會以 HTTP POST 要求形式,透過此警示通道將警示傳送至已配置的 Prometheus Alertmanager Webhook Receiver,例如 Alert Snitch 或 SNMP Notifier。
SNMP 通知程式
SNMP Notifier 專案 會將 Prometheus 警示作為 SNMP 設陷轉遞至任何已配置的 SNMP 接收端。
為了確保與 Instana 警示適當互動, Instana 為 SNMP Notifier 提供 Docker 映像檔,並在 Instana 專用 Docker 登錄中具有自訂警示對映。 如需相關資訊,請參閱 使用 Docker執行 及 在 Kubernetes。
警示通道配置
您需要配置您所建立的 Prometheus Alertmanager Webhook 警示通道,並設定 Prometheus Alertmanager Webhook 接收端 URL 欄位,如下所示:
Prometheus Alertmanager Webhook 接收端 URL: http://{SNMP-Notifier-Host}:9464/alerts。
SNMP 通知程式配置
您需要透過將下列項目指定為儲存器環境變數,來配置 SNMP Notifier 服務:
SNMP_VERSION = SNMP version. "V2c" and "V3" are currently supported. (Default: "V2c")
SNMP_DESTINATION = SNMP trap server destination. (Default: "127.0.0.1:162")
SNMP_RETRIES = SNMP number of retries. (Default: "1")
SNMP_TRAP_DEFAULT_OID = Trap OID to send if none is found in the alert labels. (Default: "1.3.6.1.4.1.98789.0.1")
SNMP_COMMUNITY = SNMP community (V2c only). (Default: "public")
SNMP_AUTHENTICATION_ENABLED = Enable SNMP authentication (V3 only). (Default: "false")
SNMP_AUTHENTICATION_PROTOCOL = Protocol for password encryption (V3 only). MD5 and SHA are currently supported. (Default: MD5)
SNMP_AUTHENTICATION_USERNAME = SNMP authentication username (V3 only).
SNMP_AUTHENTICATION_PASSWORD = SNMP authentication password (V3 only).
SNMP_PRIVATE_ENABLED = Enable SNMP encryption (V3 only). (Default: "false")
SNMP_PRIVATE_PROTOCOL = Protocol for SNMP data transmission (V3 only). DES and AES are currently supported (Default: "DES").
SNMP_PRIVATE_PASSWORD = SNMP private password (V3 only).
SNMP_SECURITY_ENGINE_ID = SNMP security engine ID (V3 only).
SNMP_CONTEXT_ENGINE_ID = SNMP context engine ID (V3 only).
SNMP_CONTEXT_NAME = SNMP context name (V3 only).
使用 Docker 執行
登入 Instana Docker 登錄。
sudo docker login https://containers.instana.io -u="_" -p="${AGENT_KEY}"啟動 Docker 儲存器。
sudo docker run -p 9464:9464/tcp --env SNMP_DESTINATION=127.0.0.1:162 --env GROUP_ID=1001 --env USER_ID=1002 containers.instana.io/instana/release/product/snmpnotifier:2.164.224-0
在 Kubernetes
建立 Instana Docker 登錄的密鑰。
kubectl create secret docker-registry instana \ --docker-server=https://containers.instana.io \ --docker-username=_ \ --docker-password=${AGENT_KEY}依照下列方式來配置部署和服務描述子:
--- apiVersion: apps/v1 kind: Deployment metadata: name: instana-snmp-notifier-deployment labels: instana.io/component: instana-snmp-notifier spec: replicas: 1 selector: matchLabels: app: instana-snmp-notifier template: metadata: labels: app: instana-snmp-notifier spec: containers: - env: - name: GROUP_ID value: '1001' - name: USER_ID value: '1002' - name: SNMP_DESTINATION value: 127.0.0.1:162 image: containers.instana.io/instana/release/product/snmpnotifier:2.164.224-0 name: instana-snmp-notifier ports: - containerPort: 9464 name: web-endpoint protocol: TCP resources: limits: cpu: 500m memory: 512Mi requests: cpu: 500m memory: 256Mi imagePullSecrets: - name: instana --- apiVersion: v1 kind: Service metadata: name: instana-snmp-notifier-service spec: type: ClusterIP ports: - name: web-endpoint port: 9464 targetPort: 9464 protocol: TCP selector: app: instana-snmp-notifier
疑難排解
遠端寫入高度量延遲
監視問題類型: 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 手冊。