prometheus监控Oracle

创建secret秘钥 指定相关namespace
kubectl create secret generic oracledb-exporter-secret     --from-literal=datasource='admin_li/dbadmin@//172.18.46.28:1521/dpdg' -n monitoring



        secretKeyRef :
          name: oracledb-exporter-secret
          key: datasource

要保持secret 与secretKeyRef name的一致性

创建相关configmap文件主要是一些查询语句

vim  oracledb-exportercm.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: oracle-metrics #与configmap名称一致
  namespace: monitoring
data:
  custom-metrics.toml: |
    [[metric]]
    context = "slow_queries"
    metricsdesc = { p95_time_usecs= "Gauge metric with percentile 95 of elapsed time.", p99_time_usecs= "Gauge metric with percentile 99 of elapsed time." }
    request = "select  percentile_disc(0.95)  within group (order by elapsed_time) as p95_time_usecs, percentile_disc(0.99)  within group (order by elapsed_time) as p99_time_usecs from v$sql where last_active_time >= sysdate - 5/(24*60)"
    [[metric]]
    context = "big_queries"
    metricsdesc = { p95_rows= "Gauge metric with percentile 95 of returned rows.", p99_rows= "Gauge metric with percentile 99 of returned rows." }
    request = "select  percentile_disc(0.95)  within group (order by rownum) as p95_rows, percentile_disc(0.99)  within group (order by rownum) as p99_rows from v$sql where last_active_time >= sysdate - 5/(24*60)"
    [[metric]]
    context = "size_user_segments_top100"
    metricsdesc = {table_bytes="Gauge metric with the size of the tables in user segments."}
    labels = ["segment_name"]
    request = "select * from (select segment_name,sum(bytes) as table_bytes from user_segments where segment_type='TABLE' group by segment_name) order by table_bytes DESC FETCH NEXT 100 ROWS ONLY"
    [[metric]]
    context = "size_user_segments_top100"
    metricsdesc = {table_partition_bytes="Gauge metric with the size of the table partition in user segments."}
    labels = ["segment_name"]
    request = "select * from (select segment_name,sum(bytes) as table_partition_bytes from user_segments where segment_type='TABLE PARTITION' group by segment_name) order by table_partition_bytes DESC FETCH NEXT 100 ROWS ONLY"
    [[metric]]
    context = "size_user_segments_top100"
    metricsdesc = {cluster_bytes="Gauge metric with the size of the cluster in user segments."}
    labels = ["segment_name"]
    request = "select * from (select segment_name,sum(bytes) as cluster_bytes from user_segments where segment_type='CLUSTER' group by segment_name) order by cluster_bytes DESC FETCH NEXT 100 ROWS ONLY"
    [[metric]]
    context = "size_dba_segments_top100"
    metricsdesc = {table_bytes="Gauge metric with the size of the tables in user segments."}
    labels = ["segment_name"]
    request = "select * from (select segment_name,sum(bytes) as table_bytes from dba_segments where segment_type='TABLE' group by segment_name) order by table_bytes DESC FETCH NEXT 100 ROWS ONLY"
    [[metric]]
    context = "size_dba_segments_top100"
    metricsdesc = {table_partition_bytes="Gauge metric with the size of the table partition in user segments."}
    labels = ["segment_name"]
    request = "select * from (select segment_name,sum(bytes) as table_partition_bytes from dba_segments where segment_type='TABLE PARTITION' group by segment_name) order by table_partition_bytes DESC FETCH NEXT 100 ROWS ONLY"
    [[metric]]
    context = "size_dba_segments_top100"
    metricsdesc = {cluster_bytes="Gauge metric with the size of the cluster in user segments."}
    labels = ["segment_name"]
    request = "select * from (select segment_name,sum(bytes) as cluster_bytes from dba_segments where segment_type='CLUSTER' group by segment_name) order by cluster_bytes DESC FETCH NEXT 100 ROWS ONLY"


创建deployment,service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: oracledb-exporter-4628  #应用名
  namespace: monitoring  #namespace
spec:
  selector:
    matchLabels:
      app: oracledb-exporter-4628 #应用名
  replicas: 1
  template:
    metadata:
      labels:
        app: oracledb-exporter-4628 #应用名
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9161" #更改端口要与下面容器端口保持一致
        prometheus.io/path: "/metrics"
    spec:
      containers:
      - name: oracledb-exporter-4628#应用名
        ports:
        - containerPort: 9161 #容器端口
        image: hc.k8s-registry.mysteel.local/base/oracledb_exporter:0.3.2 #镜像
        env: #环境变量
        - name: DATA_SOURCE_NAME 
          valueFrom: 
            secretKeyRef: # oracle相关密码信息
              name: oracledb-exporter-secret
              key: datasource
        - name: ORACLE_METRICS #真实挂载配置文件
          value: /tmp/custom-metrics.toml
        volumeMounts: #虚拟挂载文件
          - name:  oracle-metrics
            mountPath:  /tmp/custom-metrics.toml
            subPath: oracle-metrics.toml
      volumes: #加载配置文件
        - name: oracle-metrics
          configMap:
            defaultMode: 420
            name: oracle-metrics
---
apiVersion: v1
kind: Service
metadata:
  name: oracledb-exporter-4628  #应用名
  namespace: monitoring  #namespace
  labels:
    app: oracledb-exporter-4628  #应用名
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 9161  #暴露端口
      targetPort: 9161
      protocol: TCP
  selector:
    app: oracledb-exporter-4628

其他配置与Redis一致
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值