Skip to content

Commit

Permalink
Update agent init script
Browse files Browse the repository at this point in the history
change get agent id (property -> env)
  • Loading branch information
hyeon-inno committed Sep 9, 2024
1 parent a4bfc0a commit df71e16
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Constants {
public static final String COLLECTOR_CONFIG_PATH = CONFIG_ROOT_PATH + "/mc-observability-agent-collector.conf";
public static final String COLLECTOR_CONFIG_DIR_PATH = CONFIG_ROOT_PATH + "/conf";

public static final String PROPERTY_NS_ID = "mc-o11y.ns-id";
public static final String PROPERTY_MCI_ID = "mc-o11y.mci-id";
public static final String PROPERTY_TARGET_ID = "mc-o11y.target-id";
public static final String PROPERTY_NS_ID = "NS_ID";
public static final String PROPERTY_MCI_ID = "MCI_ID";
public static final String PROPERTY_TARGET_ID = "TARGET_ID";
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public boolean init() {

collectorExecutor.startCollector();

String nsId = System.getProperty(Constants.PROPERTY_NS_ID);
String nsId = System.getenv(Constants.PROPERTY_NS_ID);
if( nsId == null ) nsId = "";
String targetId = System.getProperty(Constants.PROPERTY_TARGET_ID);
String targetId = System.getenv(Constants.PROPERTY_TARGET_ID);
if( targetId == null ) targetId = "";
targetMapper.updateState(nsId, targetId, "ACTIVE");
}
Expand All @@ -61,9 +61,9 @@ public boolean init() {

@PreDestroy
public void destroy() {
String nsId = System.getProperty(Constants.PROPERTY_NS_ID);
String nsId = System.getenv(Constants.PROPERTY_NS_ID);
if( nsId == null ) nsId = "";
String targetId = System.getProperty(Constants.PROPERTY_TARGET_ID);
String targetId = System.getenv(Constants.PROPERTY_TARGET_ID);
if( targetId == null ) targetId = "";
targetMapper.updateState(nsId, targetId, "INACTIVE");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public String globalTelegrafConfig() {
throw new RuntimeException(e);
}

String nsId = System.getProperty(Constants.PROPERTY_NS_ID);
String nsId = System.getenv(Constants.PROPERTY_NS_ID);
if( nsId == null ) nsId = "";
String targetId = System.getProperty(Constants.PROPERTY_TARGET_ID);
String targetId = System.getenv(Constants.PROPERTY_TARGET_ID);
if( targetId == null ) targetId = "";
return sb.toString().replaceAll("@NS_ID", nsId).replaceAll("@TARGET_ID", targetId);
}
Expand All @@ -88,9 +88,9 @@ public boolean isCollectorAlive() {
}

public void updateConfigFile() {
String nsId = System.getProperty(Constants.PROPERTY_NS_ID);
String nsId = System.getenv(Constants.PROPERTY_NS_ID);
if( nsId == null ) nsId = "";
String targetId = System.getProperty(Constants.PROPERTY_TARGET_ID);
String targetId = System.getenv(Constants.PROPERTY_TARGET_ID);
if( targetId == null ) targetId = "";

List<MonitoringConfigInfo> configList = monitoringConfigService.list(nsId, targetId);
Expand Down
27 changes: 17 additions & 10 deletions java-module/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ if [ $? -ne 0 ]; then
sudo apt-get install -y docker-ce docker-ce-cli docker-compose
fi

cat <<EOF > mc-o11y-agent.conf
JAVA_OPTS="-Dspring.profiles.active=prd -Dmc-o11y.ns-id=$2 -Dmc-o11y.mci-id=$3 -Dmc-o11y.target-id=$4"
EOF
git --version
if [ $? -ne 0 ]; then
sudo apt-get install -y git
fi

git clone https://github.com/m-cmp/mc-observability.git

cd mc-observability

cat <<EOF > application-prd.yaml
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://$1:3306/mc_observability?useUnicode=true&characterEncoding=utf8&serverTimeZone=Asia/Seoul
username: mc-agent
password: mc-agent
cat <<EOF > .env
NS_ID=$2
MCI_ID=$3
TARGET_ID=$4
DATABASE_HOST=$1
DATABASE_NAME=mc-observability
DATABASE_ID=mc-agent
DATABASE_PW=mc-agent
EOF

docker compose up -d

0 comments on commit df71e16

Please sign in to comment.