prometheus api

如何配置prometheus的Java客户端 https://blog.csdn.net/frog4/article/details/84579165

一、文档资料

1.prometheus官方http API

https://prometheus.io/docs/prometheus/1.8/querying/api/ 可以根据使用的版本选择API
prometheus api_第1张图片

2.prometheus-operator

k8s集群使用prometheus-operator做监控

文档 https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#prometheusspec

二、访问接口

http://192.168.14.176 为k8s master节点,根据实际部署替换

prometheus-operator

prometheus-operator部署prometheus集群监控

[root@docker176 ~]# kubectl -n monitoring get pod,svc
NAME                                      READY     STATUS    RESTARTS   AGE
po/alertmanager-main-0                    2/2       Running   2          
po/alertmanager-main-1                    2/2       Running   0          
po/alertmanager-main-2                    2/2       Running   0          
po/grafana-2388285037-7ql1n               2/2       Running   0          
po/kube-state-metrics-4004652727-9bvs3    1/1       Running   0          
po/node-exporter-q0z7t                    1/1       Running   0          
po/node-exporter-zhh9f                    1/1       Running   0          
po/prometheus-k8s-0                       2/2       Running   2          
po/prometheus-k8s-1                       2/2       Running   0          
po/prometheus-operator-1217885251-p8377   1/1       Running   0          

NAME                        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
svc/alertmanager-main       10.254.233.0            9093:30903/TCP      
svc/alertmanager-operated   None                     9093/TCP,6783/TCP   10h
svc/grafana                 10.254.30.106           3000:30902/TCP      
svc/kube-state-metrics      10.254.221.201           8080/TCP            
svc/node-exporter           None                     9100/TCP            
svc/prometheus-k8s          10.254.182.160          9090:30900/TCP      
svc/prometheus-operated     None                     9090/TCP            10h
svc/prometheus-operator     10.254.102.234           8080/TCP            

使用grafana请求

http://192.168.14.176:30902/api/datasources/proxy/1/api/v1/query_range?query=((sum(node_memory_MemTotal)%20-%20sum(node_memory_MemFree)%20-%20sum(node_memory_Buffers)%20-%20sum(node_memory_Cached))%20%2F%20sum(node_memory_MemTotal))%20*%20100&start=1550732384&end=1550810623&step=1800

直接请求prometheus

http://192.168.14.176:30900/api/v1/query_range?query=((sum(node_memory_MemTotal)%20-%20sum(node_memory_MemFree)%20-%20sum(node_memory_Buffers)%20-%20sum(node_memory_Cached))%20%2F%20sum(node_memory_MemTotal))%20*%20100&start=1550732384&end=1550810623&step=1800

上面面两个请求的结果相同
prometheus http://192.168.14.176:30900/api/v1/query_range
grafana http://192.168.14.176:30902/api/datasources/proxy/1/api/v1/query_range grafana通过k8s的datasources/proxy请求到prometheus中

三、常地址

http://192.168.14.176 为k8s master节点,根据实际部署替换

prometheus
http://192.168.14.176:30900

grafana UI
http://192.168.14.176:30902

Alertmanager
http://192.168.14.176:30903

你可能感兴趣的:(K8s,prometheus)