nezha monitoring with DS220+
背景:最近想把部分云上服务迁移到DS220+,减少部分费用。synology 的DSM是Linux的改版,差异不大。但我的nezha使用了cfcdn,这agent需要使用代理访问cf的cdn。
-
DSM安装nezha agent
-
nezha agent配置文件读取http_proxy环境变量
DSM安装nezha agent
大部分都参考了官方文档,二进制包需要手工传入DSM到用户目录下面
Install Agent | Nezha Monitoring
User=root 必须使用root,否者无法使用ping
root@DS220: cat /usr/lib/systemd/system/nezha.service
[Unit]
Description=Nezha Agent Service
After=network.target
ConditionFileIsExecutable=/var/services/homes/xxx/soft/nezha/nezha-agent
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/var/services/homes/xxx/soft/nezha/nezha-agent "--report-delay" "3" "--skip-procs" "--skip-conn" "-s" "abcd.sss.org:443" "-p" "uUqsssssqJR" "--tls"
ExecStop=ps -fe |grep nezha-agent|awk '{print $2}'|xargs kill
User=root
Restart=always
RestartSec=120
EnvironmentFile=-/var/services/homes/xxx/sysconfig/proxy.env
[Install]
WantedBy=multi-user.target
root@DS220:/var/services/homes/xxx/soft/nezha#
nezha agent 使用http_proxy
cfcdn国内不一定可使用。我们可以修改systemd读取proxy配置文件,通过代理agent的请求。go 语言的agent会自动识别http_proxy,代码如链接agent/pkg/util/http.go/agent · GitHub
具体操作:
nezha.service
中添加[Service]
EnvironmentFile=-/var/services/homes/xxx/proxy.env
参数。
Systemd的参考文档:Packaging:Systemd - Fedora Project Wiki
/usr/lib/systemd/system/nezha.service
root@DS22: cat /usr/lib/systemd/system/nezha.service
---忽略--------------
[Service]
---忽略--------------
# - 参数是文件不存在时,不报错
EnvironmentFile=-/var/services/homes/xxx/sysconfig/proxy.env
---忽略--------------
sysconfig/proxy.env
http_proxy='http://127.0.0.1:9090'
https_proxy='http://127.0.0.1:9090'
HTTP_PROXY='http://127.0.0.1:9090'
HTTPS_PROXY='http://127.0.0.1:9090'