From d63317bb793862c7a780bb063b1a466da43114a5 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Mon, 2 May 2022 00:02:15 +0800 Subject: [PATCH] code refactor --- inputs/netresponse/netresponse.go | 10 ++-------- inputs/ntp/alerts.json | 30 ++++++++++++++++++++++++++++++ inputs/ping/alerts.json | 30 ++++++++++++++++++++++++++++++ inputs/ping/dashboard.json | 19 +++++++++++++++++++ 4 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 inputs/ntp/alerts.json create mode 100644 inputs/ping/alerts.json create mode 100644 inputs/ping/dashboard.json diff --git a/inputs/netresponse/netresponse.go b/inputs/netresponse/netresponse.go index fed4cad..b8b7e99 100644 --- a/inputs/netresponse/netresponse.go +++ b/inputs/netresponse/netresponse.go @@ -159,14 +159,7 @@ func (ins *Instance) gather(slist *list.SafeList, target string) { log.Println("D! net_response... target:", target) } - host, port, err := net.SplitHostPort(target) - if err != nil { - // should never happen - log.Println("E! failed to split host port, target:", target, "error:", err) - return - } - - labels := map[string]string{"server": host, "port": port} + labels := map[string]string{"target": target} for k, v := range ins.Labels { labels[k] = v } @@ -180,6 +173,7 @@ func (ins *Instance) gather(slist *list.SafeList, target string) { }() var returnTags map[string]string + var err error switch ins.Protocol { case "tcp": diff --git a/inputs/ntp/alerts.json b/inputs/ntp/alerts.json new file mode 100644 index 0000000..2ab9388 --- /dev/null +++ b/inputs/ntp/alerts.json @@ -0,0 +1,30 @@ +[ + { + "name": "NTP时间偏移太大", + "note": "", + "severity": 2, + "disabled": 0, + "prom_for_duration": 60, + "prom_ql": "ntp_offset_ms > 1000 or ntp_offset_ms < -1000", + "prom_eval_interval": 15, + "enable_stime": "00:00", + "enable_etime": "23:59", + "enable_days_of_week": [ + "1", + "2", + "3", + "4", + "5", + "6", + "0" + ], + "enable_in_bg": 0, + "notify_recovered": 1, + "notify_channels": [], + "notify_repeat_step": 60, + "recover_duration": 0, + "callbacks": [], + "runbook_url": "", + "append_tags": [] + } + ] \ No newline at end of file diff --git a/inputs/ping/alerts.json b/inputs/ping/alerts.json new file mode 100644 index 0000000..85d02d6 --- /dev/null +++ b/inputs/ping/alerts.json @@ -0,0 +1,30 @@ +[ + { + "name": "PING地址探测失败", + "note": "", + "severity": 2, + "disabled": 0, + "prom_for_duration": 60, + "prom_ql": "ping_result_code != 0", + "prom_eval_interval": 15, + "enable_stime": "00:00", + "enable_etime": "23:59", + "enable_days_of_week": [ + "1", + "2", + "3", + "4", + "5", + "6", + "0" + ], + "enable_in_bg": 0, + "notify_recovered": 1, + "notify_channels": [], + "notify_repeat_step": 60, + "recover_duration": 0, + "callbacks": [], + "runbook_url": "", + "append_tags": [] + } + ] \ No newline at end of file diff --git a/inputs/ping/dashboard.json b/inputs/ping/dashboard.json new file mode 100644 index 0000000..4c09be0 --- /dev/null +++ b/inputs/ping/dashboard.json @@ -0,0 +1,19 @@ +[ + { + "name": "PING探测", + "tags": "", + "configs": "", + "chart_groups": [ + { + "name": "Default chart group", + "weight": 0, + "charts": [ + { + "configs": "{\"targets\":[{\"refId\":\"A\",\"expr\":\"max(ping_result_code) by (target)\",\"legend\":\"UP?\"},{\"expr\":\"max(ping_percent_packet_loss) by (target)\",\"refId\":\"B\",\"legend\":\"Packet Loss %\"},{\"expr\":\"max(httpresponse_response_time) by (target)\",\"refId\":\"C\",\"legend\":\"latency(s)\"}],\"name\":\"Ping\",\"custom\":{\"showHeader\":true,\"calc\":\"lastNotNull\",\"displayMode\":\"labelValuesToRows\",\"aggrDimension\":\"target\"},\"options\":{\"valueMappings\":[],\"standardOptions\":{}},\"overrides\":[{\"properties\":{\"valueMappings\":[{\"type\":\"special\",\"match\":{\"special\":0},\"result\":{\"text\":\"UP\",\"color\":\"#417505\"}},{\"type\":\"range\",\"match\":{\"special\":1,\"from\":1},\"result\":{\"text\":\"DOWN\",\"color\":\"#e90f0f\"}}],\"standardOptions\":{}},\"matcher\":{\"value\":\"A\"}}],\"version\":\"2.0.0\",\"type\":\"table\",\"layout\":{\"h\":4,\"w\":24,\"x\":0,\"y\":0,\"i\":\"0\"}}", + "weight": 0 + } + ] + } + ] + } + ] \ No newline at end of file