diff options
| -rw-r--r-- | nz-admin/src/main/resources/db/R__AZ_sys_config.sql | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/nz-admin/src/main/resources/db/R__AZ_sys_config.sql b/nz-admin/src/main/resources/db/R__AZ_sys_config.sql index 660c8e1e..03d66f9f 100644 --- a/nz-admin/src/main/resources/db/R__AZ_sys_config.sql +++ b/nz-admin/src/main/resources/db/R__AZ_sys_config.sql @@ -26,7 +26,7 @@ * 修改密码策略,增加修改密码定时提醒 */ -REPLACE INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (NULL, 'prom_yml_tmpl', '{\r\n \"global\": {\r\n \"scrape_interval\": \"${scrape_interval}s\",\r\n \"scrape_timeout\": <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n \"evaluation_interval\": \"${scrape_interval}s\"\r\n },\r\n \r\n <#-- alert 配置 -->\r\n <#if isAlert>\r\n \"alerting\": {\r\n \"alertmanagers\": [{\r\n \"path_prefix\": \"${path_prefix}\",\r\n \"static_configs\": [{\r\n \"targets\": [\"${alert_url}\"]\r\n }]\r\n }],\r\n \"alert_relabel_configs\": [{\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }, {\r\n \"regex\": \"replica\",\r\n \"action\": \"labeldrop\"\r\n }]\r\n },\r\n \"rule_files\": [\"rule.yml\"],\r\n </#if>\r\n \r\n \r\n \r\n <#-- per-datacenter 配置 -->\r\n <#if !isGlobal>\r\n \"scrape_configs\": [\r\n <#list jobList as jobPojo>\r\n {\r\n \"job_name\": \"${jobPojo.job_name}\",\r\n \"scheme\": \"${jobPojo.scheme?default(\"http\")}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": <#if jobPojo.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${jobPojo.metrics_path}\",\r\n <#else>\r\n \"/metrics\",\r\n </#if>\r\n \"static_configs\":[\r\n <#list jobPojo.staticConfigList as staticConf >\r\n {\r\n \"targets\": [\r\n <#list staticConf.targets as targetConf>\r\n \"${targetConf}\"<#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#if staticConf.labels ??&& (staticConf.labels?size >0)>\r\n ,\r\n \"labels\": {\r\n <#list staticConf.labels?keys as itemKey>\r\n \"${itemKey}\":<#if staticConf.labels[itemKey]?default(\"\")?trim?length gt 0>\r\n \"${staticConf.labels[itemKey]}\"\r\n <#else>\"\"</#if><#sep>,</#sep>\r\n </#list>\r\n } \r\n </#if>\r\n }<#sep>,</#sep>\r\n </#list>\r\n ],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ]\r\n }<#sep>,</#sep>\r\n </#list>\r\n <#if jobList??&&(jobList?size>0)>\r\n ,\r\n </#if>\r\n <#list endpointList as endpoint>\r\n {\r\n \"job_name\": ${endpoint.id?c},\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": <#if endpoint.config.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.metrics_path}\",\r\n <#else>\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"/metrics\",\r\n <#else>\r\n \"/snmp\",\r\n </#if>\r\n </#if>\r\n \"scrape_interval\": <#if endpoint.config.scrape_interval?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_interval}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if endpoint.config.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_timeout}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n\r\n\r\n\r\n <#if endpoint.config.basic_auth??&& (endpoint.config.basic_auth?size >0)>\r\n <#if endpoint.config.basic_auth.username?default(\"\")?trim?length gt 0 && endpoint.config.basic_auth.password?default(\"\")?trim?length gt 0>\r\n \"basic_auth\":{\r\n \"username\": \"${endpoint.config.basic_auth.username}\",\r\n \"password\": \"${endpoint.config.basic_auth.password}\"\r\n },\r\n </#if>\r\n </#if>\r\n \r\n <#if endpoint.config.bearer_token??&&endpoint.config.bearer_token?trim?length gt 0>\r\n \"authorization\":{\r\n \"type\":\"Bearer\",\r\n \"credentials\":\"${endpoint.config.bearer_token}\"\r\n },\r\n </#if>\r\n\r\n \r\n <#-- params 不为空且类型为 http ,添加 params -->\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\" >\r\n \"scheme\": \"${endpoint.config.protocol}\",\r\n <#if endpoint.config.params?? && (endpoint.config.params?size >0) >\r\n \"params\":{\r\n <#list endpoint.config.params?keys as itemKey>\r\n \"${itemKey}\":[\r\n <#list endpoint.config.params[itemKey] as pojo>\r\n \"${pojo}\"\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#sep>,</#sep>\r\n </#list>\r\n },\r\n </#if>\r\n <#elseif endpoint.config.protocol == \"snmp\">\r\n <#-- 类型是 snmp ,组织 param 数据 , 原来params弃用,因为 snmp_exporter 不支持其他参数 -->\r\n \"params\":{\r\n \"target\":[ \"${endpoint.config.host}:${endpoint.config.port?c}\" ],\r\n \"module\":[ \"${endpoint.module.name}\" ]\r\n },\r\n </#if>\r\n \r\n \"static_configs\": [{\r\n \"targets\": [<#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"${endpoint.config.host}:${endpoint.config.port?c}\"\r\n <#else>\r\n \"127.0.0.1:19116\"\r\n </#if>\r\n ],\r\n \"labels\": {\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \"datacenter_id\":${endpoint.dc.id?c},\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \"project_id\": ${endpoint.project.id?c},\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \"asset_id\": ${endpoint.asset.id?c},\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \"module_id\": ${endpoint.module.id?c},\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \"endpoint_id\": ${endpoint.id?c},\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\",\r\n \"parent_asset_id\" : ${endpoint.asset.parent.id?c},\r\n </#if>\r\n\r\n \"nz_agent_id\": ${endpoint.agent.id?c}\r\n \r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"datacenter_id\" && key != \"project\" && key != \"project_id\" && key != \"asset\" && key != \"asset_id\" && key != \"module\" && key != \"module_id\" && key != \"endpoint\" && key != \"endpoint_id\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n }\r\n }],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if endpoint.config.relabel_config??&& (endpoint.config.relabel_config?size >0)>\r\n <#list endpoint.config.relabel_config as relabel>\r\n ,{\r\n <#if relabel.action?? && (relabel.action == \'labeldrop\' || relabel.action == \'labelkeep\')>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'labelmap\'>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && (relabel.action == \'drop\' || relabel.action == \'keep\')>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'replace\'>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"separator\": \"${((relabel.separator!\'\')?length>0)?string((relabel.separator!\'\'),\";\")}\", \r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"target_label\": \"${(relabel.target_label)!\'\'}\"\r\n </#if>\r\n }\r\n </#list>\r\n </#if>\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n \r\n <#-- ping 配置 -->\r\n \r\n <#if endpointList??&&(endpointList?size>0)>\r\n ,\r\n </#if>\r\n \r\n <#list assetList as asset>\r\n {\r\n \"job_name\": \"asset_ping_${asset.id?c}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": \"/probe\",\r\n \"scrape_interval\": <#if asset.assetPingInterval?default(\"\")?trim?length gt 0>\r\n \"${asset.assetPingInterval}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if asset.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${asset.scrape_timeout}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n \"params\": {\r\n \"target\":[ \"${asset.manageIp}\" ],\r\n \"module\":[ \"ping\" ]\r\n },\r\n \"static_configs\": [{\r\n \"targets\": [\"127.0.0.1:19115\"],\r\n \"labels\": {\r\n \"datacenter\": \"${asset.dc.name}\",\r\n \"host\": \"${asset.manageIp}\",\r\n \"module\": \"ping\",\r\n \"source_ip\": \"${asset.agent.host}\",\r\n \"nz_agent_id\": ${asset.agent.id?c}\r\n }\r\n }],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#-- cortex 处理 -->\r\n ,\r\n \"remote_write\": [\r\n <#list remoteWriteUrlInfos as remoteConf>\r\n {\r\n \"url\": \"${remoteConf.url}\",\r\n \"authorization\": {\r\n \"type\": \"Bearer\",\r\n \"credentials\": \"${remoteConf.token}\"\r\n },\r\n \"tls_config\":{\r\n \"insecure_skip_verify\":true\r\n },\r\n \"queue_config\":{\r\n \"capacity\": 5000,\r\n \"max_samples_per_send\": 1000,\r\n \"min_shards\": 5,\r\n \"max_shards\": 10,\r\n \"min_backoff\": \"20ms\",\r\n \"min_backoff\": \"50ms\"\r\n }\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#else>\r\n <#-- global 配置 -->\r\n \"scrape_configs\": [\r\n <#list jobList as jobPojo>\r\n {\r\n \"job_name\": \"${jobPojo.job_name}\",\r\n \"scheme\": \"${jobPojo.scheme?default(\"http\")}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n <#if jobPojo.isFederate> \r\n \"honor_labels\": ${jobPojo.honor_labels},\r\n \"params\": {\r\n \"match[]\": [\r\n \"{__name__=~\\\".+\\\",nz_agent_id != \\\"${jobPojo.excludeAgentId}\\\"}\"\r\n ]\r\n },\r\n \"authorization\":{\r\n \"type\":\"Bearer\",\r\n \"credentials\":\"${jobPojo.token}\"\r\n },\r\n </#if>\r\n \"metrics_path\": <#if jobPojo.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${jobPojo.metrics_path}\",\r\n <#else>\r\n \"/metrics\",\r\n </#if>\r\n \"static_configs\":[\r\n <#list jobPojo.staticConfigList as staticConf >\r\n {\r\n \"targets\": [\r\n <#list staticConf.targets as targetConf>\r\n \"${targetConf}\"<#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#if staticConf.labels ??&& (staticConf.labels?size >0)>\r\n ,\r\n \"labels\": {\r\n <#list staticConf.labels?keys as itemKey>\r\n \"${itemKey}\":<#if staticConf.labels[itemKey]?default(\"\")?trim?length gt 0>\r\n \"${staticConf.labels[itemKey]}\"\r\n <#else>\"\"</#if><#sep>,</#sep>\r\n </#list>\r\n } \r\n </#if>\r\n }<#sep>,</#sep>\r\n </#list>\r\n ],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ]\r\n }<#sep>,</#sep>\r\n </#list>\r\n \r\n <#-- ping 配置 -->\r\n \r\n <#if jobList??&&(jobList?size>0)>\r\n ,\r\n </#if>\r\n \r\n <#list assetList as asset>\r\n {\r\n \"job_name\": \"asset_ping_${asset.id?c}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": \"/probe\",\r\n \"scrape_interval\": <#if asset.assetPingInterval?default(\"\")?trim?length gt 0>\r\n \"${asset.assetPingInterval}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if asset.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${asset.scrape_timeout}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n \"params\": {\r\n \"target\":[ \"${asset.manageIp}\" ],\r\n \"module\":[ \"ping\" ]\r\n },\r\n \"static_configs\": [{\r\n \"targets\": [\"127.0.0.1:19115\"],\r\n \"labels\": {\r\n \"datacenter\": \"${asset.dc.name}\",\r\n \"host\": \"${asset.manageIp}\",\r\n \"module\": \"ping\",\r\n \"source_ip\": \"${asset.agent.host}\",\r\n \"nz_agent_id\": ${asset.agent.id?c}\r\n }\r\n }],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n \r\n \r\n <#if ( jobList??&&(jobList?size>0)) || assetList??&&(assetList?size>0)>\r\n ,\r\n </#if>\r\n \r\n <#list endpointList as endpoint>\r\n {\r\n \"job_name\": ${endpoint.id?c},\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": <#if endpoint.config.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.metrics_path}\",\r\n <#else>\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"/metrics\",\r\n <#else>\r\n \"/snmp\",\r\n </#if>\r\n </#if>\r\n \"scrape_interval\": <#if endpoint.config.scrape_interval?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_interval}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if endpoint.config.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_timeout}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n\r\n\r\n\r\n <#if endpoint.config.basic_auth??&& (endpoint.config.basic_auth?size >0)>\r\n <#if endpoint.config.basic_auth.username?default(\"\")?trim?length gt 0 && endpoint.config.basic_auth.password?default(\"\")?trim?length gt 0>\r\n \"basic_auth\":{\r\n \"username\": \"${endpoint.config.basic_auth.username}\",\r\n \"password\": \"${endpoint.config.basic_auth.password}\"\r\n },\r\n </#if>\r\n </#if>\r\n \r\n \r\n <#if endpoint.config.bearer_token??&&endpoint.config.bearer_token?trim?length gt 0>\r\n \"authorization\":{\r\n \"type\":\"Bearer\",\r\n \"credentials\":\"${endpoint.config.bearer_token}\"\r\n },\r\n </#if>\r\n\r\n \r\n <#-- params 不为空且类型为 http ,添加 params -->\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\" >\r\n \"scheme\": \"${endpoint.config.protocol}\",\r\n <#if endpoint.config.params?? && (endpoint.config.params?size >0) >\r\n \"params\":{\r\n <#list endpoint.config.params?keys as itemKey>\r\n \"${itemKey}\":[\r\n <#list endpoint.config.params[itemKey] as pojo>\r\n \"${pojo}\"\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#sep>,</#sep>\r\n </#list>\r\n },\r\n </#if>\r\n <#elseif endpoint.config.protocol == \"snmp\">\r\n <#-- 类型是 snmp ,组织 param 数据 , 原来params弃用,因为 snmp_exporter 不支持其他参数 -->\r\n \"params\":{\r\n \"target\":[ \"${endpoint.config.host}:${endpoint.config.port?c}\" ],\r\n \"module\":[ \"${endpoint.module.name}\" ]\r\n },\r\n </#if>\r\n \r\n \"static_configs\": [{\r\n \"targets\": [<#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"${endpoint.config.host}:${endpoint.config.port?c}\"\r\n <#else>\r\n \"127.0.0.1:19116\"\r\n </#if>\r\n ],\r\n \"labels\": {\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \"datacenter_id\":${endpoint.dc.id?c},\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \"project_id\": ${endpoint.project.id?c},\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \"asset_id\": ${endpoint.asset.id?c},\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \"module_id\": ${endpoint.module.id?c},\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \"endpoint_id\": ${endpoint.id?c},\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\",\r\n \"parent_asset_id\" : ${endpoint.asset.parent.id?c},\r\n </#if>\r\n \r\n \"nz_agent_id\": ${endpoint.agent.id?c}\r\n \r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"datacenter_id\" && key != \"project\" && key != \"project_id\" && key != \"asset\" && key != \"asset_id\" && key != \"module\" && key != \"module_id\" && key != \"endpoint\" && key != \"endpoint_id\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n }\r\n }],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if endpoint.config.relabel_config??&& (endpoint.config.relabel_config?size >0)>\r\n <#list endpoint.config.relabel_config as relabel>\r\n ,{\r\n <#if relabel.action?? && (relabel.action == \'labeldrop\' || relabel.action == \'labelkeep\')>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'labelmap\'>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && (relabel.action == \'drop\' || relabel.action == \'keep\')>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'replace\'>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"separator\": \"${((relabel.separator!\'\')?length>0)?string((relabel.separator!\'\'),\";\")}\", \r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"target_label\": \"${(relabel.target_label)!\'\'}\"\r\n </#if>\r\n }\r\n </#list>\r\n </#if>\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n \r\n ]\r\n \r\n <#-- cortex 处理 -->\r\n ,\r\n \"remote_write\": [\r\n <#list remoteWriteUrlInfos as remoteConf>\r\n { \r\n \"url\": \"${remoteConf.url}\",\r\n \"authorization\": {\r\n \"type\": \"Bearer\",\r\n \"credentials\": \"${remoteConf.token}\"\r\n },\r\n \"tls_config\":{\r\n \"insecure_skip_verify\":true\r\n },\r\n \"queue_config\":{\r\n \"capacity\": 5000,\r\n \"max_samples_per_send\": 1000,\r\n \"min_shards\": 5,\r\n \"max_shards\": 10,\r\n \"min_backoff\": \"20ms\",\r\n \"min_backoff\": \"50ms\"\r\n }\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ] \r\n </#if>\r\n}', 1, 'prometheus config文件模板'); +REPLACE INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (NULL, 'prom_yml_tmpl', '{\r\n \"global\": {\r\n \"scrape_interval\": \"${scrape_interval}s\",\r\n \"scrape_timeout\": <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n \"evaluation_interval\": \"${scrape_interval}s\"\r\n },\r\n \r\n <#-- alert 配置 -->\r\n <#if isAlert>\r\n \"alerting\": {\r\n \"alertmanagers\": [{\r\n \"path_prefix\": \"${path_prefix}\",\r\n \"static_configs\": [{\r\n \"targets\": [\"${alert_url}\"]\r\n }]\r\n }],\r\n \"alert_relabel_configs\": [{\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }, {\r\n \"regex\": \"replica\",\r\n \"action\": \"labeldrop\"\r\n }]\r\n },\r\n \"rule_files\": [\"rule.yml\"],\r\n </#if>\r\n \r\n \r\n \r\n <#-- per-datacenter 配置 -->\r\n <#if !isGlobal>\r\n \"scrape_configs\": [\r\n <#list jobList as jobPojo>\r\n {\r\n \"job_name\": \"${jobPojo.job_name}\",\r\n \"scheme\": \"${jobPojo.scheme?default(\"http\")}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": <#if jobPojo.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${jobPojo.metrics_path}\",\r\n <#else>\r\n \"/metrics\",\r\n </#if>\r\n \"static_configs\":[\r\n <#list jobPojo.staticConfigList as staticConf >\r\n {\r\n \"targets\": [\r\n <#list staticConf.targets as targetConf>\r\n \"${targetConf}\"<#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#if staticConf.labels ??&& (staticConf.labels?size >0)>\r\n ,\r\n \"labels\": {\r\n <#list staticConf.labels?keys as itemKey>\r\n \"${itemKey}\":<#if staticConf.labels[itemKey]?default(\"\")?trim?length gt 0>\r\n \"${staticConf.labels[itemKey]}\"\r\n <#else>\"\"</#if><#sep>,</#sep>\r\n </#list>\r\n } \r\n </#if>\r\n }<#sep>,</#sep>\r\n </#list>\r\n ],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ]\r\n }<#sep>,</#sep>\r\n </#list>\r\n <#if jobList??&&(jobList?size>0)>\r\n ,\r\n </#if>\r\n <#list endpointList as endpoint>\r\n {\r\n \"job_name\": ${endpoint.id?c},\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": <#if endpoint.config.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.metrics_path}\",\r\n <#else>\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"/metrics\",\r\n <#else>\r\n \"/snmp\",\r\n </#if>\r\n </#if>\r\n \"scrape_interval\": <#if endpoint.config.scrape_interval?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_interval?c}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if endpoint.config.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_timeout?c}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n\r\n\r\n\r\n <#if endpoint.config.basic_auth??&& (endpoint.config.basic_auth?size >0)>\r\n <#if endpoint.config.basic_auth.username?default(\"\")?trim?length gt 0 && endpoint.config.basic_auth.password?default(\"\")?trim?length gt 0>\r\n \"basic_auth\":{\r\n \"username\": \"${endpoint.config.basic_auth.username}\",\r\n \"password\": \"${endpoint.config.basic_auth.password}\"\r\n },\r\n </#if>\r\n </#if>\r\n \r\n <#if endpoint.config.bearer_token??&&endpoint.config.bearer_token?trim?length gt 0>\r\n \"authorization\":{\r\n \"type\":\"Bearer\",\r\n \"credentials\":\"${endpoint.config.bearer_token}\"\r\n },\r\n </#if>\r\n\r\n \r\n <#-- params 不为空且类型为 http ,添加 params -->\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\" >\r\n \"scheme\": \"${endpoint.config.protocol}\",\r\n <#if endpoint.config.params?? && (endpoint.config.params?size >0) >\r\n \"params\":{\r\n <#list endpoint.config.params?keys as itemKey>\r\n \"${itemKey}\":[\r\n <#list endpoint.config.params[itemKey] as pojo>\r\n \"${pojo}\"\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#sep>,</#sep>\r\n </#list>\r\n },\r\n </#if>\r\n <#elseif endpoint.config.protocol == \"snmp\">\r\n <#-- 类型是 snmp ,组织 param 数据 , 原来params弃用,因为 snmp_exporter 不支持其他参数 -->\r\n \"params\":{\r\n \"target\":[ \"${endpoint.config.host}:${endpoint.config.port?c}\" ],\r\n \"module\":[ \"${endpoint.module.name}\" ]\r\n },\r\n </#if>\r\n \r\n \"static_configs\": [{\r\n \"targets\": [<#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"${endpoint.config.host}:${endpoint.config.port?c}\"\r\n <#else>\r\n \"127.0.0.1:19116\"\r\n </#if>\r\n ],\r\n \"labels\": {\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \"datacenter_id\":${endpoint.dc.id?c},\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \"project_id\": ${endpoint.project.id?c},\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \"asset_id\": ${endpoint.asset.id?c},\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \"module_id\": ${endpoint.module.id?c},\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \"endpoint_id\": ${endpoint.id?c},\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\",\r\n \"parent_asset_id\" : ${endpoint.asset.parent.id?c},\r\n </#if>\r\n\r\n \"nz_agent_id\": ${endpoint.agent.id?c}\r\n \r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"datacenter_id\" && key != \"project\" && key != \"project_id\" && key != \"asset\" && key != \"asset_id\" && key != \"module\" && key != \"module_id\" && key != \"endpoint\" && key != \"endpoint_id\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n }\r\n }],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if endpoint.config.relabel_config??&& (endpoint.config.relabel_config?size >0)>\r\n <#list endpoint.config.relabel_config as relabel>\r\n ,{\r\n <#if relabel.action?? && (relabel.action == \'labeldrop\' || relabel.action == \'labelkeep\')>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'labelmap\'>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && (relabel.action == \'drop\' || relabel.action == \'keep\')>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'replace\'>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"separator\": \"${((relabel.separator!\'\')?length>0)?string((relabel.separator!\'\'),\";\")}\", \r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"target_label\": \"${(relabel.target_label)!\'\'}\"\r\n </#if>\r\n }\r\n </#list>\r\n </#if>\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n \r\n <#-- ping 配置 -->\r\n \r\n <#if endpointList??&&(endpointList?size>0)>\r\n ,\r\n </#if>\r\n \r\n <#list assetList as asset>\r\n {\r\n \"job_name\": \"asset_ping_${asset.id?c}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": \"/probe\",\r\n \"scrape_interval\": <#if asset.assetPingInterval?default(\"\")?trim?length gt 0>\r\n \"${asset.assetPingInterval}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if asset.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${asset.scrape_timeout}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n \"params\": {\r\n \"target\":[ \"${asset.manageIp}\" ],\r\n \"module\":[ \"ping\" ]\r\n },\r\n \"static_configs\": [{\r\n \"targets\": [\"127.0.0.1:19115\"],\r\n \"labels\": {\r\n \"datacenter\": \"${asset.dc.name}\",\r\n \"host\": \"${asset.manageIp}\",\r\n \"module\": \"ping\",\r\n \"source_ip\": \"${asset.agent.host}\",\r\n \"nz_agent_id\": ${asset.agent.id?c}\r\n }\r\n }],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#-- cortex 处理 -->\r\n ,\r\n \"remote_write\": [\r\n <#list remoteWriteUrlInfos as remoteConf>\r\n {\r\n \"url\": \"${remoteConf.url}\",\r\n \"authorization\": {\r\n \"type\": \"Bearer\",\r\n \"credentials\": \"${remoteConf.token}\"\r\n },\r\n \"tls_config\":{\r\n \"insecure_skip_verify\":true\r\n },\r\n \"queue_config\":{\r\n \"capacity\": 5000,\r\n \"max_samples_per_send\": 1000,\r\n \"min_shards\": 5,\r\n \"max_shards\": 10,\r\n \"min_backoff\": \"20ms\",\r\n \"min_backoff\": \"50ms\"\r\n }\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#else>\r\n <#-- global 配置 -->\r\n \"scrape_configs\": [\r\n <#list jobList as jobPojo>\r\n {\r\n \"job_name\": \"${jobPojo.job_name}\",\r\n \"scheme\": \"${jobPojo.scheme?default(\"http\")}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n <#if jobPojo.isFederate> \r\n \"honor_labels\": ${jobPojo.honor_labels},\r\n \"params\": {\r\n \"match[]\": [\r\n \"{__name__=~\\\".+\\\",nz_agent_id != \\\"${jobPojo.excludeAgentId?c}\\\"}\"\r\n ]\r\n },\r\n \"authorization\":{\r\n \"type\":\"Bearer\",\r\n \"credentials\":\"${jobPojo.token}\"\r\n },\r\n </#if>\r\n \"metrics_path\": <#if jobPojo.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${jobPojo.metrics_path}\",\r\n <#else>\r\n \"/metrics\",\r\n </#if>\r\n \"static_configs\":[\r\n <#list jobPojo.staticConfigList as staticConf >\r\n {\r\n \"targets\": [\r\n <#list staticConf.targets as targetConf>\r\n \"${targetConf}\"<#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#if staticConf.labels ??&& (staticConf.labels?size >0)>\r\n ,\r\n \"labels\": {\r\n <#list staticConf.labels?keys as itemKey>\r\n \"${itemKey}\":<#if staticConf.labels[itemKey]?default(\"\")?trim?length gt 0>\r\n \"${staticConf.labels[itemKey]}\"\r\n <#else>\"\"</#if><#sep>,</#sep>\r\n </#list>\r\n } \r\n </#if>\r\n }<#sep>,</#sep>\r\n </#list>\r\n ],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if !jobPojo.instanceRelabel> \r\n ,\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n </#if>\r\n ]\r\n }<#sep>,</#sep>\r\n </#list>\r\n \r\n <#-- ping 配置 -->\r\n \r\n <#if jobList??&&(jobList?size>0)>\r\n ,\r\n </#if>\r\n \r\n <#list assetList as asset>\r\n {\r\n \"job_name\": \"asset_ping_${asset.id?c}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": \"/probe\",\r\n \"scrape_interval\": <#if asset.assetPingInterval?default(\"\")?trim?length gt 0>\r\n \"${asset.assetPingInterval}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if asset.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${asset.scrape_timeout}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n \"params\": {\r\n \"target\":[ \"${asset.manageIp}\" ],\r\n \"module\":[ \"ping\" ]\r\n },\r\n \"static_configs\": [{\r\n \"targets\": [\"127.0.0.1:19115\"],\r\n \"labels\": {\r\n \"datacenter\": \"${asset.dc.name}\",\r\n \"host\": \"${asset.manageIp}\",\r\n \"module\": \"ping\",\r\n \"source_ip\": \"${asset.agent.host}\",\r\n \"nz_agent_id\": ${asset.agent.id?c}\r\n }\r\n }],\r\n \"relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n \r\n \r\n <#if ( jobList??&&(jobList?size>0)) || assetList??&&(assetList?size>0)>\r\n ,\r\n </#if>\r\n \r\n <#list endpointList as endpoint>\r\n {\r\n \"job_name\": ${endpoint.id?c},\r\n \"tls_config\":{\r\n \"insecure_skip_verify\": true\r\n },\r\n \"metrics_path\": <#if endpoint.config.metrics_path?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.metrics_path}\",\r\n <#else>\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"/metrics\",\r\n <#else>\r\n \"/snmp\",\r\n </#if>\r\n </#if>\r\n \"scrape_interval\": <#if endpoint.config.scrape_interval?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_interval?c}s\",\r\n <#else>\r\n \"${scrape_interval}s\",\r\n </#if>\r\n \"scrape_timeout\": <#if endpoint.config.scrape_timeout?default(\"\")?trim?length gt 0>\r\n \"${endpoint.config.scrape_timeout?c}s\",\r\n <#else>\r\n <#if scrape_timeout??> \r\n \"${scrape_timeout}s\",\r\n <#else>\r\n \"10s\",\r\n </#if>\r\n </#if>\r\n\r\n\r\n\r\n <#if endpoint.config.basic_auth??&& (endpoint.config.basic_auth?size >0)>\r\n <#if endpoint.config.basic_auth.username?default(\"\")?trim?length gt 0 && endpoint.config.basic_auth.password?default(\"\")?trim?length gt 0>\r\n \"basic_auth\":{\r\n \"username\": \"${endpoint.config.basic_auth.username}\",\r\n \"password\": \"${endpoint.config.basic_auth.password}\"\r\n },\r\n </#if>\r\n </#if>\r\n \r\n \r\n <#if endpoint.config.bearer_token??&&endpoint.config.bearer_token?trim?length gt 0>\r\n \"authorization\":{\r\n \"type\":\"Bearer\",\r\n \"credentials\":\"${endpoint.config.bearer_token}\"\r\n },\r\n </#if>\r\n\r\n \r\n <#-- params 不为空且类型为 http ,添加 params -->\r\n <#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\" >\r\n \"scheme\": \"${endpoint.config.protocol}\",\r\n <#if endpoint.config.params?? && (endpoint.config.params?size >0) >\r\n \"params\":{\r\n <#list endpoint.config.params?keys as itemKey>\r\n \"${itemKey}\":[\r\n <#list endpoint.config.params[itemKey] as pojo>\r\n \"${pojo}\"\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n <#sep>,</#sep>\r\n </#list>\r\n },\r\n </#if>\r\n <#elseif endpoint.config.protocol == \"snmp\">\r\n <#-- 类型是 snmp ,组织 param 数据 , 原来params弃用,因为 snmp_exporter 不支持其他参数 -->\r\n \"params\":{\r\n \"target\":[ \"${endpoint.config.host}:${endpoint.config.port?c}\" ],\r\n \"module\":[ \"${endpoint.module.name}\" ]\r\n },\r\n </#if>\r\n \r\n \"static_configs\": [{\r\n \"targets\": [<#if endpoint.config.protocol == \"http\" || endpoint.config.protocol == \"https\">\r\n \"${endpoint.config.host}:${endpoint.config.port?c}\"\r\n <#else>\r\n \"127.0.0.1:19116\"\r\n </#if>\r\n ],\r\n \"labels\": {\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \"datacenter_id\":${endpoint.dc.id?c},\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \"project_id\": ${endpoint.project.id?c},\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \"asset_id\": ${endpoint.asset.id?c},\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \"module_id\": ${endpoint.module.id?c},\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \"endpoint_id\": ${endpoint.id?c},\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\",\r\n \"parent_asset_id\" : ${endpoint.asset.parent.id?c},\r\n </#if>\r\n \r\n \"nz_agent_id\": ${endpoint.agent.id?c}\r\n \r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"datacenter_id\" && key != \"project\" && key != \"project_id\" && key != \"asset\" && key != \"asset_id\" && key != \"module\" && key != \"module_id\" && key != \"endpoint\" && key != \"endpoint_id\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n }\r\n }],\r\n \"metric_relabel_configs\": [\r\n {\r\n \"regex\": \"job\",\r\n \"action\": \"labeldrop\"\r\n },\r\n {\r\n \"regex\": \"instance\",\r\n \"action\": \"labeldrop\"\r\n }\r\n <#if endpoint.config.relabel_config??&& (endpoint.config.relabel_config?size >0)>\r\n <#list endpoint.config.relabel_config as relabel>\r\n ,{\r\n <#if relabel.action?? && (relabel.action == \'labeldrop\' || relabel.action == \'labelkeep\')>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'labelmap\'>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && (relabel.action == \'drop\' || relabel.action == \'keep\')>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'replace\'>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"separator\": \"${((relabel.separator!\'\')?length>0)?string((relabel.separator!\'\'),\";\")}\", \r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"target_label\": \"${(relabel.target_label)!\'\'}\"\r\n </#if>\r\n }\r\n </#list>\r\n </#if>\r\n ]\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n \r\n ]\r\n \r\n <#-- cortex 处理 -->\r\n ,\r\n \"remote_write\": [\r\n <#list remoteWriteUrlInfos as remoteConf>\r\n { \r\n \"url\": \"${remoteConf.url}\",\r\n \"authorization\": {\r\n \"type\": \"Bearer\",\r\n \"credentials\": \"${remoteConf.token}\"\r\n },\r\n \"tls_config\":{\r\n \"insecure_skip_verify\":true\r\n },\r\n \"queue_config\":{\r\n \"capacity\": 5000,\r\n \"max_samples_per_send\": 1000,\r\n \"min_shards\": 5,\r\n \"max_shards\": 10,\r\n \"min_backoff\": \"20ms\",\r\n \"min_backoff\": \"50ms\"\r\n }\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ] \r\n </#if>\r\n}', 1, 'prometheus config文件模板'); REPLACE INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (NULL, 'promtail_yml_tmpl', '{\r\n \"server\": {\r\n \"http_listen_address\": \"0.0.0.0\",\r\n \"http_listen_port\": 19080,\r\n \"grpc_listen_port\": 19081\r\n },\r\n \"clients\": [\r\n <#list clientsMapList as clientMap>\r\n {\r\n \"url\" : \"${clientMap.url}\",\r\n \"bearer_token\": \"${clientMap.token}\",\r\n \"tls_config\":{\r\n \"insecure_skip_verify\":true\r\n }\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ],\r\n \"positions\": {\r\n \"filename\": \"/opt/nezha/promtail/positions.yaml\"\r\n },\r\n \"scrape_configs\": [\r\n <#list endpointList as endpoint>\r\n {\r\n \"job_name\": \"${endpoint.id?c}_${endpoint_index}\",\r\n \"pipeline_stages\": [\r\n <#if endpoint.config.pipeline??&&(endpoint.config.pipeline?size>0)>\r\n <#list endpoint.config.pipeline as pipeline>\r\n {\r\n <#if pipeline.type == \"regex\">\r\n \"regex\": {\r\n \"expression\": \"${pipeline.expression}\",\r\n \"source\": \"${pipeline.source}\"\r\n }\r\n </#if>\r\n <#if pipeline.type == \"json\">\r\n \"json\": {\r\n \"expressions\": {\r\n <#if pipeline.expressions??&& (pipeline.expressions?size >0)>\r\n <#list pipeline.expressions?keys as key>\r\n \"${key}\":\"${pipeline.expressions[key]}\"\r\n <#sep>,</#sep>\r\n </#list>\r\n </#if>\r\n },\r\n \"source\": \"${pipeline.source}\"\r\n }\r\n </#if>\r\n <#if pipeline.type == \"template\">\r\n \"template\": {\r\n \"source\": \"${pipeline.source}\",\r\n \"template\": \"${pipeline.template}\"\r\n }\r\n </#if>\r\n <#if pipeline.type == \"timestamp\">\r\n \"timestamp\": {\r\n \"source\": \"${pipeline.source}\",\r\n \"format\": \"${pipeline.format}\"\r\n }\r\n </#if>\r\n <#if pipeline.type == \"labels\"> \r\n \"labels\": { \r\n <#if pipeline.labels??&& (pipeline.labels?size >0)>\r\n <#list pipeline.labels?keys as key>\r\n \"${key}\":\"${pipeline.labels[key]}\"\r\n <#sep>,</#sep>\r\n </#list>\r\n </#if>\r\n }\r\n </#if> \r\n <#if pipeline.type == \"output\"> \r\n \"output\": {\r\n \"source\": \"${pipeline.source}\"\r\n }\r\n </#if> \r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n </#if>\r\n ],\r\n \"relabel_configs\": [\r\n <#if endpoint.config.relabel_config ??&& (endpoint.config.relabel_config?size >0)>\r\n <#list endpoint.config.relabel_config as relabel>\r\n {\r\n <#if relabel.action?? && (relabel.action == \'labeldrop\' || relabel.action == \'labelkeep\')>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'labelmap\'>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && (relabel.action == \'drop\' || relabel.action == \'keep\')>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\"\r\n </#if>\r\n <#if relabel.action?? && relabel.action == \'replace\'>\r\n <#if relabel.source_labels??&& (relabel.source_labels?size >0)>\r\n \"source_labels\":[\r\n <#list relabel.source_labels as label>\r\n \"${label!\'\'}\"<#sep>,</#sep>\r\n </#list>\r\n ],\r\n </#if>\r\n \"separator\": \"${((relabel.separator!\'\')?length>0)?string((relabel.separator!\'\'),\";\")}\", \r\n \"regex\": \"${(relabel.regex)!\'\'}\",\r\n \"replacement\": \"${(relabel.replacement)!\'\'}\",\r\n \"action\": \"${(relabel.action)!\'\'}\",\r\n \"target_label\": \"${(relabel.target_label)!\'\'}\"\r\n </#if>\r\n }<#sep>,</#sep>\r\n </#list>\r\n <#-- 自定义 relabel_config 为空,补充默认配置 -->\r\n <#if endpoint.config.type == \"syslog\">\r\n ,{\r\n \"source_labels\": [\r\n \"__syslog_message_app_name\"\r\n ],\r\n \"regex\":\"${endpoint.config.appName}\",\r\n \"action\":\"keep\"\r\n },\r\n {\r\n \"source_labels\": [\r\n \"__syslog_message_app_name\"\r\n ],\r\n \"target_label\": \"appName\"\r\n }\r\n </#if>\r\n \r\n <#if endpoint.config.type == \"journal\">\r\n ,{\r\n \"source_labels\": [\r\n \"__journal__systemd_unit\"\r\n ],\r\n \"regex\":\"${endpoint.config.unit}\",\r\n \"action\":\"keep\"\r\n },\r\n {\r\n \"source_labels\": [\r\n \"__journal__systemd_unit\"\r\n ],\r\n \"target_label\": \"unit\"\r\n }\r\n </#if>\r\n <#else>\r\n <#-- 自定义 relabel_config 为空,补充默认配置 -->\r\n <#if endpoint.config.type == \"syslog\">\r\n {\r\n \"source_labels\": [\r\n \"__syslog_message_app_name\"\r\n ],\r\n \"regex\":\"${endpoint.config.appName}\",\r\n \"action\":\"keep\"\r\n },\r\n {\r\n \"source_labels\": [\r\n \"__syslog_message_app_name\"\r\n ],\r\n \"target_label\": \"appName\"\r\n }\r\n </#if>\r\n \r\n <#if endpoint.config.type == \"journal\">\r\n {\r\n \"source_labels\": [\r\n \"__journal__systemd_unit\"\r\n ],\r\n \"regex\":\"${endpoint.config.unit}\",\r\n \"action\":\"keep\"\r\n },\r\n {\r\n \"source_labels\": [\r\n \"__journal__systemd_unit\"\r\n ],\r\n \"target_label\": \"unit\"\r\n }\r\n </#if>\r\n </#if>\r\n ],\r\n <#if endpoint.config.type == \"file\">\r\n \"static_configs\": [\r\n {\r\n \"labels\": {\r\n \"__path__\": \"${endpoint.config.fileName}\",\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\"\r\n </#if>\r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"project\" && key != \"asset\" && key != \"module\" && key != \"endpoint\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n }\r\n }\r\n ]\r\n <#elseif endpoint.config.type == \"syslog\">\r\n \"syslog\": {\r\n \"listen_address\": \"${endpoint.config.listenAddress}\",\r\n \"labels\": {\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\"\r\n </#if>\r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"project\" && key != \"asset\" && key != \"module\" && key != \"endpoint\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n }\r\n }\r\n <#elseif endpoint.config.type == \"journal\">\r\n \"journal\": {\r\n \"labels\": {\r\n \"datacenter\": \"${endpoint.dc.name}\",\r\n \r\n \"project\": \"${endpoint.project.name}\",\r\n \r\n \"asset\": \"${endpoint.asset.name}\",\r\n \r\n \"module\": \"${endpoint.module.name}\",\r\n \r\n \"endpoint\": \"${endpoint.name}\",\r\n \r\n <#if endpoint.asset.parent??&&(endpoint.asset.parent?size >0)>\r\n \"parent_asset\" : \"${endpoint.asset.parent.name}\"\r\n </#if>\r\n \r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n ,\r\n </#if>\r\n <#-- 补充用户自定义 Labels -->\r\n <#if endpoint.config.labels??&& (endpoint.config.labels?size >0)>\r\n <#list endpoint.config.labels?keys as key>\r\n <#if key != \"datacenter\" && key != \"project\" && key != \"asset\" && key != \"module\" && key != \"endpoint\">\r\n \"${key}\":\"${endpoint.config.labels[key]}\"<#sep>,</#sep>\r\n </#if>\r\n </#list>\r\n </#if>\r\n\r\n }\r\n } \r\n <#elseif endpoint.config.type == \"kubernetes\">\r\n \"kubernetes_sd_configs\": [\r\n {\r\n \"api_server\": \"${((endpoint.config.apiServer!\'\')?length>0)?string((endpoint.config.apiServer!\'\'),\"127.0.0.1\")}\",\r\n \"role\": \"${((endpoint.config.role!\'\')?length>0)?string((endpoint.config.role!\'\'),\"pod\")}\",\r\n \r\n <#if endpoint.config.basic_auth??&& (endpoint.config.basic_auth?size >0)>\r\n <#if endpoint.config.basic_auth.username?default(\"\")?trim?length gt 0 && endpoint.config.basic_auth.password?default(\"\")?trim?length gt 0>\r\n \"basic_auth\":{\r\n \"username\": \"${endpoint.config.basic_auth.username}\",\r\n \"password\": \"${endpoint.config.basic_auth.password}\"\r\n },\r\n </#if>\r\n </#if>\r\n \r\n <#if endpoint.config.bearer_token??&&endpoint.config.bearer_token?trim?length gt 0>\r\n \"bearer_token\": \"${endpoint.config.bearer_token}\",\r\n </#if>\r\n \r\n \"namespaces\": {\r\n \"names\": [\r\n <#if endpoint.config.namespaces.names ??&& (endpoint.config.namespaces.names?size >0)>\r\n <#list endpoint.config.namespaces.names as namespace>\r\n \"${namespace}\"<#sep>,</#sep>\r\n </#list>\r\n </#if>\r\n ]\r\n }\r\n }\r\n ]\r\n </#if>\r\n }\r\n <#sep>,</#sep>\r\n </#list>\r\n ]\r\n}', 1, 'promtail.yml 配置模板'); REPLACE INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (null, 'pin_policy', '{\"enable\":0,\"length\":6,\"num\":1,\"lower\":1,\"upper\":1,\"spec\":1,\"valid\":30,\"remind\":3,\"retry\":2,\"lockTime\":30}', 1, NULL); REPLACE INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (null, 'snmp_exporter_prometheus_path', '/metrics', 1, NULL); |
