小编Sim*_* K.的帖子

HAProxy 从操作系统使用 DNS?

我在 hsproxy.cfg 中为后端服务器使用 dns 名称,例如

backend s0
    server server0 server0.x.y.local:8080

backend s1
    server server1 server1.x.y.local:8080
Run Code Online (Sandbox Code Playgroud)

启动后名称解析工作正常。但是一旦后端服务器的 ipadress 更改,对 haproxy 的请求需要很长时间(例如 25 秒),然后以 503 响应(原因:SC)。它不会更新或重新解析 dns 名称。但是curl那台机器上的一个工作正常,所以操作系统正确地更新了这些 dns 条目的 ip 地址。所以看起来 haproxy 在启动时缓存 IP 地址并且从不更改它们。

我在 kubernetes 集群中使用 haproxy 作为 pod(不确定这是否重要)。

从我在官方文档中读到的内容来看,libc 选项应该使用操作系统解析吗?我试过放置init-addr libc但它没有帮助,haproxy 在机器上仍然以长时间运行的 503 响应,dns 完美解析。

我还看到在使用resolver条目时可以进行一些微调,您可以在其中配置刷新时间等。如果没有 haproxy.cfg 中的硬编码名称服务器,而只使用操作系统中的名称服务器,这是否可行?

dns haproxy kubernetes

7
推荐指数
1
解决办法
1532
查看次数

普罗米修斯收集器失败,并显示“收集的指标之前已收集,具有相同的名称和标签值”

我有一个设备以以下格式将温度测量结果作为 JSON 公开:

[
  {
    "dataPointId": 123456,
    "values": [
      {
        "t": 1589236277000,
        "v": 14.999993896484398
      },
      {
        "t": 1589236877000,
        "v": 14.700006103515648
      },
      {
        "t": 1589237477000,
        "v": 14.999993896484398
      },
[..]
Run Code Online (Sandbox Code Playgroud)

如您所见,这些值包含时间戳和温度测量值。我想通过 Prometheus 指标公开这些测量值,因此我正在使用它prometheus/client_golang来构建一个导出器。

我的期望是/metrics端点然后从上面的数据中暴露出这样的东西:

# HELP my_temperature_celsius Temperature
# TYPE my_temperature_celsius gauge
my_temperature_celsius{id="123456"} 14.999993896484398 1589236277000
my_temperature_celsius{id="123456"} 14.700006103515648 1589236877000
my_temperature_celsius{id="123456"} 14.999993896484398 1589237477000
Run Code Online (Sandbox Code Playgroud)

我实现了一个简单的prometheus.Collector,我添加我的静态指标没有任何问题。对于上面的测量,NewMetricWithTimestamp似乎是添加带有时间戳的指标的唯一方法,因此我使用以下内容迭代这些值:

for _, measurements := range dp.Values {
  ch <- prometheus.NewMetricWithTimestamp(
    time.Unix(measurements.T, 0),
    prometheus.MustNewConstMetric(
      collector.temperature,
      prometheus.GaugeValue,
      float64(measurements.V),
      device.DatapointID))
}
Run Code Online (Sandbox Code Playgroud)

但是,这会导致我不完全理解的以下错误:

An error has …
Run Code Online (Sandbox Code Playgroud)

go prometheus

5
推荐指数
1
解决办法
3632
查看次数

标签 统计

dns ×1

go ×1

haproxy ×1

kubernetes ×1

prometheus ×1