度量方案设计与度量值确定需要我们对服务架构有一定了解,比如GRPC微服务 我们关心的就是QPS、延迟、成功率(错误率)等数据; API Gateway 我们除了关心上述几个度量值,我们还关心并发请求数量,当前带宽等数据;无论哪种类型的服务与业务我们都关心运行环境的CPU/内存使用率等数据,以确定当前资源水位是否安全,是否有扩缩容的必要。
// The Handler function provides a default handler to expose metrics // via an HTTP server. "/metrics" is the usual endpoint for that. http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(":8080", nil)) }
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 7.7299e-05 go_gc_duration_seconds{quantile="0.25"} 9.7869e-05 go_gc_duration_seconds{quantile="0.5"} 0.000115081 go_gc_duration_seconds{quantile="0.75"} 0.000141982 go_gc_duration_seconds{quantile="1"} 0.088763487 go_gc_duration_seconds_sum 54.35006894 go_gc_duration_seconds_count 93984 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. -job_name:qietv_go consul_sd_configs: -server:172.17.3.79:8500 datacenter:tx tags: -metrics relabel_configs: -source_labels: ["__meta_consul_service_id"] target_label:"service_id" -source_labels: ["__meta_consul_service"] target_label:"service" -job_name:'mongo' static_configs: -targets: ['172.17.1.130:9216'] -job_name:etcd scheme:https tls_config: cert_file:/opt/etcd/cert/79/client.crt key_file:/opt/etcd/cert/79/client.key insecure_skip_verify:true static_configs: -targets: ['172.17.3.79:2379','172.17.3.80:2379','172.17.3.81:2379']
2. 基于Consul服务发现的微服务集群
参考
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: qietv_go consul_sd_configs: - server: 172.17.3.79:8500 datacenter: tx tags: - metrics relabel_configs: - source_labels: ["__meta_consul_service_id"] target_label: "service_id" - source_labels: ["__meta_consul_service"] target_label: "service"