support

package
v13.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 14 Imported by: 19

Documentation

Overview

Package support provides methods for collecting and printing support information about system.

By default, it collects information about the application and environment:

  • App name
  • App version
  • Go version used for build
  • Binary SHA checksum
  • Git commit SHA checksum

There are also some sub-packages to collect/parse additional information:

  • apps: Extracting apps versions info
  • deps: Extracting dependency information from gomod data
  • pkgs: Collecting information about installed packages
  • services: Collecting information about services
  • fs: Collecting information about the file system
  • network: Collecting information about the network
  • resources: Collecting information about CPU and memory
  • kernel: Collecting information from OS kernel

Example of collecting maximum information about the application and system:

support.Collect("TestApp", "12.3.4").
  WithRevision("fc8d81e").
  WithDeps(deps.Extract(gomodData)).
  WithApps(apps.Golang(), apps.GCC()).
  WithPackages(pkgs.Collect("rpm", "go,golang", "java,jre,jdk", "nano")).
  WithServices(services.Collect("firewalld", "nginx")).
  WithChecks(myAppAvailabilityCheck()).
  WithEnvVars("LANG", "PAGER", "SSH_CLIENT").
  WithNetwork(network.Collect("https://cloudflare.com/cdn-cgi/trace")).
  WithFS(fs.Collect()).
  WithResources(resources.Collect()).
  WithKernel(kernel.Collect("vm.nr_hugepages*", "vm.swappiness")).
  Print()

Also, you can't encode data to JSON/GOB and send it to your server instead of printing it to the console.

info := support.Collect("TestApp", "12.3.4").
  WithRevision("fc8d81e").
  WithDeps(deps.Extract(gomodData)).
  WithApps(apps.Golang(), apps.GCC()).
  WithPackages(pkgs.Collect("rpm", "go,golang", "java,jre,jdk", "nano")).
  WithServices(services.Collect("firewalld", "nginx")).
  WithChecks(myAppAvailabilityCheck()).
  WithEnvVars("LANG", "PAGER", "SSH_CLIENT").
  WithNetwork(network.Collect("https://cloudflare.com/cdn-cgi/trace")).
  WithFS(fs.Collect()).
  WithResources(resources.Collect()).
  WithKernel(kernel.Collect("vm.nr_hugepages*", "vm.swappiness"))

b, _ := json.Marshal(info)

fmt.Println(string(b))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

App contains basic information about app

type BuildInfo

type BuildInfo struct {
	GoVersion string `json:"go_version"`
	GoArch    string `json:"go_arch"`
	GoOS      string `json:"go_os"`
	CGO       bool   `json:"cgo"`

	GitSHA string `json:"git_sha,omitempty"`
	BinSHA string `json:"bin_sha,omitempty"`
}

BuildInfo contains information about binary

type CPUInfo added in v13.5.0

type CPUInfo struct {
	Model   string `json:"model"`
	Threads int    `json:"threads"`
	Cores   int    `json:"cores"`
}

CPUInfo contains info about CPU

type Check

type Check struct {
	Status  CheckStatus `json:"status"`
	Title   string      `json:"title"`
	Message string      `json:"message,omitempty"`
}

Check contains info about custom check

type CheckStatus

type CheckStatus string
const (
	CHECK_OK    CheckStatus = "ok"
	CHECK_ERROR CheckStatus = "error"
	CHECK_WARN  CheckStatus = "warn"
	CHECK_SKIP  CheckStatus = "skip"
)

type Dep

type Dep struct {
	Path    string `json:"path"`
	Version string `json:"version"`
	Extra   string `json:"extra"`
}

Dep contains dependency information

type EnvVar

type EnvVar struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

EnvVar contains information about environment variable

type FSInfo

type FSInfo struct {
	Path   string `json:"path,omitempty"`
	Device string `json:"device,omitempty"`
	Type   string `json:"type,omitempty"`
	Used   uint64 `json:"used,omitempty"`
	Free   uint64 `json:"free,omitempty"`
}

FSInfo contains basic information about file system mount

type Info

type Info struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Binary  string `json:"binary"`

	Build     *BuildInfo     `json:"build,omitempty"`
	OS        *OSInfo        `json:"os,omitempty"`
	System    *SystemInfo    `json:"system,omitempty"`
	Network   *NetworkInfo   `json:"network,omitempty"`
	Resources *ResourcesInfo `json:"resources,omitempty"`
	Kernel    []KernelParam  `json:"kernel,omitempty"`
	FS        []FSInfo       `json:"fs,omitempty"`
	Pkgs      []Pkg          `json:"pkgs,omitempty"`
	Services  []Service      `json:"services,omitempty"`
	Deps      []Dep          `json:"deps,omitempty"`
	Apps      []App          `json:"apps,omitempty"`
	Checks    []Check        `json:"checks,omitempty"`
	Env       []EnvVar       `json:"env,omitempty"`
}

Info contains all support information (can be encoded in JSON/GOB)

func Collect

func Collect(app, ver string) *Info

Collect collects basic info about system

func (*Info) Print

func (i *Info) Print()

Print prints support info

func (*Info) WithApps

func (i *Info) WithApps(apps ...App) *Info

WithPackages adds information about system apps

func (*Info) WithChecks

func (i *Info) WithChecks(check ...Check) *Info

WithChecks adds information custom checks

func (*Info) WithDeps

func (i *Info) WithDeps(deps []Dep) *Info

WithDeps adds information about dependencies

func (*Info) WithEnvVars

func (i *Info) WithEnvVars(vars ...string) *Info

WithEnvVars adds information with environment variables

func (*Info) WithFS

func (i *Info) WithFS(info []FSInfo) *Info

WithFS adds file system information

func (*Info) WithKernel added in v13.5.0

func (i *Info) WithKernel(info []KernelParam) *Info

WithKernel adds kernel parameters info

func (*Info) WithNetwork

func (i *Info) WithNetwork(info *NetworkInfo) *Info

WithNetwork adds information about the network

func (*Info) WithPackages

func (i *Info) WithPackages(pkgs []Pkg) *Info

WithPackages adds information about packages

func (*Info) WithResources added in v13.5.0

func (i *Info) WithResources(info *ResourcesInfo) *Info

WithResources adds system resources information

func (*Info) WithRevision

func (i *Info) WithRevision(rev string) *Info

WithRevision adds git revision

func (*Info) WithServices

func (i *Info) WithServices(services []Service) *Info

WithServices adds information about services

type KernelParam added in v13.5.0

type KernelParam = EnvVar

KernelParam contains info about kernel parameter

type NetworkInfo

type NetworkInfo struct {
	Hostname string   `json:"hostname"`
	PublicIP string   `json:"public_ip,omitempty"`
	IPv4     []string `json:"ipv4"`
	IPv6     []string `json:"ipv6,omitempty"`
}

NetworkInfo contains basic information about network

type OSInfo

type OSInfo struct {
	Name        string `json:"name,omitempty"`
	PrettyName  string `json:"pretty_name,omitempty"`
	Version     string `json:"version,omitempty"`
	Build       string `json:"build,omitempty"`
	ID          string `json:"id,omitempty"`
	IDLike      string `json:"id_like,omitempty"`
	VersionID   string `json:"version_id,omitempty"`
	VersionCode string `json:"version_code,omitempty"`
	PlatformID  string `json:"platform_id,omitempty"`
	CPE         string `json:"cpe,omitempty"`
	// contains filtered or unexported fields
}

OSInfo contains extended information about OS

type Pkg

type Pkg = App

Pkg contains basic information about package

type ResourcesInfo added in v13.5.0

type ResourcesInfo struct {
	CPU       []CPUInfo `json:"cpu"`
	MemTotal  uint64    `json:"mem_total,omitempty"`
	MemFree   uint64    `json:"mem_free,omitempty"`
	MemUsed   uint64    `json:"mem_used,omitempty"`
	SwapTotal uint64    `json:"swap_total,omitempty"`
	SwapFree  uint64    `json:"swap_free,omitempty"`
	SwapUsed  uint64    `json:"swap_used,omitempty"`
}

ResourcesInfo contains information about system resources

type Service

type Service struct {
	Name      string        `json:"name"`
	Status    ServiceStatus `json:"status"`
	IsPresent bool          `json:"is_present"`
	IsEnabled bool          `json:"is_enabled"`
}

Service contains basic info about service

type ServiceStatus

type ServiceStatus string
const (
	STATUS_WORKS   ServiceStatus = "works"
	STATUS_STOPPED ServiceStatus = "stopped"
	STATUS_UNKNOWN ServiceStatus = "unknown"
)

type SystemInfo

type SystemInfo struct {
	Name            string `json:"name"`
	Arch            string `json:"arch"`
	Kernel          string `json:"kernel"`
	ContainerEngine string `json:"container_engine,omitempty"`
}

SystemInfo contains basic information about system

Directories

Path Synopsis
Package apps provides methods for obtaining version information about various tools
Package apps provides methods for obtaining version information about various tools
Package pkgs provides methods for collecting information about used dependencies
Package pkgs provides methods for collecting information about used dependencies
Package pkgs provides methods for collecting information about filesystem
Package pkgs provides methods for collecting information about filesystem
Package kernel provides methods for collecting information from OS kernel
Package kernel provides methods for collecting information from OS kernel
Package network provides methods for collecting information about machine network
Package network provides methods for collecting information about machine network
Package pkgs provides methods for collecting information about installed packages
Package pkgs provides methods for collecting information about installed packages
Package resources provides methods for collecting information about system resources (cpu/memory)
Package resources provides methods for collecting information about system resources (cpu/memory)
Package services provides methods for collecting information about system services
Package services provides methods for collecting information about system services

Jump to

Keyboard shortcuts

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