> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lwops.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 1.4. 端口监控

基于现有模板或主机添加自动发现规则，如下用“Windows代理模板\[主动模式]“举例

### 1.4.1. 创建自动发现规则

![1.4. 端口监控 操作截图 1](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-01.png)

![1.4. 端口监控 操作截图 2](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-02.png)

自动发现规则使用”脚本“类型，脚本内容填写如下

```plain theme={null}
var str = JSON.parse(value).service_port;
var arr = str.split(",");
var json = [];
for(var i=0;i<arr.length;i++){
var temp = arr[i].split(":");
var obj = {};
obj["{#SERVICE_NAME}"] = temp[0];
obj["{#SERVICE_PORT}"] = temp[1];
json.push(obj);
}
return JSON.stringify(json);
```

JS脚本效果：将多个字符转换为json 效果如下

![1.4. 端口监控 操作截图 3](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-03.png)

### 1.4.2. 添加监控项原型

选择如下键值进行端口探测

![1.4. 端口监控 操作截图 4](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-04.png)

名称：服务 \{#SERVICE\_NAME} 端口检测 键值：net.tcp.port\[,\{#SERVICE\_PORT}]

![1.4. 端口监控 操作截图 5](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-05.png)

### 1.4.3. 定义模板宏

![1.4. 端口监控 操作截图 6](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-06.png)

### 1.4.4. 任意windows操作系统查看监控效果

修改或使用默认模板宏

![1.4. 端口监控 操作截图 7](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-07.png)

agent:10050,mstsc:3389,tomcat:7001

![1.4. 端口监控 操作截图 8](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-08.png)

### 1.4.5. 验证监控项

![1.4. 端口监控 操作截图 9](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/port/image-09.png)
