From a6bfa5b0a1205e83cf0d3b8f80b7e5dbb0006c71 Mon Sep 17 00:00:00 2001 From: irwinsun Date: Tue, 8 Mar 2022 10:01:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=BC=80=E5=90=AFinfluxdb=E9=87=87?= =?UTF-8?q?=E9=9B=86=E6=9E=84=E5=BB=BA=E6=9C=BA=E8=AF=A6=E6=83=85=20#6275?= =?UTF-8?q?=20=20=E7=BD=91=E5=85=B3=E5=BC=80=E5=90=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/bkenv.properties | 6 +++--- .../com/tencent/devops/environment/client/InfluxdbClient.kt | 5 +++-- support-files/templates/gateway#core#devops.server.conf | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/bkenv.properties b/scripts/bkenv.properties index 0d262783279..ada913c576f 100644 --- a/scripts/bkenv.properties +++ b/scripts/bkenv.properties @@ -241,9 +241,9 @@ BK_CI_ES_REST_ADDR=127.0.0.1 BK_CI_ES_REST_PORT=9200 # BK_CI_ES_USER无默认值. 按需修改. ElasticSearch用户名, 如设置则启用认证. BK_CI_ES_USER= -# BK_CI_INFLUXDB_ADDR默认为127.0.0.1:8086. 按需修改. 第三方构建机状态上报时用. BK_CI_ENVIRONMENT_AGENT_COLLECTOR_ON -BK_CI_INFLUXDB_ADDR=127.0.0.1:8086 -# BK_CI_INFLUXDB_DB默认为agentMetrix. 请勿修改. 采集数据的数据库名. +# BK_CI_INFLUXDB_ADDR默认为http://127.0.0.1:8086. 按需修改. 第三方构建机状态上报还要设置 BK_CI_ENVIRONMENT_AGENT_COLLECTOR_ON +BK_CI_INFLUXDB_ADDR=http://127.0.0.1:8086 +# BK_CI_INFLUXDB_DB默认为agentMetrix. 请勿修改. 采集数据的数据库名. 请创建数据库:CREATE DATABASE agentMetrix BK_CI_INFLUXDB_DB=agentMetrix # BK_CI_INFLUXDB_HOST默认为127.0.0.1. 按需修改. 网关目前需要分别指定主机名及端口 BK_CI_INFLUXDB_HOST=127.0.0.1 diff --git a/src/backend/ci/core/environment/biz-environment/src/main/kotlin/com/tencent/devops/environment/client/InfluxdbClient.kt b/src/backend/ci/core/environment/biz-environment/src/main/kotlin/com/tencent/devops/environment/client/InfluxdbClient.kt index de8908c0326..687b4f13fac 100644 --- a/src/backend/ci/core/environment/biz-environment/src/main/kotlin/com/tencent/devops/environment/client/InfluxdbClient.kt +++ b/src/backend/ci/core/environment/biz-environment/src/main/kotlin/com/tencent/devops/environment/client/InfluxdbClient.kt @@ -55,10 +55,11 @@ class InfluxdbClient { val influxdbPassword: String = "" private val influxdb by lazy { - if (influxdbUserName.isBlank()) + if (influxdbUserName.isBlank()) { InfluxDBFactory.connect(influxdbServer) - else + } else { InfluxDBFactory.connect(influxdbServer, influxdbUserName, influxdbPassword) + } } fun getInfluxDb(): InfluxDB? { diff --git a/support-files/templates/gateway#core#devops.server.conf b/support-files/templates/gateway#core#devops.server.conf index f60807c9853..853eb209827 100644 --- a/support-files/templates/gateway#core#devops.server.conf +++ b/support-files/templates/gateway#core#devops.server.conf @@ -47,6 +47,9 @@ server { # 文档中心 include docs.conf; + # 构建机状态采集上报 influxdb + include influxdb.conf; + # 重定向 include vhosts/devops.redirect.conf; } From 616dc451729a1a3be507f251cb7b8ce6eb3d4554 Mon Sep 17 00:00:00 2001 From: fighterliu Date: Wed, 16 Mar 2022 15:35:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=BC=80=E5=90=AFinfluxdb=E9=87=87?= =?UTF-8?q?=E9=9B=86=E6=9E=84=E5=BB=BA=E6=9C=BA=E8=AF=A6=E6=83=85=20Tencen?= =?UTF-8?q?t#6275?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/bk-ci-install.sh | 16 ++++--- scripts/bk-ci-reg-influxdb.sh | 90 +++++++++++++++++++++++++++++++++++ scripts/bkce-set-env03.sh | 9 +++- 3 files changed, 108 insertions(+), 7 deletions(-) create mode 100755 scripts/bk-ci-reg-influxdb.sh diff --git a/scripts/bk-ci-install.sh b/scripts/bk-ci-install.sh index 3ade979b900..e92fe651b60 100755 --- a/scripts/bk-ci-install.sh +++ b/scripts/bk-ci-install.sh @@ -98,18 +98,22 @@ install_ci__ms_common (){ tip_dir_exist "$BK_CI_SRC_DIR/$MS_NAME" || return 16 # 检查安装java install_java || return $? + # 备份配置文件 + backup_time=$(date +'%Y%m%d%H%M') + mkdir -p /tmp/ci/$backup_time + find "$BK_CI_HOME" -name "*.env"|xargs -i -n 1 cp -rvnP --parents {} /tmp/ci/$backup_time/ > /dev/null # 增量复制. - rsync -ra "$BK_CI_SRC_DIR/$MS_NAME/" "$BK_CI_HOME/$MS_NAME" + rsync -ra --delete "$BK_CI_SRC_DIR/$MS_NAME/" "$BK_CI_HOME/$MS_NAME" for f in agent-package jars-public jars-private scripts VERSION; do [ -e "$BK_CI_SRC_DIR/$f" ] || continue echo "install $BK_CI_SRC_DIR/$f to $BK_CI_HOME." - rsync -ra "$BK_CI_SRC_DIR/${f%/}" "$BK_CI_HOME" + rsync -ra --delete "$BK_CI_SRC_DIR/${f%/}" "$BK_CI_HOME" done echo "change mode for agent-package dir." find "$BK_CI_HOME/agent-package/" -type d -exec chmod -c a+rx {} \; find "$BK_CI_HOME/agent-package/" -type f -exec chmod -c a+r {} \; # 保持微服务部分子目录的强一致性. - rsync -ra --del "$BK_CI_SRC_DIR/$MS_NAME/lib" "$BK_CI_SRC_DIR/$MS_NAME/com" "$BK_CI_HOME/$MS_NAME" + rsync -ra --delete "$BK_CI_SRC_DIR/$MS_NAME/lib" "$BK_CI_SRC_DIR/$MS_NAME/com" "$BK_CI_HOME/$MS_NAME" } install_ci_dockerhost (){ @@ -141,10 +145,10 @@ install_ci_gateway (){ local proj=$1 install_openresty || return $? rsync -ra "$BK_CI_SRC_DIR/gateway" "$BK_CI_HOME" # 不能del, 会删除codecc注入的配置文件. - rsync -ra --del "$BK_CI_SRC_DIR/frontend" "$BK_CI_HOME" # frontend不必verbose. - rsync -ra "$BK_CI_SRC_DIR/agent-package" "$BK_CI_HOME" # #3707 网关提供jars下载. + rsync -ra --delete "$BK_CI_SRC_DIR/frontend" "$BK_CI_HOME" # frontend不必verbose. + rsync -ra --delete "$BK_CI_SRC_DIR/agent-package" "$BK_CI_HOME" # #3707 网关提供jars下载. if [ -d "$BK_CI_SRC_DIR/docs" ]; then - rsync -ra --del "$BK_CI_SRC_DIR/docs" "$BK_CI_HOME" || return $? # 可选docs + rsync -ra --delete "$BK_CI_SRC_DIR/docs" "$BK_CI_HOME" || return $? # 可选docs fi } diff --git a/scripts/bk-ci-reg-influxdb.sh b/scripts/bk-ci-reg-influxdb.sh new file mode 100755 index 00000000000..6edb296545d --- /dev/null +++ b/scripts/bk-ci-reg-influxdb.sh @@ -0,0 +1,90 @@ +#!/bin/bash +SELF_DIR=$(dirname "$(readlink -f "$0")") +set -eu +trap "on_ERR;" ERR +on_ERR (){ + local fn=$0 ret=$? lineno=${BASH_LINENO:-$LINENO} + echo >&2 "ERROR $fn exit with $ret at line $lineno: $(sed -n ${lineno}p $0)." +} + +source ${CTRL_DIR:-/data/install}/load_env.sh +source ${CTRL_DIR:-/data/install}/bin/04-final/ci.env +export INFLUXDB_PORT=8086 +INFLUXDB_VERSION=1.7.10 + +if [[ ${LAN_IP} != "${BK_CI_IP0}" ]] ; then echo "仅支持在CI第一台服务运行" ; exit 1 ; fi +if grep -w "disable rsyslog rate limit" /etc/rsyslog.conf ; then sed -i -e '/disable rsyslog rate limit/s/^/#&/' /etc/rsyslog.conf ; fi +if grep -w "disable journald rate limit" /etc/rsyslog.conf ; then sed -i -e '/disable journald rate limit/s/^/#&/' /etc/rsyslog.conf ; fi + +port_test () { +ip="$1" +port=$2 +resFile=/tmp/influxdb_test_temptelnnfdswg + +#echo "telnet $ip $port..." +/usr/bin/expect >${resFile} 2>&1 <