公司内使用部分华为云云服务,针对云服务可以采用云监控服务CES
进行监控。但是有较多的人员需要看监控图表,这就需要开通很多华为云账号。所以决定将部分华为云服务的监控接入到Prometheus
中,通过Grafana
出图展示。所有同事通过域账号登录Grafana
可查看监控图表。
实现思路:
- 通过华为云监控
CES
实现对华为云服务的监控。
- 通过cloudeye-exporter从云监控
CES
中获取监控指标。
服务器部署
安装cloudeye-exporter
下载安装
1
2
3
4
|
mkdir /opt/cloudeye-exporter
cd /usr/local/src/
wget https://github.com/huaweicloud/cloudeye-exporter/releases/download/v2.0.5/cloudeye-exporter.v2.0.5.tar.gz
tar xf cloudeye-exporter.v2.0.5.tar.gz -C /opt/cloudeye-exporter/
|
配置服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
cat /opt/cloudeye-exporter/clouds.yml
global:
prefix: "huaweicloud"
port: ":8087"
metric_path: "/metrics"
scrape_batch_size: 300
auth:
auth_url: "https://iam.af-south-1.myhuaweicloud.com/v3"
project_name: "af-south-1"
access_key: "xxxxxx"
secret_key: "xxxxxx"
region: "af-south-1"
|
以ops
用户启动,需要先创建用户并授权。
1
2
|
useradd ops
chown -R ops. /opt/cloudeye-exporter*
|
服务启动
systemd
配置文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
cat > /etc/systemd/system/cloudeye-exporter.service << EOF
[Unit]
Description=Cloudeye-exporter daemon
After=network.target
[Service]
ExecStart=/opt/cloudeye-exporter/cloudeye-exporter
User=ops
Group=ops
WorkingDirectory=/opt/cloudeye-exporter
PrivateTmp=True
[Install]
WantedBy=multi-user.target
EOF
|
启动
1
2
3
4
|
systemctl daemon-reload
systemctl enable cloudeye-exporter
systemctl start cloudeye-exporter
systemctl status cloudeye-exporter
|
K8S部署
ConfigMap
配置文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: cloudeye-exporter
name: cloudeye-exporter-cm
namespace: thanos
data:
clouds.yml: |
global:
prefix: "huaweicloud"
port: ":8087"
metric_path: "/metrics"
scrape_batch_size: 300
auth:
auth_url: "https://iam.af-south-1.myhuaweicloud.com/v3"
project_name: "af-south-1"
access_key: "xxxxx"
secret_key: "xxxxx"
region: "af-south-1"
|
Deployment
配置文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudeye-exporter
namespace: thanos
labels:
app: cloudeye-exporter
spec:
selector:
matchLabels:
app: cloudeye-exporter
template:
metadata:
labels:
app: cloudeye-exporter
spec:
containers:
- image: ennnan/cloudeye-exporter:v1.0
imagePullPolicy: Always
name: cloudeye-exporter
ports:
- containerPort: 8087
name: http
volumeMounts:
- name: config
mountPath: "/opt/clouds.yml"
subPath: clouds.yml
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: 500m
memory: 1024Mi
livenessProbe:
failureThreshold: 5
initialDelaySeconds: 30
periodSeconds: 30
successThreshold: 1
tcpSocket:
port: 8087
timeoutSeconds: 10
readinessProbe:
failureThreshold: 5
initialDelaySeconds: 30
periodSeconds: 30
successThreshold: 1
tcpSocket:
port: 8087
timeoutSeconds: 10
restartPolicy: Always
volumes:
- name: config
configMap:
name: cloudeye-exporter-cm
|
Service
配置文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
apiVersion: v1
kind: Service
metadata:
name: cloudeye-exporter
namespace: thanos
spec:
ports:
- name: cloudeye-exporter
port: 8087
protocol: TCP
targetPort: 8087
selector:
app: cloudeye-exporter
type: ClusterIP
|
Prometheus
配置Prometheus
,从cloudeye-exporter
获取数据。其中SYS.DMS
为华为云资源名称,不同的资源最好使用不同的job
。具体可参考官方文档。
1
2
3
4
5
|
- job_name: huaweicloud-DMS
static_configs:
- targets: ['cloudeye-exporter.thanos.svc.cluster.local:8087']
params:
services: ['SYS.DMS']
|
若Prometheus
不能正常采集到数据,可以进入到容器,执行以下命令,看是否有返回。
1
|
curl http://localhost:8087/metrics?services=SYS.DMS
|
Grafana
请参考官方文档