ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
[TOC] ## metrics - 收集的服务器运行指标 - [Prometheus普罗米修斯](https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format)或[OpenMetrics格式](https://pkg.go.dev/github.com/prometheus/client_golang@v1.7.1/prometheus/promhttp#HandlerOpts)(`application/openmetrics-text`)协商返回指标 - 返回内容说明[metrics 文档](https://caddyserver.com/docs/metrics) ### Prometheus 普罗米修斯 - [Prometheus](https://prometheus.io/)是一个监视平台,它通过在这些目标上收集度量标准HTTP端点来从被监视的目标收集度量标准。除了使用[Grafana](https://grafana.com/docs/grafana/latest/getting-started/what-is-grafana/)等仪表盘工具帮助您显示指标[外](https://grafana.com/docs/grafana/latest/getting-started/what-is-grafana/),Prometheus还用于[警报](https://prometheus.io/docs/alerting/latest/overview/) - 像Caddy一样,Prometheus用Go编写 运行普罗米修斯 ``` # prometheus.yaml global: scrape_interval: 15s # default is 1 minute scrape_configs: - job_name: caddy static_configs: - targets: ['localhost:2019'] ``` 执行 ``` prometheus --config.file=prometheus.yaml ``` ### metrics 指标 详情点击[metrics 指标](https://caddyserver.com/docs/metrics) 分为三类 #### 运行时指标 - 这些度量标准涵盖了Caddy流程的内部,并且由Prometheus Go Client自动提供。 - 以`go_*`和开头`process_*` #### 管理员API指标 - 这些指标有助于监控Caddy管理员API。每个管理端点都可以跟踪请求计数和错误。 - 这些指标以开头`caddy_admin_*`。 ``` > curl -s http://localhost:2019/metrics | grep ^caddy_admin caddy_admin_http_requests_total{code="200",handler="admin",method="GET",path="/config/"} 1 caddy_admin_http_requests_total{code="200",handler="admin",method="GET",path="/debug/pprof/"} 2 caddy_admin_http_requests_total{code="200",handler="admin",method="GET",path="/debug/pprof/cmdline"} 1 caddy_admin_http_requests_total{code="200",handler="load",method="POST",path="/load"} 1 caddy_admin_http_requests_total{code="200",handler="metrics",method="GET",path="/metrics"} 3 ``` #### HTTP中间件指标 所有Caddy HTTP中间件处理程序都会自动进行检测,以确定请求等待时间,到第一个字节的时间,错误以及请求/响应正文大小 ### 实例 ``` # 指定统计的地址 , 访问 /metrics 获取信息 metrics /metrics ```