OpenShift采用Blackbox_exporter进行服务状态监控
本文主要是针对prometheus的blackbox_exporter,对集群中的服务进行状态的监控
因为OpenShift 3.11版本自己带的promethues修改起来有一些问题,所以自己安装和部署了自己的prometheus和grafana
1.BlackBox安装
blackbox的详细情况可以参考
https://github.com/prometheus/blackbox_exporter
安装过程如下
git clone https://github.com/prometheus/blackbox_exporter.git
在https://github.com/prometheus/blackbox_exporter/releases
下载最新版本的blackbox_exporter-0.14.0.linux-amd64.tar.gz , 解压放到相应的目录下,然后构建镜像
docker build -t blackbox_exporter .
blackbox可以直接通过docker run来运行在本地,比如
docker run -d -p 9115:9115 --name blackbox blackbox_exporter
但问题是我们需要针对ocp内部的服务进行监控,因此最好还是作为pod运行在ocp的内部,这样通过服务就可以获取固定的url.
2.Blackbox部署成为Pod
下面三条语句,比较简单了...
oc new-project blackbox oc import-image blackbox:latest --from=registry.example.com/openshift/blackbox_exporter:latest --insecure --confirm oc new-app blackbox:latest --name=blackbox
完成后看到有个blackbox pod在运行
3.部署prometheus
Prometheus部署使用的是
https://github.com/openshift/origin/tree/master/examples/prometheus
下载相关版本镜像,推送到registry.example.com,然后
oc new-project prometheus oc new-app -f prometheus.yaml -p NAMESPACE=prometheus
因为原本prometheus的配置是在内部的,为了便于修改,直接放到宿主机上。
将需要监控的url写入到prometheus.yml的配置
配置文件如下
[root@master prometheus]# cat prometheus.yml rule_files: - '*.rules' ..... - job_name: blackbox metrics_path: /probe params: module: [http_2xx] static_configs: - targets: - http://ericapp1.ericproject1:8080 - http://ericapp2.ericproject1:8080 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: blackbox.blackbox:9115 # Blackbox exporter. alerting: alertmanagers: - scheme: http static_configs: - targets: - "localhost:9093"
主要看blackbox这段.
oc create configmap prom-config --from-file=prometheus.yml oc set volume sts/prometheus --add --overwrite --name=config-volume --mount-path=/etc/prometheus/myconfig --source='{"configMap": { "name": "prom-config"}}'
然后进入console修改prometheus的yaml
一切完成,进入prometheus的主页面,看到相关的指标
4.部署grafana
可以参考
https://github.com/openshift/origin/tree/master/examples/grafana
https://labs.consol.de/development/2018/01/19/openshift_application_monitoring.html
oc new-project grafana oc new-app -f grafana.yaml -p NAMESPACE=grafana oc policy add-role-to-user view system:serviceaccount:grafana:grafana-ocp -n prometheus
登录grafana界面,添加数据源,这个数据源这里折腾了一段时间
因为是走的https,所以必须需要token,这个token值为
[root@master prometheus]# oc sa get-token grafana-ocp eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJncmFmYW5hIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImdyYWZhbmEtb2NwLXRva2VuLXhodDl2Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImdyYWZhbmEtb2NwIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiM2IyYmU5YjQtNThkMS0xMWU5LThlMDQtMDgwMDI3ZGM5OTFhIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmdyYWZhbmE6Z3JhZmFuYS1vY3AifQ.NAf03C7v42aBNrRbwLcIosKDFgv3WyBA2-jZ73RqmX-OyNkshzgkvO6RZDGU7Oi9x27Hu7S69CW-2nZBDqSuCKP_fOyr7pKkOZTHfmgnXQdOeqnG8WSGM5HMbMsLbrAgOMZSehG5jFos-FaJb6jYJwQx485u0ViwWcSN58y7m4unIyrXgvzvjCoFijIjoCcYOvJklZVAsToVIFnevOcXEdJhtoitFiG2Agg4_KSiEUOhhKzyvKCIOLfSZN1UGsicUx_vFmqix8ARmOegILJNdRHksBAXRdReZuaJlJ1-FJnh1j9-QVVSSgw2DP6JrMEhS9gV38VWiWhoizSZLqsgCw
Save Test后一定需要出现is working啊.
New Dashboard
singlestat->edit->metrics,修改options
修改完最后
好啦,搞定!