本文介绍了无法从配置文件Consul创建Http Health Check的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用配置文件为REST服务创建http运行状况检查。

I have been trying to create a http health check for a REST service using the config file.

在加载领事时,它会从配置中读取服务详细信息文件,并且反映在8500 Web UI中。

While loading the consul, it read the service details from the config file and that is reflected in 8500 Web UI.

但是它没有添加该服务的运行状况检查详细信息。

But it did not add the health check details for that service.

将运行状况检查与服务定义(案例1)一起显示时也不会显示错误。

No error is displayed too when the health check is along with the service definition (Case 1).

但是当尝试进行运行状况检查时,它会通知错误。分别配置。 (案例2)

But it notified an error when tried to give the health check config seperatly. (Case 2)

但是,通过rest api添加时,我能够成功添加http运行状况检查。 (情况3)

However I can able to successfully add a http health check when added via rest api. (Case 3)

带有服务详细信息的健康检查:-(情况1)

Health Check with service details:- (Case 1)

{
"service": {
"id":"somename",
"name":"nameofthissevice",
"service": "myservice",
"address": "127.0.0.1",
"port": 62133,
"enableTagOverride": false,
"check": {
"HTTP": "http://127.0.0.1:62133/Service1.svc/MyService/PingMe",
"Interval": "5s"
}
}
}

仅健康检查配置:-(第2种情况)

Health Check config alone:- (Case 2)

"check": {
"http": "http://127.0.0.1:62133/Service1.svc/MyService/PingMe",
"interval": "5s",
"timeout": "150s",
"ttl" : "100s"
}

通过C#中的代码进行健康检查:-(情况3)

Health Check via Code in C#:- (Case 3)

var check = new AgentServiceCheck()
        {
            Interval = TimeSpan.FromSeconds(10),
            HTTP = "http://127.0.0.1:62133/Service1.svc/MyService/PingMe",
            DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(10)
        };

var srv = new AgentServiceRegistration()
        {
            XXXXX,
            Check = check
        };

var result = client.Agent.ServiceRegister(srv).GetAwaiter().GetResult();

我在Windows上使用Consul V.0.9.0。

I am using Consul V.0.9.0 for windows.

这是我的领事日志。

==>领事代理正在运行!

版本:'v0.9.0'

节点ID:'d0afc715-46d0-6087-27e9-a388cc274bd2'

节点名称:'BETA-PC'

数据中心:'dc1'

服务器:true(引导程序:false)

客户端地址:127.0.0.1(HTTP:8500,HTTPS:-1,DNS:8600)

群集地址:127.0。 0.1(LAN:8301,WAN:8302)

八卦加密:false,RPC-TLS:false,TLS传入:false

==> Consul agent running!
Version: 'v0.9.0'
Node ID: 'd0afc715-46d0-6087-27e9-a388cc274bd2'
Node name: 'BETA-PC'
Datacenter: 'dc1'
Server: true (bootstrap: false)
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false

== >日志数据现在将在出现时流式传输:

==> Log data will now stream in as it occurs:

2017/08/11 00:18:23 [DEBUG] Using random ID "d0afc715-46d0-6087-27e9-a388cc274bd2" as node ID
2017/08/11 00:18:23 [DEBUG] agent: restored service definition "somename" from "services\\ServiceRegister.json"
2017/08/11 00:18:23 [WARN] raft: Heartbeat timeout from "" reached, starting election
2017/08/11 00:18:23 [INFO] consul: member 'BETA-PC' joined, marking health alive
2017/08/11 00:18:24 [INFO] agent: Synced service 'somename'
2017/08/11 00:18:24 [DEBUG] agent: Node info in sync
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/internal/ui/nodes?dc=dc1&token=<hidden> (0s) from=127.0.0.1:52479
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/catalog/datacenters (37.0021ms) from=127.0.0.1:52478
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/coordinate/nodes?dc=dc1&token=<hidden> (14.0008ms) from=127.0.0.1:52480
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/internal/ui/services?dc=dc1&token=<hidden> (0s) from=127.0.0.1:52480
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/health/service/myservice?dc=dc1&token=<hidden> (1.0001ms) from=127.0.0.1:52480

任何人都可以提供有关此信息的信息。

Could anyone give some info on this one.

Thx

推荐答案

案例1具有大写的HTTP密钥,看起来像错误-

case 1 has upper case HTTP key which seems like a mistake - https://www.consul.io/docs/agent/checks.html

情况2-如果这是您的整个检查文件,则JSON无效(用{}换行)。您可能还需要通过指定service_id

case 2 - if this is your entire check file, the JSON is invalid (wrap it with { }). you may also want to link it to the service by specifying a service_id

这篇关于无法从配置文件Consul创建Http Health Check的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:58