> For the complete documentation index, see [llms.txt](https://jam2in.gitbook.io/arcus-hubble/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jam2in.gitbook.io/arcus-hubble/ch04-update-collection-target.md).

# Chapter 4. Add/Remove Collection target

## 수집 대상 클러스터 추가

아래와 같은 주소에 ZooKeeper ensemble이 신규로 구동되었다고 가정합니다.

```
new.arcuscloud.jam2in.com:2181
10.0.0.1:2181 10.0.0.2:2181 10.0.0.3:2181
```

새로 구동된 클러스터를 Arcus Hubble V3의 수집 대상으로 추가하려면, Arcus Exporter, ZooKeeper Exporter를 새로 구동하고 필요 시 각 장비에 Node Exporter를 구동해야 합니다. 그리고 VictoriaMetrics(Short Term), Orbiter를 재구동해주어야 합니다.

### Arcus Exporter 구동 (Memcached 서버 메트릭 수집)

#### 설정 파일(`/INSTALL_DIR/arcus_exporter/conf/new.json`) 작성

* `listen`: 기존에 사용 중인 port와 중복되지 않도록 설정합니다.
* `ensemble`: ZK 도메인 또는 서버 목록을 입력합니다.
* `log.filename`: 설정파일과 동일한 이름으로 설정하는 것을 권장합니다.
* 기타 설정은 [arcus\_exporter config](https://github.com/jam2in/arcus-hubble-v3/blob/develop/docs/hubble-v3-guide.md#arcus-exporter) 참고 바랍니다.

```json
{
  "listen": "127.0.0.1:13119",
  "ensembleByName": { "new": [ "new.arcuscloud.jam2in.com:2181" ] },
  // "ensembleByName": { "new": [ "10.0.0.1:2181", "10.0.0.2:2181", "10.0.0.3:2181" ] },
  "log": {
    "filename": "/INSTALL_DIR/arcus_exporter/log/new.log"
  }
}
```

#### 구동

```sh
/INSTALL_DIR/arcus_exporter/start.sh new
```

### ZooKeeper Exporter 구동 (ZooKeeper 서버 메트릭 수집)

> 만약 ZooKeeper Exporter를 구동 중인 상태에서 ZK DNS 변경이 발생했다면 자동 반영되지 않으므로 재구동이 필요합니다.

#### 설정 파일(`/INSTALL_DIR/zookeeper_exporter/conf/new.env`) 작성

* `LISTEN_PORT`: 기존에 사용 중인 port와 중복되지 않도록 설정합니다.
* `ZK_DOMAIN` or `ZK_SERVERS`: domain 주소를 입력하거나, 각 서버 주소를 입력합니다.

```sh
LISTEN_PORT=9149
ZK_DOMAIN="new.arcuscloud.jam2in.com:2181"
#ZK_SERVERS=("10.0.0.1:2181" "10.0.0.2:2181" "10.0.0.3:2181")
```

#### 구동

```sh
/INSTALL_DIR/zookeeper-exporter/start.sh new
```

### Node Exporter 구동 (호스트 장비 메트릭 수집)

#### 수집 대상 장비에 Node Exporter 구동

[일괄 설치 및 실행 방법](https://jam2in.gitbook.io/arcus-hubble/pages/uHoIdGZTG2uHsjaK4JiX#일괄-설치-및-실행-방법) 문서를 참고하여 각 캐시 장비마다 node\_exporter 설치 후 구동합니다.

#### systemd service로 Node Exporter 구동

1. `node_exporter.service` 파일과 `node_exporter.socket` 파일을 `/etc/systemd/system` 하위에 복사합니다.
2. User와 INSTALL\_DIR 값을 적절히 변경합니다.
3. `systemctl` 명령을 통해 `node_exporter.socket`을 실행합니다.

```
sudo systemctl daemon-reload
sudo systemctl enable node_exporter.socket
sudo systemctl start node_exporter.socket
```

### VictoriaMetrics(Short Term) 설정 변경 및 reload

#### 설정 변경

* Arcus Exporter 설정 파일(`/INSTALL_DIR/victoriametrics/conf/exporter/arcus_exporter.yml`)에 새로 구동한 arcus\_exporter 주소를 추가합니다.

```yml
- targets:
  - localhost:13111
  - localhost:13112
  ...
  - localhost:13119 # add
```

* ZooKeeper Exporter 설정 파일(`/INSTALL_DIR/victoriametrics/conf/exporter/zookeeper_exporter.yml`)에 새로 구동한 ZooKeeper Exporter 주소를 추가합니다.

```yml
- targets:
  - localhost:9141
  labels:
    ensemble: example-1
- targets:
  - localhost:9142
  labels:
    ensemble: example-2
  ...
- targets:  # add
  - localhost:9149
  labels:
    ensemble: new
```

* Node Exporter 설정 파일(`/INSTALL_DIR/victoriametrics/conf/exporter/node_exporter.yml`)에 새로 구동한 Node Exporter 주소를 추가합니다.

```yml
- targets:
  - localhost:9100
  ...
  - 10.0.0.1:9100 # add
  - 10.0.0.2:9100 # add
  - 10.0.0.3:9100 # add
  labels:
    group: host
```

#### 설정 파일 reload

* 아래와 같이 VictoriaMetrics(Short Term)이 구동된 주소로 HTTP 요청을 보내 프로세스를 리로드합니다.

```sh
curl -X POST http://localhost:8428/-/reload
```

### Orbiter 설정 변경 및 reload

#### 설정 변경

* Orbiter 설정 파일(`/INSTALL_DIR/orbiter/config.json`)에 새로 구동한 ZooKeeper ensemble의 이름과 주소를 추가합니다.

```json
{
    "listen": "0.0.0.0:8084",
    "ensembleByName": {
        "example-1": [ "example-1.arcuscloud.jam2in.com:2181" ],
        "example-2": [ "example-2.arcuscloud.jam2in.com:2181" ],
        ...
        "new": [ "new.arcuscloud.jam2in.com:2181" ]  // add
        // "new": [ "10.0.0.1:2181", "10.0.0.2:2181", "10.0.0.3:2181" ]
    },
    ...
}
```

#### 설정 파일 reload

* 아래와 같이 HTTP 요청을 보내 Orbiter 프로세스를 리로드합니다.

```sh
curl -X POST http://localhost:8084/reload/config
```

## 수집 대상 클러스터 제거

아래와 같은 주소에 구동되어 있던 ZooKeeper ensemble을 제거하기 위해 수집 대상에서 먼저 제거한다고 가정합니다.

```
new.arcuscloud.jam2in.com:2181
10.0.0.1:2181 10.0.0.2:2181 10.0.0.3:2181
```

클러스터를 Arcus Hubble V3의 수집 대상에서 제거하려면, VictoriaMetrics(Short Term), Orbiter를 재구동하고 Arcus Exporter, Node Exporter, ZooKeeper Exporter를 종료해야 합니다.

### Orbiter 설정 변경 및 reload

#### 설정 변경

* Orbiter 설정 파일(`/INSTALL_DIR/orbiter/config.json`)에서 수집이 필요 없어진 ZooKeeper ensemble의 이름과 주소를 제거합니다.

```json
{
    "listen": "0.0.0.0:8084",
    "ensembleByName": {
        "example-1": [ "example-1.arcus.com:2181" ],
        "example-2": [ "example-2.arcus.com:2181" ],
        ...
        // "new": [ "new.arcuscloud.jam2in.com:2181" ] remove
    },
    ...
}
```

#### 설정 파일 reload

* 아래와 같이 HTTP 요청을 보내 Orbiter 프로세스를 리로드합니다.

```sh
curl -X POST http://localhost:8084/reload/config
```

### VictoriaMetrics(Short Term) 설정 변경 및 reload

#### 설정 변경

* Arcus Exporter 설정 파일(`/INSTALL_DIR/victoriametrics/conf/exporter/arcus_exporter.yml`)에서 제거 대상인 ZooKeeper ensemble 캐시 서버들의 지표를 수집 중인 Arcus Exporter 주소를 제거합니다.

```yml
- targets:
  - localhost:13111
  - localhost:13112
  ...
  # localhost:13119 remove
```

* ZooKeeper Exporter 설정 파일(`/INSTALL_DIR/victoriametrics/conf/exporter/zookeeper_exporter.yml`)에서 제거 대상인 ZooKeeper ensemble의 지표를 수집 중인 ZooKeeper Exporter 주소를 제거합니다.

```yml
- targets:
  - localhost:9141
  labels:
    ensemble: example-1
- targets:
  - localhost:9142
  labels:
    ensemble: example-2
  ...
# - targets:  remove
#  - localhost:9149
#  labels:
#    ensemble: new
```

* node\_exporter (`/INSTALL_DIR/victoriametrics/conf/exporter/node_exporter.yml`)에서 제거 대상인 ZooKeeper ensemble 장비의 지표를 수집 중인 Node Exporter 주소를 제거합니다.

```yml
- targets:
  - localhost:9100
  ...
  - # 10.0.0.1:9100 remove
  - # 10.0.0.2:9100 remove
  - # 10.0.0.3:9100 remove
  labels:
    group: host
```

#### 설정 파일 reload

* 아래와 같이 VictoriaMetrics(Short Term)이 구동된 주소로 HTTP 요청을 보내 프로세스를 리로드합니다.

```sh
curl -X POST http://localhost:8428/-/reload
```

### Arcus Exporter, ZooKeeper Exporter 프로세스 종료

* `ps -ef`와 `grep` 명령어를 사용해 제거될 ZooKeeper ensemble의 주소를 담은 exporter 프로세스들의 PID를 찾고 종료시킵니다.

1. `ps -ef | grep hubble | grep new`
2. `kill <pid>`

### 캐시 장비 Node Exporter 프로세스 종료

각 ZooKeeper, Arcus 캐시 서버가 구동되었던 장비에 있던 Node Exporter 프로세스의 PID를 찾고 종료시킵니다.

1. `ssh <cache host> "ps -ef | grep node_exporter"`
2. `ssh <cache host> "kill <pid>"`

#### systemd service로 등록된 Node Exporter 종료

```
sudo systemctl stop node_exporter.socket
sudo systemctl disable node_exporter.socket
sudo rm /etc/systemd/system/node_exporter.*
sudo systemctl daemon-reload
```

## Service code 단위 수집 대상 추가/제거

1. Arcus Exporter는 기본적으로 하나의 ZooKeeper ensemble에 등록된 모든 클러스터 정보를 수집합니다.
2. 일부 클러스터에 대한 메트릭만 수집하려면 [`serviceCodes`](https://github.com/jam2in/arcus-hubble-v3/blob/develop/docs/hubble-v3-guide.md#arcus-exporter) 설정에 수집하려는 클러스터의 service code 목록을 지정합니다.
3. 그 외 구성 요소의 설정은 상단의 수집 대상 추가/제거 항목을 참고하여 진행합니다.
   * ZooKeeper Exporter
   * Node Exporter
   * Orbiter
   * VictoriaMetrics(Short Term)
