# 采集集群信息

首先确认 `operator` 启动成功，并且有 `clloectinfo controller` 在运行。 下面是 `operator` 的信息，可以看到 `collectinfo controller` 在运行。如果 `collectinfo controller` 不存在， 表明当前使用的 `operator` 版本不支持 `collectinfo` 功能，请升级 `operator` 版本

```console
kubectl get pod -n alluxio-operator
NAME                                             READY   STATUS    RESTARTS   AGE
alluxio-cluster-controller-8656d54bc-x6ms6       1/1     Running   0          19s
alluxio-collectinfo-controller-cc49c56b6-wlw8k   1/1     Running   0          19s
alluxio-csi-controller-84df9646fd-4d5b8          2/2     Running   0          19s
alluxio-csi-nodeplugin-fcp7b                     2/2     Running   0          19s
alluxio-csi-nodeplugin-t59ch                     2/2     Running   0          19s
alluxio-csi-nodeplugin-vbq2q                     2/2     Running   0          19s
alluxio-ufs-controller-57fbdf8d5c-2f79l          1/1     Running   0          19s
```

确认 Alluxio 集群是否启动成功, 假设 Alluxio 集群在 `default` 命名空间下 下面是 Alluxio 集群的信息，可以看到 Alluxio 集群的各个组件都在运行

```console
kubectl get pod 
NAME                                  READY   STATUS    RESTARTS   AGE
alluxio-coordinator-0                 1/1     Running   0          2m17s
alluxio-etcd-0                        1/1     Running   0          2m17s
alluxio-etcd-1                        1/1     Running   0          2m17s
alluxio-etcd-2                        1/1     Running   0          2m17s
alluxio-grafana-9fd587b4f-mnczs       1/1     Running   0          2m17s
alluxio-prometheus-6b55c568b8-sfp96   1/1     Running   0          2m17s
alluxio-worker-779d87567f-95wls       1/1     Running   0          2m17s
alluxio-worker-779d87567f-sgh4b       1/1     Running   0          2m17s
```

## 采集信息

`collectinfo` 用于采集 Alluxio 集群的信息，包括配置、硬件、任务记录、日志和指标信息。提供定时采集和单次采集两种方式： 定时采集可以设置采集的时间间隔，例如每天、每周、每月等；单次采集会立刻触发一次采集任务。

下面我们以定时采集为例，提交采集任务。（完整的配置可以参考[详细配置](#详细配置)）

创建 Alluxio 集群之后会自动创建一个 `collectinfo` 资源，用于采集集群信息。默认情况下，`collectinfo` 每天会自动采集信息。 如果希望修改采集信息的内容或者时间，可以先删除之前的 `collectinfo`，然后创建新的 `collectinfo`。

```console
# 删除 collectinfo
kubectl delete collectinfo <COLLECTINFO_NAME> -n <ALLUXIO_NAMESPACE>
```

假设 Alluxio 集群位于 `default` 命名空间，创建 `collectinfo.yaml` 文件，内容如下：

```yaml
apiVersion: k8s-operator.alluxio.com/v1
kind: CollectInfo
metadata:
  name: example-collectinfo
  namespace: default
spec:
  scheduled:
    enabled: true
    cron: "0 0 * * *"
```

我们创建了一个 `collectinfo` 资源，名称为 `example-collectinfo`，和 Alluxio 集群同样位于 `default` 命名空间， 并且设置了定时采集信息，`"0 0 * * *"` 代表每天午夜运行一次。 可以参考 [Cron 时间表语法](https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/cron-jobs/#cron-schedule-syntax)。

创建 `collectinfo` ，开始采集信息。

```console
kubectl apply -f collectinfo.yaml
```

可以通过 `collectinfo` 的状态来查看采集信息的进度，`LASTSCHEDULETIME` 表示下次执行采集任务的时间， `LASTSUCCESSFULTIME` 表示最近采集成功的时间。因为设置了定时采集，所以每次采集任务结束之后，直到下次采集时间会再次执行采集任务。 通过查看 `collectinfo` 的状态，可以看到采集信息的进度。每天午夜会自动采集信息。

```console
kubectl get collectinfo
NAME                  LASTSCHEDULETIME       LASTSUCCESSFULTIME     Age         
example-collectinfo                                                 0s               
example-collectinfo                                                 0s              
example-collectinfo   2025-01-23T00:00:00Z                          0s      
example-collectinfo   2025-01-24T00:00:00Z                          2m       
example-collectinfo   2025-01-24T00:00:00Z   2025-01-23T00:00:43Z   1d     
example-collectinfo   2025-01-25T00:00:00Z   2025-01-23T00:00:43Z   1d       
example-collectinfo   2025-01-25T00:00:00Z   2025-01-24T00:00:44Z   2d    
example-collectinfo   2025-01-26T00:00:00Z   2025-01-24T00:00:44Z   2d       
example-collectinfo   2025-01-26T00:00:00Z   2025-01-25T00:00:45Z   3d     
```

`collectinfo` 在 `collectinfo controller` 完成信息采集后，会将结果同步在 `coordinator` pod 中，保存到 `metastore` 目录中， 防止 `collectinfo controller` 意外重启导致的采集结果丢失。`collectinfo` 会根据 `expiration` 字段的值删除过期的采集结果。 默认的 `expiration` 为 `720h`，即采集结果会保存 `720` 小时，超过 `720` 小时的采集结果会被删除。 可以进入 `coordinator` 的 pod 中查看采集结果。 执行下面的命令进入 `coordinator` 的 pod 中。

```console
COORDINATOR_NAME=$(kubectl get pod -l app.kubernetes.io/name=alluxio,app.kubernetes.io/component=coordinator -o jsonpath="{.items[0].metadata.name}")

➜ kubectl exec -it ${COORDINATOR_NAME} -- bash
alluxio@test-collect-alluxio-coordinator-0:/$ 

# 进入metastore目录
alluxio@test-collect-alluxio-coordinator-0:~$ cd /mnt/alluxio/metastore/collectinfo/

# 查看采集结果
alluxio@test-collect-alluxio-coordinator-0:/mnt/alluxio/metastore/collectinfo$ ls
example-collectinfo_default_2025-01-23-00-00-00.tar.gz  example-collectinfo_default_2025-01-25-00-00-00.tar.gz
example-collectinfo_default_2025-01-24-00-00-00.tar.gz
```

一天的采集结果会保存在一个 `tar.gz` 文件中，文件名表示采集任务的名称、Alluxio 集群的命名空间和采集时间。 文件大小主要取决于 metrics 信息的大小，如果按照默认的 metrics 采集配置（采集时长24小时，metrics 采集频率1分钟1次），采集结果大小约为 **5MB**。 一个月的采集结果大小约为 **150MB**。

## 下载结果

`colectinfo` 结果包含以下类型的信息：

* config: Alluxio conf/ 目录中的配置文件，例如 `alluxio-site.properties` 和 `alluxio-env.sh`。
* hardware: 每个 Kubernetes 节点的 CPU 和内存详细信息。coordinator、worker、fuse 和 operator 组件的硬件规格。
* etcd: Alluxio 集群中存储到etcd中的信息，包括 mount、quota、priority、ttl、workers 和 license 信息。
* logs: coordinator、worker、fuse 和 operator 组件的日志。支持 tail 日志以显示末尾指定行数的日志。
* metrics: 允许设置持续时间(duration)和步长(step)，以定义指标的时间范围和采样间隔（收集所有指标）。
* job history: Alluxio 集群中的 load、free 和 copy 任务历史记录, 包括任务的详细信息和状态。

通过 `kubectl cp` 的方式，将采集的信息拷贝到本地。

```console
# 设置环境变量保存 coordinator pod 的名字 
COORDINATOR_NAME=$(kubectl get pod -l app.kubernetes.io/name=alluxio,app.kubernetes.io/component=coordinator -o jsonpath="{.items[0].metadata.name}")

# 需要填入 coordinator pod 的名字
kubectl cp default/${COORDINATOR_NAME}:/mnt/alluxio/metastore/collectinfo/ collectinfo-output
```

## 详细配置

```yaml
apiVersion: k8s-operator.alluxio.com/v1
kind: CollectInfo
metadata:
  name: example-collectinfo
spec:
  # 设置定时采集信息
  scheduled:
    # 是否启用定时采集，true表示启用，则会按照cron表达式定时采集信息
    # false表示不启用定时采集，则会立即采集一次信息
    enabled: false
    # cron表达式，用于设置定时采集的时间
    # 下面的示例表示每天午夜执行一次采集任务
    # cron表达式的具体语法可以参考：https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/cron-jobs/#cron-schedule-syntax
    cron: "0 0 * * *"
    # 时区，用于设置采集任务的时区
    # 下面的示例表示采集任务的时区为上海时区
    # 时区的具体值可以参考：https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/cron-jobs/#time-zones
    timezone: "Asia/Shanghai"
    # 采集任务的过期时间，超过过期时间的采集结果会被删除
    # 下面的示例表示采集结果会保存720小时，超过720小时的采集结果会被删除
    # 过期时间的具体值可以参考：https://golang.org/pkg/time/#ParseDuration
    expiration: "720h"
  # 采集信息类型，包括config, hardware, etcd, job-history, logs, metrics
  # 如果不指定或者指定all，表示采集全部信息
  # 允许指定多个类型:
  # type:
  #   - config
  #   - hardware
  type:
    - all
  logs:
    # 采集日志的数量，比如100表示采集最新的100条日志
    tail: 100
  # 指标信息，duration表示采集的时长，step表示采集的间隔
  # 下面的参数示例表示采集从现在到过去2小时内的全部指标(metrics)，间隔每分钟采集一次指标(metrics)
  metrics:
    # 采集指标(metrics)的时长，比如2h表示采集从现在到过去24小时内的指标(metrics)
    duration: 24h
    # 采集指标(metrics)的间隔，比如1m表示每分钟采集一次指标(metrics)
    step: 1m
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.alluxio.io/ee-ai-cn/ai-3.5/start/collectinfo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
