提交 8018e575 编写于 作者: A alv00

realize the adaptation to OB 4.0. Add rootService judgment and OB version...

realize the adaptation to OB 4.0. Add rootService judgment and OB version judgment, and modify the collection configuration of ob_table, ob_plan_cache, and ob_index. Achieve compatibility with OB v3.x and v4.x
上级 e7da5129
FROM golang:1.16 as builder
WORKDIR /workspace
RUN echo '----------- DATE_CHANGE: Add this line to disable cache during docker building -------------------'
# Copy the Go Modules manifests
RUN mkdir /workspace/obagent
ADD . /workspace/obagent
# Build
RUN cd /workspace/obagent && make build-release
FROM openanolis/anolisos:8.4-x86_64
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
WORKDIR /home/admin
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
RUN useradd -m admin
RUN mkdir -p /home/admin/obagent/bin
RUN mkdir -p /home/admin/obagent/run
RUN mkdir -p /home/admin/obagent/log
RUN mkdir -p /home/admin/obagent/conf
COPY --from=builder /workspace/obagent/bin/monagent ./obagent/bin
COPY --from=builder /workspace/obagent/etc ./obagent/etc
RUN chown -R admin:admin /home/admin/obagent
ADD ./replace_yaml.sh /home/admin/obagent
ENTRYPOINT ["/tini", "--"]
CMD ["bash", "-c", " cd /home/admin/obagent && if [ \"`ls -A conf`\" == \"\" ]; then cp -r etc/* conf/ && ./replace_yaml.sh; fi && ./bin/monagent -c conf/monagent.yaml"]
文件已添加
......@@ -12,7 +12,31 @@ obInputBasic: &obInputBasic
ob_svr_ip: ${monagent.host.ip}
ob_svr_port: ${monagent.ob.rpc.port}
ob_is_rootservice: true
ob_is_v4: true
ob_is_v3: true
collectConfig:
- sql: select ob_version() REGEXP '^4' as ob_is_v4
name: ob_is_v4
conditionValues:
ob_is_v4: ob_is_v4
- sql: select ob_version() REGEXP '^3' as ob_is_v3
name: ob_is_v3
conditionValues:
ob_is_v3: ob_is_v3
- name: ob_role
sqlSlowThreshold: 100ms
metrics:
is_rootserver: with_rootserver
conditionValues:
ob_is_rootservice: with_rootserver
subConfig:
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ with_rootserver from __all_server where svr_ip = ? and svr_port = ?
params: [ ob_svr_ip, ob_svr_port ]
condition: ob_is_v3
- sql: select (case when with_rootserver='YES' then 1 else 0 end) as with_rootserver from DBA_OB_SERVERS where svr_ip = ? and svr_port = ?
params: [ ob_svr_ip, ob_svr_port ]
condition: ob_is_v4
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ tenant_name, cache_name, cache_size from __all_virtual_kvcache_info, __all_tenant where __all_tenant.tenant_id = __all_virtual_kvcache_info.tenant_id and svr_ip = ? and svr_port = ?
params: [ob_svr_ip, ob_svr_port]
name: ob_cache
......@@ -52,7 +76,17 @@ obInputBasic: &obInputBasic
cacheDataExpire: 120s
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(100000000) */ tenant_name, count(*) as cnt from gv$table group by tenant_id
name: ob_table
condition: ob_is_rootservice
condition: ob_is_v3 ob_is_rootservice
tags:
tenant_name: tenant_name
metrics:
num: cnt
enableCache: true
cacheExpire: 1h
cacheDataExpire: 2h
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(100000000) */ tenant_name, count(*) as cnt from CDB_TABLES join __all_tenant on CDB_TABLES.con_id = __all_tenant.tenant_id group by con_id
name: ob_table
condition: ob_is_v4 ob_is_rootservice
tags:
tenant_name: tenant_name
metrics:
......@@ -77,6 +111,16 @@ obInputBasic: &obInputBasic
current_timestamp: current
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ tenant_name, mem_used, access_count, hit_count from v$plan_cache_stat join __all_tenant on v$plan_cache_stat.tenant_id = __all_tenant.tenant_id
name: ob_plan_cache
condition: ob_is_v3
tags:
tenant_name: tenant_name
metrics:
memory_bytes: mem_used
access_total: access_count
hit_total: hit_count
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ tenant_name, mem_used, access_count, hit_count from V$OB_PLAN_CACHE_STAT join __all_tenant on V$OB_PLAN_CACHE_STAT.tenant_id = __all_tenant.tenant_id
name: ob_plan_cache
condition: ob_is_v4
tags:
tenant_name: tenant_name
metrics:
......@@ -115,7 +159,30 @@ obInputExtra: &obInputExtra
ob_svr_ip: ${monagent.host.ip}
ob_svr_port: ${monagent.ob.rpc.port}
ob_is_rootservice: true
ob_is_v4: true
ob_is_v3: true
collectConfig:
- sql: select ob_version() REGEXP '^4' as ob_is_v4
name: ob_is_v4
conditionValues:
ob_is_v4: ob_is_v4
- sql: select ob_version() REGEXP '^3' as ob_is_v3
name: ob_is_v3
conditionValues:
ob_is_v3: ob_is_v3
- name: ob_role
sqlSlowThreshold: 100ms
metrics:
is_rootserver: with_rootserver
conditionValues:
ob_is_rootservice: with_rootserver
subConfig:
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ with_rootserver from __all_server where svr_ip = ? and svr_port = ?
params: [ ob_svr_ip, ob_svr_port ]
condition: ob_is_v3
- sql: select (case when with_rootserver='YES' then 1 else 0 end) as with_rootserver from DBA_OB_SERVERS where svr_ip = ? and svr_port = ?
params: [ ob_svr_ip, ob_svr_port ]
condition: ob_is_v4
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ count(*) as cnt from v$unit
name: ob_unit
metrics:
......@@ -155,7 +222,12 @@ obInputExtra: &obInputExtra
expire_num: cnt
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(100000000) */ count(*) as cnt from gv$table where table_type in (5) and index_status in (5, 6)
name: ob_index
condition: ob_is_rootservice
condition: ob_is_v3 ob_is_rootservice
metrics:
error_num: cnt
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(100000000) */ count(*) as cnt from CDB_INDEXES where table_type in (5) and status in (5, 6)
name: ob_index
condition: ob_is_v4 ob_is_rootservice
metrics:
error_num: cnt
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ __all_tenant.tenant_name, active, total, freeze_trigger, freeze_cnt from gv$memstore, __all_tenant where gv$memstore.tenant_id = __all_tenant.tenant_id and ip = ? and port = ?
......
......@@ -14,6 +14,7 @@ package mysql
import (
"database/sql"
"strings"
"sync"
"time"
......@@ -143,16 +144,6 @@ func (t *TableInput) Init(config map[string]interface{}) error {
log.Info("table input init with config", t.Config)
nameMap := make(map[string]bool)
for _, collectConfig := range pluginConfig.CollectConfigs {
_, exists := nameMap[collectConfig.Name]
if exists {
return errors.Errorf("collect config %s already exists", collectConfig.Name)
} else {
nameMap[collectConfig.Name] = true
}
}
err = t.initDbConnection()
if err != nil {
return errors.Wrap(err, "db init connection")
......@@ -285,19 +276,23 @@ func (t *TableInput) doCollect(config *TableCollectConfig, metricChan chan metri
defer wg.Done()
currentTime := time.Now()
if len(config.Condition) > 0 {
value, found := t.ConditionValueMap.Load(config.Condition)
if !found {
log.Warn("Condition value not found:", config.Condition)
return
} else {
conditionSatisfied, ok := utils.ConvertToBool(value)
if !ok {
log.Warn("condition value convert failed")
return
}
if !conditionSatisfied {
log.Warn("condition not satisfied, skip do collect for:", config.Name)
conditionArray := strings.Split(config.Condition, " ")
for _, condition := range conditionArray {
value, found := t.ConditionValueMap.Load(condition)
if !found {
log.Warn("Condition value not found:", condition)
return
} else {
conditionSatisfied, ok := utils.ConvertToBool(value)
if !ok {
log.Warn("condition value convert failed")
return
}
if !conditionSatisfied {
log.Warn("condition not satisfied, skip do collect for:", config.Name)
return
}
}
}
}
......
#!/bin/bash
### 关闭这个功能
http_basic_auth_user='admin'
http_basic_auth_password='root'
pprof_basic_auth_user='admin'
pprof_basic_auth_password='root'
monitor_user=$monitor_user
monitor_password=$monitor_password
sql_port='2881'
rpc_port='2882'
ob_install_path='ori_path'
host_ip=$host_ip
cluster_name=$cluster_name
cluster_id=$cluster_id
zone_name=$zone_name
ob_monitor_status='active'
ob_log_monitor_status='inactive'
host_monitor_status='inactive'
alertmanager_address='temp'
disable_http_basic_auth='true'
disable_pprof_basic_auth='true'
### 配置 monagent_basic_auth.yaml
sed -i "s/{http_basic_auth_user}/${http_basic_auth_user}/g" ./conf/config_properties/monagent_basic_auth.yaml
sed -i "s/{http_basic_auth_password}/${http_basic_auth_password}/g" ./conf/config_properties/monagent_basic_auth.yaml
sed -i "s/{pprof_basic_auth_user}/${pprof_basic_auth_user}/g" ./conf/config_properties/monagent_basic_auth.yaml
sed -i "s/{pprof_basic_auth_password}/${pprof_basic_auth_password}/g" ./conf/config_properties/monagent_basic_auth.yaml
### 配置 monagent_pipeline.yaml
sed -i "s/{monitor_user}/${monitor_user}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{monitor_password}/${monitor_password}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{sql_port}/${sql_port}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{rpc_port}/${rpc_port}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{ob_install_path}/${ob_install_path}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{host_ip}/${host_ip}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{cluster_name}/${cluster_name}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{cluster_id}/${cluster_id}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{zone_name}/${zone_name}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{ob_monitor_status}/${ob_monitor_status}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{ob_log_monitor_status}/${ob_log_monitor_status}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{host_monitor_status}/${host_monitor_status}/g" ./conf/config_properties/monagent_pipeline.yaml
sed -i "s/{alertmanager_address}/${alertmanager_address}/g" ./conf/config_properties/monagent_pipeline.yaml
### 替换 ip
sed -i 's/127.0.0.1/${monagent.host.ip}/g' ./conf/module_config/monitor_ob.yaml
sed -i "s/{disable_http_basic_auth}/${disable_http_basic_auth}/g" ./conf/module_config/monagent_basic_auth.yaml
sed -i "s/{disable_pprof_basic_auth}/${disable_pprof_basic_auth}/g" ./conf/module_config/monagent_basic_auth.yaml
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册