Show HN:Dish:一个用Go语言编写的轻量级HTTP和TCP套接字监控工具
Show HN: Dish: A lightweight HTTP and TCP socket monitoring tool written in Go

原始链接: https://github.com/thevxn/dish

Dish是一个轻量级、无需依赖的基于Go语言的监控服务,用于快速测试HTTP/S和TCP端点。它使用JSON API进行远程配置,能够实现快速、并发的测试,并将执行时间最小化。Dish默认的套接字超时时间为10秒。 它支持多种故障通知方式,包括更新远程JSON API、发送Telegram消息、更新Prometheus Pushgateway或使用Webhook。 Dish设计为易于通过Docker部署,并提供灵活的命令行标志配置选项,允许您指定套接字定义的来源(本地文件或远程API)、配置Telegram告警、将指标推送到Pushgateway、设置超时时间以及定义自定义头部。提供的示例bash脚本和cronjob展示了自动化部署和定时执行以进行持续监控。Dish提供了一种简单的方法来实现快速简便的套接字级别监控。

Dish是一款轻量级、无依赖的Go语言编写的HTTP和TCP套接字监控工具。它是一个小型二进制可执行文件,可以检查提供的套接字(通过JSON文件或远程API配置),并将结果报告给已配置的通道。 Dish最初是一个学习项目,三年来一直用于监控服务。开发者最近对其进行了重构并开源共享。 支持的报告通道包括Telegram、Prometheus的Pushgateway、Webhook和自定义API端点。你可以在GitHub上找到代码:github.com/thevxn/dish。

原文

PkgGoDev Go Report Card libs.tech recommends

  • tiny one-shot monitoring service
  • remote configuration of independent 'dish network' (via -source ${REMOTE_JSON_API_URL} flag)
  • fast concurrent testing, low overall execution time, 10-sec timeout per socket by default
  • 0 dependencies
go install go.vxn.dev/dish/cmd/dish@latest
dish -h
Usage of dish:
  -failedOnly
        a bool, specifies whether only failed checks should be reported (default true)
  -hname string
        a string, custom additional header name
  -hvalue string
        a string, custom additional header value
  -name string
        a string, dish instance name (default "generic-dish")
  -source string
        a string, path to/URL JSON socket list (default "./configs/demo_sockets.json")
  -target string
        a string, result update path/URL to pushgateway, plaintext/byte output
  -telegramBotToken string
        a string, Telegram bot private token
  -telegramChatID string
        a string, Telegram chat/channel ID
  -timeout uint
        an int, timeout in seconds for http and tcp calls (default 10)
  -updateURL string
        a string, URL of the source api instance
  -verbose
        a bool, console stdout logging toggle
  -webhookURL string
        a string, URL of webhook endpoint

The list of sockets can be provided via a local JSON-formated file (e.g. demo_sockets.json file in the CWD), or via a remote REST/RESTful JSON API.

# local JSON file
dish -source /opt/dish/sockets.json

# remote JSON API source
dish -source http://restapi.example.com/dish/sockets/:instance

When a socket test fails, it's always good to be notified. For this purpose, dish provides 4 different ways of doing so (can be combined):

  • test results upload to a remote JSON API (via -updateURL flag)
  • failed sockets list as the Telegram message body (via Telegram-related flags, see the help output above)
  • failed count and last test timestamp update to Pushgateway for Prometheus (via -pushgw and -target flags)
  • test results push to a webhook URL (via the webhookURL and webhooks flags)

telegram-alerting

(The screenshot above shows the Telegram alerting as of v1.5.0.)

One way to run dish is to build and install a binary executable.

# Fetch and install the specific version
go install go.vxn.dev/dish/cmd/dish@latest

export PATH=$PATH:~/go/bin

# Load sockets from sockets.json file, and use Telegram 
# provider for alerting
dish -source sockets.json -telegram -telegramChatID "-123456789" \
 -telegramBotToken "123:AAAbcD_ef"

# Use remote JSON API service as socket source, and push
# the results to Pushgateway
dish -source https://api.example.com/dish/sockets -pushgw \
 -target https://pushgw.example.com/
# Copy, and/or edit dot-env file (optional)
cp .env.example .env
vi .env

# Build a Docker image
make build

# Run using docker compose stack
make run

# Run using native docker run
docker run --rm \
 dish:1.7.1-go1.23 \
 -verbose \
 -source https://api.example.com \
 -pushgw \
 -target https://pushgateway.example.com

Create a bash script to easily deploy dish and update its settings:

#!/bin/bash

TELEGRAM_TOKEN="123:AAAbcD_ef"
TELEGRAM_CHATID="-123456789"

SOURCE_URL=https://api.example.com/dish/sockets
UPDATE_URL=https://api.example.com/dish/sockets/results
TARGET_URL=https://pushgw.example.com

DISH_TAG=dish:1.6.0-go1.22
INSTANCE_NAME=tiny-dish

SWAPI_TOKEN=AbCd

docker run --rm \
        ${DISH_TAG} \
        -name ${INSTANCE_NAME} \
        -source ${SOURCE_URL} \
        -hvalue ${SWAPI_TOKEN} \
        -hname X-Auth-Token \
        -pushgw \
        -target ${TARGET_URL} \
        -update \
        -updateURL ${UPDATE_URL} \
        -telegram \
        -telegramBotToken ${TELEGRAM_TOKEN} \
        -telegramChatID ${TELEGRAM_CHATID} \
        -timeout 15 \
        -verbose

Make it an executable:

chmod +x tiny-dish-run.sh
Cronjob to run periodically
# m h  dom mon dow   command
[email protected]

*/2 * * * * /home/user/tiny-dish-run.sh

dish history article

The idea of a tiny one-shot service comes with the need for a quick monitoring service implementation to test HTTP/S and generic TCP endpoints (or just sockets in general = hosts and their ports).

联系我们 contact @ memedata.com