对于目标发现,Managed Service for Prometheus Operator 需要与同一命名空间中的 Apache HTTP 服务器导出器对应的 PodMonitoring 资源。
您可以使用以下 PodMonitoring 配置:
# Copyright 2023 Google LLC## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## https://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.apiVersion:monitoring.googleapis.com/v1kind:PodMonitoringmetadata:name:httpdlabels:app.kubernetes.io/name:httpdapp.kubernetes.io/part-of:google-cloud-managed-prometheusspec:endpoints:-port:prometheusscheme:httpinterval:30spath:/metricsselector:matchLabels:app.kubernetes.io/name:httpd
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-30。"],[],[],null,["# Apache Web Server (httpd)\n\n\u003cbr /\u003e\n\nThis document describes how to configure your Google Kubernetes Engine deployment\nso that you can use Google Cloud Managed Service for Prometheus to collect metrics from\n\nApache Web Server (httpd). This document shows you how to do the following:\n\n- Set up the exporter for Apache Web Server to report metrics.\n- Configure a PodMonitoring resource for Managed Service for Prometheus to collect the exported metrics.\n- Access a dashboard in Cloud Monitoring to view the metrics.\n\n\u003cbr /\u003e\n\nThese instructions apply only if you are using [managed collection](/stackdriver/docs/managed-prometheus/setup-managed)\nwith Managed Service for Prometheus.\nIf you are using self-deployed collection, then see the\n\n[source repository](https://github.com/Lusitaniae/apache_exporter)\nfor the Apache HTTP exporter\n\nfor installation information.\n\nThese instructions are provided as an example and are expected to work in\nmost Kubernetes environments.\n\nIf you are having trouble installing an\napplication or exporter due to restrictive security or organizational policies,\nthen we recommend you consult open-source documentation for support.\n\nFor information about Apache Web Server (httpd), see [Apache HTTP](https://httpd.apache.org/).\n\nPrerequisites\n-------------\n\nTo collect metrics from\n\nApache Web Server\n\nby using\nManaged Service for Prometheus and managed collection, your deployment must\nmeet the following requirements:\n\n- Your cluster must be running Google Kubernetes Engine version 1.21.4-gke.300 or later.\n- You must be running Managed Service for Prometheus with managed collection enabled. For more information, see [Get started with managed collection](/stackdriver/docs/managed-prometheus/setup-managed).\n\n \u003cbr /\u003e\n\n- To use dashboards available in Cloud Monitoring for the Apache Web Server integration, you must use `httpd_exporter` version v1.0.0 or later.\n\n For more information about available dashboards, see\n\n [View dashboards](#monitoring-dashboard).\n\n\u003cbr /\u003e\n\nInstall the Apache Web Server exporter\n--------------------------------------\n\nWe recommend that you install the Apache Web Server exporter,\n[`httpd_exporter`](https://github.com/Lusitaniae/apache_exporter),\nas a sidecar to your Apache Web Server workload.\nFor information about using sidecars, see\n[Extended applications on Kubernetes with multi-container\npods](https://learnk8s.io/sidecar-containers-patterns).\n\nTo install `httpd_exporter` as a sidecar to Apache Web Server,\nmodify your Apache Web Server configuration as shown in the following\nexample: \n\n # Copyright 2023 Google LLC\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # https://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n apiVersion: v1\n kind: ConfigMap\n metadata:\n name: httpd\n data:\n httpd.conf: |\n ...\n + \u003cLocation \"/server-status\"\u003e\n + SetHandler server-status\n + \u003c/Location\u003e\n + LoadModule status_module modules/mod_status.so\n ...\n ---\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: httpd\n spec:\n replicas: 1\n selector:\n matchLabels:\n + app.kubernetes.io/name: httpd\n template:\n metadata:\n labels:\n + app.kubernetes.io/name: httpd\n spec:\n containers:\n - name: httpd\n image: httpd:2.4\n ports:\n - containerPort: 80\n name: httpd\n + volumeMounts:\n + - mountPath: /usr/local/apache2/conf/httpd.conf\n + subPath: httpd.conf\n + name: httpd\n + - name: httpd-exporter\n + image: lusotycoon/apache-exporter:v1.0.0\n + ports:\n + - containerPort: 9117\n + name: prometheus\n + command: [\"/bin/apache_exporter\"]\n + args: [\"--scrape_uri=http://localhost/server-status?auto\", \"--web.listen-address=:9117\", \"--telemetry.endpoint=/metrics\"]\n + volumes:\n + - name: httpd\n + configMap:\n + name: httpd\n + items:\n + - key: httpd.conf\n + path: httpd.conf\n\nYou must add any lines preceded by the `+` symbol to your\nconfiguration.\nThese instructions assume you already have a working Apache Web Server installation and want to modify it to include an exporter. Apache HTTP server can be configured to serve metrics on `/server-status` by modifying the configuration with a new `Location` directive and by loading the [status_module](https://httpd.apache.org/docs/2.4/mod/mod_status.html).\n\nTo apply configuration changes from a local file, run the following command:\n\n```\nkubectl apply -n NAMESPACE_NAME -f FILE_NAME\n```\n\n\u003cbr /\u003e\n\nYou can also\n[use Terraform](/stackdriver/docs/managed-prometheus/setup-managed#terraform-scrape)\nto manage your configurations.\n\nDefine a PodMonitoring resource\n-------------------------------\n\nFor target discovery, the Managed Service for Prometheus Operator\nrequires a PodMonitoring resource that corresponds to the Apache HTTP exporter\nin the same namespace.\n\nYou can use the following PodMonitoring configuration: \n\n # Copyright 2023 Google LLC\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # https://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n apiVersion: monitoring.googleapis.com/v1\n kind: PodMonitoring\n metadata:\n name: httpd\n labels:\n app.kubernetes.io/name: httpd\n app.kubernetes.io/part-of: google-cloud-managed-prometheus\n spec:\n endpoints:\n - port: prometheus\n scheme: http\n interval: 30s\n path: /metrics\n selector:\n matchLabels:\n app.kubernetes.io/name: httpd\n\nEnsure that the label selectors and the port match the selectors and port\nused in\n[Install the Apache Web Server exporter](#install-exporter).\n\nTo apply configuration changes from a local file, run the following command:\n\n```\nkubectl apply -n NAMESPACE_NAME -f FILE_NAME\n```\n\n\u003cbr /\u003e\n\nYou can also\n[use Terraform](/stackdriver/docs/managed-prometheus/setup-managed#terraform-scrape)\nto manage your configurations.\n\nVerify the configuration\n------------------------\n\nYou can use Metrics Explorer to verify that you correctly configured\nthe Apache HTTP exporter. It might take one or two minutes for\nCloud Monitoring to ingest your metrics.\n\nTo verify the metrics are ingested, do the following:\n\n1. In the Google Cloud console, go to the\n *leaderboard* **Metrics explorer** page:\n\n [Go to **Metrics explorer**](https://console.cloud.google.com/monitoring/metrics-explorer)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Monitoring**.\n2. In the toolbar of the query-builder pane, select the button whose name is either *code* **MQL** or *code* **PromQL**.\n3. Verify that **PromQL** is selected in the **Language** toggle. The language toggle is in the same toolbar that lets you format your query.\n4. Enter and run the following query: \n\n ```\n up{job=\"httpd\", cluster=\"CLUSTER_NAME\", namespace=\"NAMESPACE_NAME\"}\n ```\n\n\u003cbr /\u003e\n\nView dashboards\n---------------\n\nThe Cloud Monitoring integration includes\n\nthe **Apache Prometheus Overview** dashboard.\n\nDashboards are automatically installed when you configure the integration.\nYou can also view static previews of dashboards without installing the\nintegration.\n\n\nTo view an installed dashboard, do the following:\n\n1. In the Google Cloud console, go to the **Dashboards** page:\n\n [Go to **Dashboards**](https://console.cloud.google.com/monitoring/dashboards)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Monitoring**.\n2. Select the **Dashboard List** tab.\n3. Choose the **Integrations** category.\n4. Click the name of the dashboard, for example, **Apache Prometheus Overview**.\n\n\u003cbr /\u003e\n\nTo view a static preview of the dashboard, do the following:\n\n1. In the Google Cloud console, go to the\n **Integrations**\n page:\n\n [Go to **Integrations**](https://console.cloud.google.com/monitoring/integrations)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Monitoring**.\n2. Click the **Kubernetes Engine** deployment-platform filter.\n3. Locate the Apache Web Server (httpd) integration and click **View Details**.\n4. Select the **Dashboards** tab.\n\n\u003cbr /\u003e\n\nTroubleshooting\n---------------\n\nFor information about troubleshooting metric ingestion problems, see\n[Problems with collection from exporters](/stackdriver/docs/managed-prometheus/troubleshooting#exporter-problems) in [Troubleshooting ingestion-side problems](/stackdriver/docs/managed-prometheus/troubleshooting#ingest-problems)."]]