healthcheck

package module
v0.0.0-...-c39ede9 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 11 Imported by: 0

README

Server Health Check

English | 한국어

English

A Go library for checking server status and reporting to Slack.

Requirements

  • Linux operating system (required)
  • sshpass command (for server access)
  • curl command (for Slack message delivery)

Installation

go get github.com/SundaePorkCutlet/healthCheck

Basic Usage

package main
import (
"fmt"
"github.com/SundaePorkCutlet/healthCheck/healthcheck"
)
func main() {
// Create config with default settings
config := healthcheck.NewDefaultConfig()
// Set Slack Webhook URL
config.SlackWebhookURL = "https://hooks.slack.com/services/YOUR_WEBHOOK_URL"
// Add servers to monitor
config.AddServer("10.1.0.170", "user", "password", []string{"nginx", "prometheus"})
// Run health check
report := config.RunCheck()
fmt.Println("Health check completed!")
}

Advanced Features

Process Type Management
// Set default processes for different server types
config.AddProcessType("web", []string{"nginx", "prometheus"})
config.AddProcessType("app", []string{"api-server", "auth-service"})
Custom Commands and Thresholds
// Add custom commands
config.AddCommand("Docker Status", "systemctl status docker | grep Active")
// Set custom thresholds
config.SetThreshold("CPU Idle", 15.0) // Warning if CPU idle is below 15%
config.SetThreshold("Memory Used", 90.0) // Warning if memory usage exceeds 90%
config.SetThreshold("Disk Used", 95.0) // Warning if disk usage exceeds 95%
Process Monitoring Examples
// Add specific processes to monitor for a server
config.AddServer("10.1.0.170", "user", "password", 
    []string{"nginx", "prometheus", "api-server"}, // specific processes
    "")  // empty type

// Use predefined process type
config.AddProcessType("web-server", []string{"nginx", "prometheus"})
config.AddServer("10.1.0.171", "user", "password", 
    []string{}, // empty process list
    "web-server") // use predefined type

// Combine both approaches
config.AddProcessType("base", []string{"prometheus", "node-exporter"})
config.AddServer("10.1.0.172", "user", "password",
    []string{"custom-service", "api-gateway"}, // additional processes
    "base") // also monitor base processes
Process Monitoring Examples
// Add specific processes to monitor for a server
config.AddServer("10.1.0.170", "user", "password", 
    []string{"nginx", "prometheus", "api-server"}, // specific processes
    "")  // empty type

// Use predefined process type
config.AddProcessType("web-server", []string{"nginx", "prometheus"})
config.AddServer("10.1.0.171", "user", "password", 
    []string{}, // empty process list
    "web-server") // use predefined type

// Combine both approaches
config.AddProcessType("base", []string{"prometheus", "node-exporter"})
config.AddServer("10.1.0.172", "user", "password",
    []string{"custom-service", "api-gateway"}, // additional processes
    "base") // also monitor base processes

Features

  • Customizable process monitoring per server
  • Default process lists by server type
  • Custom command execution
  • Adjustable warning thresholds
  • System metrics monitoring:
    • CPU usage
    • Memory usage
    • Disk usage
    • Network connectivity
    • Process status
  • Slack integration for reporting

Korean

서버 상태를 확인하고 Slack으로 보고하는 Go 라이브러리입니다.

요구사항

  • Linux 운영체제 (필수)
  • sshpass 명령어 (서버 접속용)
  • curl 명령어 (Slack 메시지 전송용)

설치

go get github.com/SundaePorkCutlet/healthCheck

기본 사용법

package main
import (
"fmt"
"github.com/SundaePorkCutlet/healthCheck/healthcheck"
)
func main() {
// 기본 설정으로 Config 생성
config := healthcheck.NewDefaultConfig()
// Slack Webhook URL 설정
config.SlackWebhookURL = "https://hooks.slack.com/services/YOUR_WEBHOOK_URL"
// 서버 추가
config.AddServer("10.1.0.170", "user", "password", []string{"nginx", "prometheus"})
// 헬스 체크 실행
report := config.RunCheck()
fmt.Println("Health check completed!")
}

고급 기능

프로세스 타입 관리
// 서버 유형별 기본 프로세스 목록 설정
config.AddProcessType("web", []string{"nginx", "prometheus"})
config.AddProcessType("app", []string{"api-server", "auth-service"})
사용자 정의 명령어 및 임계값
// 사용자 정의 명령어 추가
config.AddCommand("Docker Status", "systemctl status docker | grep Active")
// 임계값 설정
config.SetThreshold("CPU Idle", 15.0) // CPU 사용률이 15% 이하일 때 경고
config.SetThreshold("Memory Used", 90.0) // 메모리 사용률이 90% 이상일 때 경고
config.SetThreshold("Disk Used", 95.0) // 디스크 사용률이 95% 이상일 때 경고
프로세스 모니터링 예제
// 서버에 대해 특정 프로세스 모니터링 추가
config.AddServer("10.1.0.170", "user", "password", 
    []string{"nginx", "prometheus", "api-server"}, // 특정 프로세스 목록
    "")  // 빈 타입

// 미리 정의된 프로세스 타입 사용
config.AddProcessType("web-server", []string{"nginx", "prometheus"})
config.AddServer("10.1.0.171", "user", "password", 
    []string{}, // 빈 프로세스 목록
    "web-server") // 미리 정의된 타입 사용

// 두 방식 조합
config.AddProcessType("base", []string{"prometheus", "node-exporter"})
config.AddServer("10.1.0.172", "user", "password",
    []string{"custom-service", "api-gateway"}, // 추가 프로세스
    "base") // 기본 프로세스도 함께 모니터링

기능

  • 서버별 프로세스 모니터링 커스터마이징
  • 서버 유형별 기본 프로세스 목록 설정
  • 커스텀 명령어 실행
  • 경고 임계값 조정
  • 시스템 메트릭 모니터링:
    • CPU 사용량
    • 메모리 사용량
    • 디스크 사용량
    • 네트워크 연결 상태
    • 프로세스 상태
  • Slack 연동 보고

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Servers         []ServerConfig      // List of servers to monitor
	SlackWebhookURL string              // Slack webhook URL
	ProcessMap      map[string][]string // Default process list by server type
	Commands        map[string]string   // List of commands to execute
	Thresholds      map[string]float64  // Warning thresholds
}

Config holds health check configuration

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a Config with default settings

func (*Config) AddCommand

func (c *Config) AddCommand(name, command string)

AddCommand adds a new command or modifies an existing one

func (*Config) AddProcessType

func (c *Config) AddProcessType(typeName string, processes []string)

AddProcessType adds a process list for a server type

func (*Config) AddServer

func (c *Config) AddServer(ip, username, password string, processes []string, serverType string)

AddServer adds a new server to the configuration

func (*Config) RunCheck

func (c *Config) RunCheck() string

RunCheck checks the status of all servers and returns the result

func (*Config) SetThreshold

func (c *Config) SetThreshold(name string, value float64)

SetThreshold sets a warning threshold

type ServerConfig

type ServerConfig struct {
	IP        string   // Server IP or hostname
	Username  string   // SSH username
	Password  string   // SSH password
	Processes []string // List of processes to monitor
	Type      string   // Server type (used for default process selection)
}

ServerConfig holds configuration for individual server

Directories

Path Synopsis
cmd
example command

Jump to

Keyboard shortcuts

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