status

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 3 Imported by: 12

README

gin-status-api

A system status monitoring API handler for the Gin framework that provides CPU, memory, garbage collection, and other runtime information for your Go applications.

GoDoc Run Tests Trivy Security Scan Go Report Card codecov

Table of Contents

Features

  • Simple Integration: Add system monitoring with just one line of code
  • Comprehensive Metrics: Provides complete runtime information including CPU, memory, and GC stats
  • JSON Format: Easy to integrate with monitoring systems and dashboards
  • Lightweight: Minimal performance impact on your application
  • Multiple Use Cases: Perfect for health checks, performance monitoring, debugging, and alerting

Installation

Download and install the package using go get:

go get github.com/appleboy/gin-status-api

Quick Start

Basic Usage

Import the package and register a route in your Gin application:

package main

import (
    status "github.com/appleboy/gin-status-api"
    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.New()

    // Register the status API endpoint
    r.GET("/api/status", status.GinHandler)

    // Start the server
    r.Run() // Listen and serve on 0.0.0.0:8080
}
Running the Example

The project includes a complete example that you can run:

cd _example
go run server.go

Then access the status endpoint using curl or your browser:

curl http://localhost:8080/api/status

API Response

The API returns a JSON object containing comprehensive system status information:

Field Description
time Current Unix timestamp
go_version Go runtime version
go_os Operating system
go_arch System architecture
cpu_num Number of CPU cores
goroutine_num Current number of goroutines
gomaxprocs GOMAXPROCS setting
cgo_call_num Number of CGO calls
memory_alloc Bytes of allocated heap objects
memory_total_alloc Cumulative bytes allocated for heap objects
memory_sys Total bytes of memory obtained from the OS
memory_lookups Number of pointer lookups performed
memory_mallocs Cumulative count of heap objects allocated
memory_frees Cumulative count of heap objects freed
memory_stack Bytes in stack spans
heap_alloc Bytes of allocated heap objects (same as memory_alloc)
heap_sys Bytes of heap memory obtained from the OS
heap_idle Bytes in idle (unused) spans
heap_inuse Bytes in in-use spans
heap_released Bytes of physical memory returned to the OS
heap_objects Number of allocated heap objects
gc_next Target heap size for next GC cycle
gc_last Time of last garbage collection
gc_num Number of completed GC cycles
gc_per_second GC cycles per second
gc_pause_per_second Average GC pause time per second
gc_pause Circular buffer of recent GC pause times

For more detailed information about these metrics, please refer to the golang-stats-api-handler documentation.

Response Example

response screenshot

Use Cases

  • Health Checks: Integrate with Kubernetes liveness/readiness probes
  • Performance Monitoring: Track memory usage and GC behavior over time
  • Debugging: Quickly inspect goroutine counts and resource usage
  • Alerting Systems: Set up alerts based on memory thresholds or goroutine counts
  • DevOps Dashboards: Feed metrics into Grafana, Prometheus, or other monitoring tools
  • Capacity Planning: Analyze application resource consumption patterns

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for bugs, feature requests, or questions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GinHandler added in v1.1.0

func GinHandler(c *gin.Context)

GinHandler is gin handle for get system status.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL