容器化部署Prometheus

Posted givenchy_yzl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了容器化部署Prometheus相关的知识,希望对你有一定的参考价值。

使用kubernetes部署Prometheus

#下载Prometheus包并解压
[root@k8s-master-01 ~]# wget https://github.com/prometheus-operator/kube-prometheus/archive/refs/tags/v0.7.0.tar.gz
[root@k8s-master-01 ~]# tar -xf v0.7.0.tar.gz 

# 安装Prometheus
[root@k8s-master-01 ~]# cd kube-prometheus-0.7.0/manifests/setup
[root@k8s-master-01 setup]# kubectl apply -f ./
[root@k8s-master-01 setup]# cd ..
[root@k8s-master-01 ~/kube-prometheus-0.7.0/manifests]# kubectl apply -f ./

#查看Prometheus的服务
[root@k8s-master-01 ~]# kubectl get svc -n monitoring 
NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
alertmanager-main       ClusterIP   10.98.137.171    <none>        9093/TCP                     4d
alertmanager-operated   ClusterIP   None             <none>        9093/TCP,9094/TCP,9094/UDP   4d7h
grafana                 ClusterIP   10.107.21.11     <none>        3000/TCP                     4d
kube-state-metrics      ClusterIP   None             <none>        8443/TCP,9443/TCP            4d
node-exporter           ClusterIP   None             <none>        9100/TCP                     4d
prometheus-adapter      ClusterIP   10.100.126.154   <none>        443/TCP                      4d
prometheus-k8s          ClusterIP   10.96.118.32     <none>        9090/TCP                     4d
prometheus-operated     ClusterIP   None             <none>        9090/TCP                     4d7h
prometheus-operator     ClusterIP   None             <none>        8443/TCP                     4d7h

# 为Prometheus和grafana创建ingress
[root@k8s-master-01 ingress]# cat > ingress.yaml << EOF
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: prometheus
  namespace: monitoring
spec:
  rules:
    - host: "prometheus.test.com"
      http:
        paths:
          - backend:
              service:
                name: prometheus-k8s
                port: 
                  number: 9090
            path: "/"
            pathType: Prefix
---            
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: grafana
  namespace: monitoring
spec:
  rules:
    - host: "grafana.test.com"
      http:
        paths:
          - backend:
              service:
                name: grafana
                port:
                  number: 3000
            path: "/"
            pathType: Prefix
EOF

[root@k8s-master-01 ~]# kubectl apply -f ingress/ingress.yaml

[root@k8s-master-01 ~]# kubectl get ingress -n monitoring 

将prometheus.test.com,grafana.test.com加入本地解析
浏览器访问
prometheus.test.com:30080
grafana.test.com:30080

添加数据源后---->+ -----> import----> 搜索框输入官方GUI码
GUI码来源:grafana.com---->grafana---->dashborad---->数据源选择 Prometheus---->搜索kubernetes---->点击模板---->copy id to clipboard
成功:如下图

携带metircs接口的服务
1、jiang

[root@web02 ~]# cat /prometheus_mysql/.my.cnf
host=192.168.13.11
port=mysql的端口
[client]
user=mysql_monitor
password=abc123

Prometheus监控Java
1、修改pom.xml

	<dependencies>
		........
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>io.micrometer</groupId>
                <artifactId>micrometer-registry-prometheus</artifactId>
                <version>1.1.3</version>
            </dependency>
            <dependency>
                <groupId>io.github.mweirauch</groupId>
                <artifactId>micrometer-jvm-extras</artifactId>
                <version>0.2.0</version>
            </dependency>
		 ........
   </dependencies>

以上是关于容器化部署Prometheus的主要内容,如果未能解决你的问题,请参考以下文章

容器化 Prometheus 无法抓取 JMX-exporter

Prometheus部署监控容器

使用 Prometheus 监控容器化 Spark v2.1 应用程序

如何快速部署 Prometheus?- 每天5分钟玩转 Docker 容器技术(85)

Prometheus容器监控环境部署

部署 Prometheus Operator - 每天5分钟玩转 Docker 容器技术(179)