提交 2525cbba 编写于 作者: 雪染

Merge branch 'adaptV4' into 'master'

Adapt v4



See merge request !1754150
......@@ -11,3 +11,4 @@
*.dylib
*.test
*.out
bin/*
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"]
......@@ -11,8 +11,39 @@ obInputBasic: &obInputBasic
defaultConditionValues:
ob_svr_ip: ${monagent.host.ip}
ob_svr_port: ${monagent.ob.rpc.port}
ob_is_rootservice: true
ob_is_rootservice: false
ob_is_v4: false
ob_is_v3: false
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
conditions: [ ob_is_v3 ]
params: [ ob_svr_ip, ob_svr_port ]
sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ with_rootserver from __all_server where svr_ip = ? and svr_port = ?
- name: ob_role
sqlSlowThreshold: 100ms
metrics:
is_rootserver: with_rootserver
conditionValues:
ob_is_rootservice: with_rootserver
conditions: [ ob_is_v4 ]
params: [ ob_svr_ip, ob_svr_port ]
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 = ?
- 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 +83,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
conditions: [ 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
conditions: [ ob_is_v4, ob_is_rootservice ]
tags:
tenant_name: tenant_name
metrics:
......@@ -75,8 +116,19 @@ obInputBasic: &obInputBasic
metrics:
stat: value
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
- 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 group by tenant_name
name: ob_plan_cache
conditions: [ 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 group by tenant_name
name: ob_plan_cache
condition: [ ob_is_v4 ]
tags:
tenant_name: tenant_name
metrics:
......@@ -114,8 +166,37 @@ obInputExtra: &obInputExtra
defaultConditionValues:
ob_svr_ip: ${monagent.host.ip}
ob_svr_port: ${monagent.ob.rpc.port}
ob_is_rootservice: true
ob_is_rootservice: false
ob_is_v4: false
ob_is_v3: false
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
conditions: [ ob_is_v3 ]
params: [ ob_svr_ip, ob_svr_port ]
sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ with_rootserver from __all_server where svr_ip = ? and svr_port = ?
- name: ob_role
sqlSlowThreshold: 100ms
metrics:
is_rootserver: with_rootserver
conditionValues:
ob_is_rootservice: with_rootserver
conditions: [ ob_is_v4 ]
params: [ ob_svr_ip, ob_svr_port ]
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 = ?
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ count(*) as cnt from v$unit
name: ob_unit
metrics:
......@@ -150,12 +231,17 @@ obInputExtra: &obInputExtra
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ count(1) as cnt from __all_virtual_trans_stat where part_trans_action > 2 and ctx_create_time < date_sub(now(), interval 600 second) and svr_ip = ? and svr_port = ?
params: [ob_svr_ip, ob_svr_port]
name: ob_trans
condition: ob_is_rootservice
conditions: [ ob_is_rootservice ]
metrics:
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
conditions: [ 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
conditions: [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 = ?
......@@ -189,12 +275,13 @@ obInputExtra: &obInputExtra
min_iops: min_iops
max_disk_size_bytes: max_disk_size
max_session_num: max_session_num
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ tenant_name, tenant_id, name, gets, misses, sleeps, immediate_gets, immediate_misses, spin_gets, wait_time / 1000000 as wait_time from v$latch, __all_tenant where __all_tenant.tenant_id = v$latch.con_id
- sql: select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) */ tenant_name, tenant_id, `latch#` as latch_no, name, gets, misses, sleeps, immediate_gets, immediate_misses, spin_gets, wait_time / 1000000 as wait_time from v$latch, __all_tenant where __all_tenant.tenant_id = v$latch.con_id
name: ob_latch
tags:
tenant_name: tenant_name
tenant_id: tenant_id
name: name
latch_no: latch_no
metrics:
get_total: gets
miss_total: misses
......
......@@ -64,7 +64,7 @@ type TableCollectConfig struct {
Name string `yaml:"name"`
Sql string `yaml:"sql"`
Params []string `yaml:"params"`
Condition string `yaml:"condition"`
Conditions []string `yaml:"conditions"`
TagColumnMap map[string]string `yaml:"tags"`
MetricColumnMap map[string]string `yaml:"metrics"`
ConditionValueColumnMap map[string]string `yaml:"conditionValues"`
......@@ -143,16 +143,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")
......@@ -284,20 +274,23 @@ func (t *TableInput) collectData(config *TableCollectConfig) []metric.Metric {
func (t *TableInput) doCollect(config *TableCollectConfig, metricChan chan metric.Metric, wg *sync.WaitGroup) {
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)
if len(config.Conditions) > 0 {
for _, condition := range config.Conditions {
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='active'
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.
先完成此消息的编辑!
想要评论请 注册