Golang: “gocraft/health”库中的healthd和healthtop。

huangapple go评论84阅读模式
英文:

Golang: healthd and healthtop of the library "gocraft/health"

问题

我正在使用gocraft/health来检查我的服务的健康状况,并获取每个端点的指标。我正在使用JSON轮询接收器来获取指标。

sink := health.NewJsonPollingSink(time.Minute*5, time.Minute*5)
stream.AddSink(sink)

我想在这里使用healthtop和healthd链接中有相关说明。

我按照他们的说法修复了环境变量:export HEALTHD_MONITORED_HOSTPORTS=:5001 HEALTHD_SERVER_HOSTPORT=:5002 healthd

在他们说完"Now you can run it"之后,我不知道该如何运行。他们没有给出任何命令。我真的不明白他们的意思。

我导航到src/github.com/gocraft/health/cmd/healthd。我找到了main.go,当我运行它时,控制台输出如下:

[openrtb@sd-69536 healthd]$ go run main.go
[2015-06-17T23:04:20.871743758Z]: job:general event:starting kvs:[health_host_port::5002 monitored_host_ports::5001,:5002 server_host_port::5002]
[2015-06-17T23:04:20.87810814Z]: job:poll status:success time:4 ms kvs:[host_port::5002]
[2015-06-17T23:04:20.881896459Z]: job:poll status:success time:8 ms kvs:[host_port::5001]
[2015-06-17T23:04:20.882338024Z]: job:recalculate status:success time:231 μs
[2015-06-17T23:04:23.275370787Z]: job:recalculate status:success time:6 μs
[2015-06-17T23:04:30.875230839Z]: job:poll status:success time:1573 μs kvs:[host_port::5002]
[2015-06-17T23:04:30.881415193Z]: job:poll status:success time:7 ms kvs:[host_port::5001]
...

但是在这些端点上没有结果:

localhost:5002/jobs: 列出前几个作业

localhost:5002/hosts: 列出所有监控的主机及其状态

它给了我**{"error": "not_found"}**。

除了localhost:5002/health之外,我得到了以下JSON响应:

{
	"instance_id": "sd-69536.1291",
	"interval_duration": 3600000000000,
	"aggregations": [
		{
			"interval_start": "2015-06-18T01:00:00+02:00",
			"serial_number": 48,
			"jobs": {
				"general": {
					"timers": {},
					"events": {
						"starting": 1
					},
					"event_errs": {},
					"count": 0,
					"nanos_sum": 0,
					"nanos_sum_squares": 0,
					"nanos_min": 0,
					"nanos_max": 0,
					"count_success": 0,
					"count_validation_error": 0,
					"count_panic": 0,
					"count_error": 0,
					"count_junk": 0
				},
				"poll": {
					"timers": {},
					"events": {},
					"event_errs": {},
					"count": 24,
					"nanos_sum": 107049159,
					"nanos_sum_squares": 6.06770682813009e+14,
					"nanos_min": 1581783,
					"nanos_max": 8259442,
					"count_success": 24,
					"count_validation_error": 0,
					"count_panic": 0,
					"count_error": 0,
					"count_junk": 0
				},
				"recalculate": {
					"timers": {},
					"events": {},
					"event_errs": {},
					"count": 23,
					"nanos_sum": 3501601,
					"nanos_sum_squares": 6.75958305123e+11,
					"nanos_min": 70639,
					"nanos_max": 290877,
					"count_success": 23,
					"count_validation_error": 0,
					"count_panic": 0,
					"count_error": 0,
					"count_junk": 0
				}
			},
			"timers": {},
			"events": {
				"starting": 1
			},
			"event_errs": {}
		}
	]
}

但是我不知道这个结果的含义,因为它与我的localhost:5001/health端点没有任何关系,而根据他们的说法,它们应该是聚合的。

英文:

Im using gocraft/health to check the health of my service and have the metrics of each endPoint.
Im usin The JSON polling sink to get the metrics.

sink := health.NewJsonPollingSink(time.Minute*5, time.Minute*5)
stream.AddSink(sink)

I want to use healthtop and healthd here Link they explain how.

I fixed the environment variables: export HEALTHD_MONITORED_HOSTPORTS=:5001 HEALTHD_SERVER_HOSTPORT=:5002 healthd
as they said

after they said "Now you can run it". how, they didn't give any command to do it.I didn't realy understand what they mean.

I navigated to src/github.com/gocraft/health/cmd/healthd. I found main.go when I run it I got that in the console

    [openrtb@sd-69536 healthd]$ go run main.go
    [2015-06-17T23:04:20.871743758Z]: job:general event:starting kvs:[health_host_port::5002 monitored_host_ports::5001,:5002 server_host_port::5002]
    [2015-06-17T23:04:20.87810814Z]: job:poll status:success time:4 ms kvs:[host_port::5002]
    [2015-06-17T23:04:20.881896459Z]: job:poll status:success time:8 ms kvs:[host_port::5001]
    [2015-06-17T23:04:20.882338024Z]: job:recalculate status:success time:231 μs
    [2015-06-17T23:04:23.275370787Z]: job:recalculate status:success time:6 μs
    [2015-06-17T23:04:30.875230839Z]: job:poll status:success time:1573 μs kvs:[host_port::5002]
    [2015-06-17T23:04:30.881415193Z]: job:poll status:success time:7 ms kvs:[host_port::5001]
.
.

but no reslute on the those endpoints

localhost:5002/jobs: Lists top jobs

localhost:5002/hosts: Lists all monitored hosts and their statuses

it gave me {"error": "not_found"}

excepte this localhost:5002/health I got this JSON responce

{
	"instance_id": "sd-69536.1291",
	"interval_duration": 3600000000000,
	"aggregations": [
		{
			"interval_start": "2015-06-18T01:00:00+02:00",
			"serial_number": 48,
			"jobs": {
				"general": {
					"timers": {},
					"events": {
						"starting": 1
					},
					"event_errs": {},
					"count": 0,
					"nanos_sum": 0,
					"nanos_sum_squares": 0,
					"nanos_min": 0,
					"nanos_max": 0,
					"count_success": 0,
					"count_validation_error": 0,
					"count_panic": 0,
					"count_error": 0,
					"count_junk": 0
				},
				"poll": {
					"timers": {},
					"events": {},
					"event_errs": {},
					"count": 24,
					"nanos_sum": 107049159,
					"nanos_sum_squares": 6.06770682813009e+14,
					"nanos_min": 1581783,
					"nanos_max": 8259442,
					"count_success": 24,
					"count_validation_error": 0,
					"count_panic": 0,
					"count_error": 0,
					"count_junk": 0
				},
				"recalculate": {
					"timers": {},
					"events": {},
					"event_errs": {},
					"count": 23,
					"nanos_sum": 3501601,
					"nanos_sum_squares": 6.75958305123e+11,
					"nanos_min": 70639,
					"nanos_max": 290877,
					"count_success": 23,
					"count_validation_error": 0,
					"count_panic": 0,
					"count_error": 0,
					"count_junk": 0
				}
			},
			"timers": {},
			"events": {
				"starting": 1
			},
			"event_errs": {}
		}
	]
}

but no idea what this result mean, because it doesn't have any relation with my
localhost:5001/health EndPoint that should normaly aggregate as they said.

答案1

得分: 1

你下载的是一个二进制文件,所以如果你在正确的目录下,可以直接使用healthd来调用它,他们实际上提供了这个例子:

HEALTHD_MONITORED_HOSTPORTS=:5020 HEALTHD_SERVER_HOSTPORT=:5032 healthd

这并不是设置环境变量,而是使用这两个值来调用healthd(需要使用export或其他方法来使更改持久化,超出一个命令的范围)。healthtop更清楚地说明了它是什么,但从它们的路径可以看出,它们都是gocraft/health/cmd/healthtop命令。他们有几个在bash中使用healthtop的例子,对于healthd没有那么明确,但它们是相同的。

如果你运行了你在问题中展示的那个命令,那么你可以尝试运行healthtop jobs或类似的命令。我对这个项目了解不多,也不想去研究它,但据我所知,healthd只是一个服务,它从各种/health端点收集结果,并在一个API中提供这些结果。看起来他们希望你使用healthtop来查看报告。

还要注意这一点:

> 太棒了!为了了解healthd提供的数据类型,你可以手动导航到:
>/jobs:列出顶级作业
>/aggregations:提供聚合的时间序列
>/aggregations/overall:将所有时间序列聚合成一个聚合。
>/hosts:列出所有受监视的主机及其状态。
>但是,查看原始JSON只是为了让你了解数据。请参阅下一节...

我不确定域名是什么(如果你在本地运行,可能是localhost:5032),但你应该可以直接访问localhost:5032/jobs,看到healthd正在运行并且在做一些事情。还要检查你的应用程序,确认它是否正在运行。不要期望直接从它那里获得任何输出,这就是healthtop的作用。

英文:

What you downloaded is a binary so you can just invoke it with healthd if you're in the correct directory, they actually provide this example;

HEALTHD_MONITORED_HOSTPORTS=:5020 HEALTHD_SERVER_HOSTPORT=:5032 healthd

Which isn't setting env var as much as invoking healthd with those two values (export or something would be required to persist the change beyond the one command). healthtop more clearly states what it is but as you can see by their paths, they're both commands gocraft/health/cmd/healthtop. They have several examples of using healthtop from bash, not so explicit about healthd but it's the same.

If you ran that command (as you show in your question) then you may want to try healthtop jobs or something to that effect. I don't know a ton about this project and don't care to research it but from what I can tell healthd is just a service that collects results from various /health endpoints and makes them available in on API. It seems like they intend for you to use healthtop to on top of it to view reports.

Also note this;

> Great! To get a sense of the type of data healthd serves, you can manually navigate to:
>/jobs: Lists top jobs
>/aggregations: Provides a time series of aggregations
>/aggregations/overall: Squishes all time series aggregations into one aggregation.
>/hosts: Lists all monitored hosts and their statuses.
>However, viewing raw JSON is just to give you a sense of the data. See the next section...

I'm not sure what the domain is (localhost:5032 if you're running locally?) but you should probably just be able to go to localhost:5032/jobs and see the healthd is running and doing something. Also check your apps to confirm it's up and running. Don't expect any output from it directly, that's what healthtop is for.

huangapple
  • 本文由 发表于 2015年6月17日 04:31:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/30877603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定