Operations 9 min read

Boost Go Service Reliability with the Lightweight go-monitor Tool

The article presents go-monitor, an open‑source Go library that provides lightweight, lock‑free service quality monitoring, automatic analysis, configurable alerts, and flexible reporting for backend applications, complete with installation steps and code examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Go Service Reliability with the Lightweight go-monitor Tool

This article introduces the open‑source Go monitoring project go-monitor, a lightweight tool built with Go for service quality monitoring and alert analysis.

What can go-monitor do?

By reporting interface names, durations, and success status, go-monitor automatically analyzes service quality at configurable intervals, generates detailed reports, and triggers alerts when performance degrades, followed by recovery notifications when the service returns to normal.

The library offers extensive configuration options, uses a lock‑free queue to avoid concurrency bottlenecks (benchmark: 5 million reports processed in 1.6 s), and can be embedded in any Go project just like a logging component.

Usage

Installation
go get github.com/blurooo/go-monitor
Import and Register

After importing, call Register to obtain a reporting client, then use its Report method to submit latency metrics.

import (
    "github.com/blurooo/go-monitor"
    "time"
)

var httpReportClient = monitor.Register(monitor.ReportClientConfig{
    Name: "http service monitor",
    StatisticalCycle: 100, // statistics every 100 ms
})

func main() {
    t := time.NewTicker(10 * time.Millisecond)
    for curTime := range t.C {
        // report a request taking 0‑100 ms with status 200
        httpReportClient.Report("GET - /app/api/users", uint32(curTime.Nanosecond()%100), 200)
    }
}

Reports are output to the console by default, but a custom OutputCaller can direct them to logs, files, or databases.

var httpReportClient = monitor.Register(monitor.ReportClientConfig{
    Name: "http service monitor",
    StatisticalCycle: 100,
    OutputCaller: func(o *monitor.OutPutData) {
        // custom handling, e.g., write to DB
    },
})

Multiple instances are supported, allowing separate monitors for HTTP services, function latency, etc.

var httpReportClient = monitor.Register(monitor.ReportClientConfig{ Name: "http service monitor" })
var funcReportClient = monitor.Register(monitor.ReportClientConfig{ Name: "function latency monitor" })

Alerting can be customized via a whitelist CodeFeatureMap or a dynamic GetCodeFeature function to define success criteria and names for status codes.

var httpReportClient = monitor.Register(monitor.ReportClientConfig{
    Name: "http service monitor",
    CodeFeatureMap: map[int]monitor.CodeFeature{
        0: {Success: true, Name: "Success"},
        10000: {Success: false, Name: "Service Unavailable"},
    },
})

When success rates fall below thresholds, go-monitor raises alerts with detailed data; a RecoverCaller can handle recovery notifications.

var httpReportClient = monitor.Register(monitor.ReportClientConfig{
    Name: "http service monitor",
    AlertCaller: func(clientName, interfaceName string, alertType monitor.AlertType, recent []monitor.OutPutData) {
        // handle alert
    },
    RecoverCaller: func(clientName, interfaceName string, alertType monitor.AlertType, recent []monitor.OutPutData) {
        // handle recovery
    },
})

Additional configuration options allow setting default latency thresholds and per‑entry fast‑time limits.

var httpReportClient = monitor.Register(monitor.ReportClientConfig{
    Name: "http service monitor",
    DefaultFastTime: 1000, // 1 s
})
httpReportClient.AddEntryConfig("GET - /app/api/users", monitor.EntryConfig{FastLessThan: 100})

The project welcomes contributions and aims to evolve into a standalone service supporting front‑ and back‑end reporting, database output, email alerts, and more. Repository: https://github.com/blurooo/go-monitor

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringperformanceGolangAlertingservice-quality
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.