方便运维查看nacos注册服务,快速查找服务,同时生成prometheus自动发现所需要的json文件。
golang 运维萌新,学习项目... 😊
- 快速查找注册服务,支持匹配名称,命名空间,端口,ip
- 支持命令行导出json
- 支持自定义Prometheus label
- 支持Prometheus自动发现,
file_sd
和http_sd_configs
- 查看集群状态,以及v1升级v2接口详情
- 支持注册本身到Nacos集群
curl -L https://github.com/typ431127/Nacos_check/releases/download/0.6-fix/nacos-check_Linux_x86_64.tar.gz -o nacos-check_Linux_x86_64.tar.gz
tar xvf nacos-check_Linux_x86_64.tar.gz
chmod +x nacos-check
./nacos-check --url https://nacos地址
Nacos
Usage:
nacos-check [flags]
nacos-check [command]
Available Commands:
cluster 集群状态
completion Generate the autocompletion script for the specified shell
config 查看本地配置文件路径
help Help about any command
register 注册本实例到Nacos并开启webapi
version 查看版本
web 开启web api Prometheus http_sd_configs
Flags:
-f, --find string 查找服务
-h, --help help for nacos-check
-i, --ipfile string ip解析文件 (default "salt_ip.json")
--json 输出json
-l, --lable stringToString 添加标签 -l env=dev,pro=java (default [])
-s, --second duration 监控服务间隔刷新时间 (default 5s)
-u, --url string Nacos地址 (default "http://dev-k8s-nacos:8848")
-w, --watch 监控服务
-o, --write string 导出json文件, prometheus 自动发现文件路径
Use "nacos-check [command] --help" for more information about a command.
./nacos_check-linux-amd64 --url http://nacos-0:8848
./nacos_check-linux-amd64 --url http://nacos-0:8848 cluster --v2upgrade
./nacos_check-linux-amd64 --url http://nacos-0:8848 -f gateway
./nacos_check-linux-amd64 --url http://nacos-0:8848 -f 8080
./nacos_check-linux-amd64 --url http://nacos-0:8848 -f 172.30
- 支持查找服务名,ip,端口,命名空间
./nacos_check-linux-amd64 --url http://nacos-0:8848 -f gateway -w -s 10s
./nacos_check-linux-amd64 --url http://nacos-0:8848 -o discovery.json
./nacos_check-linux-amd64 --url http://nacos-0:8848 --json
# 添加自定义label
./nacos_check-linux-amd64 --url http://nacos-0:8848 -l env=dev,pro=test-pro,k8s=true --json
file_sd_configs:
- files:
- '/data/work/prometheus/discovery/*.json'
refresh_interval: 3m
prometheus-file-sd 自动发现
./nacos_check-linux-amd64 --url http://nacos-0.xxxxx:8848 -o discovery.json
http_sd_configs 自动发现
开启webapi
./nacos_check-linux-amd64 web --url http://nacos-0.xxxx:8848
开启webapi并添加自定义label
./nacos_check-linux-amd64 web --url http://nacos-0.xxxx:8848 -l env=dev,pro=test-pro,k8s=true
基于http_sd_configs的自动发现
scrape_configs:
- job_name: 'nacos'
scrape_interval: 10s
metrics_path: /probe
params:
module: [tcp_connect]
http_sd_configs:
- url: http://localhost:8099
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9115
- 匹配命名空间
- 匹配服务名
- 匹配IP端口
# 模糊匹配命名空间
./nacos_check-linux-amd64 -f registry
# 模糊匹配服务
./nacos_check-linux-amd64 -f gateway
# 匹配端口
./nacos_check-linux-amd64 -f 8080
# 模糊匹配IP
./nacos_check-linux-amd64 -f 172.30
每次运行工具都需要指定url很麻烦,可以在本地写一个配置文件,这样默认情况下就会加载配置文件里面的url,就不需要每次都指定了。 查看配置文件路径
./nacos_check-linux-amd64 config
本地配置文件路径: /root/.nacos_conf.toml
/root/.nacos_conf.toml
示例
# nacos url地址
url = "http://nacos-0:8848"
# 定义容器网段
container_network = ["172.30.0.0/16","172.16.0.0/16","192.168.0.0/16"]
# 设置默认导出json和web服务附加标签
label = [
{name = "env",value = "dev"},
{name = "os",value = "linux"}
]
ipfile = "/mnt/cxxxx/ip.json"
默认优先加载本地配置文件
docker run -itd -e nacos_url=http://nacos-xx.com:8848 -p 8099:8099 typ431127/nacos-check:0.6
访问 http://localhost:8099
./nacos_check-linux-amd64 register -i 192.168.1.4 -p ":8048" -n ddn-test1 --url http://192.16
8.100.132:8848
./nacos_check-linux-amd64 register -i 192.168.1.4 -p ":8048" -n ddn-test1 --url \
http://192.168.100.132:8848,http://192.168.100.133:8848,http://192.168.100.134:8848
执行后工具会开启一个web服务并注册到Nacos上面,同时可指定多个Nacos地址,此功能方便运维排查Nacos注册问题。
- -i 指定注册到Nacos的IP地址
- -p 指定开启端口
- --url 指定Nacos服务地址,多个地址,号分开
- -n 指定注册到Nacos的服务名称
注意: 仅注册功能支持多个nacos地址写法
因为默认只获取到主机ip,获取不到主机名,可以指定ipfile解析主机名,有条件可以二次开发对接自己cmdb, 文件格式如下 (可选)
{
"test1": "10.x.x.x",
"test2": "10.x.x.x",
}
./nacos_check-linux-amd64 -i ../ip.json
grafana控制台导入grafana.json
此模板默认匹配blackbox_exporter