apps

package
v0.0.0-...-17a5fe9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlertLevelInfo    = "info"
	AlertLevelDebug   = "debug"
	AlertLevelWarning = "warning"
	AlertLevelError   = "error"
)
View Source
const (
	LogTypeNormal = "normal"
	LogTypeAccess = "access"
	LogTypeError  = "error"
)

日志类型

View Source
const (
	LogFormatPlain = "plain"
	LogFormatXML   = "xml"  // @TODO 暂不支持
	LogFormatGzip  = "gzip" // @TODO 暂不支持
	LogFormatJSON  = "json" // @TODO 暂不支持
	LogFormatSQL   = "sql"  // @TODO 暂不支持
)

日志文件格式

Variables

This section is empty.

Functions

func Exec

func Exec(command string, arg ...string) (string, error)

func ParseArgs

func ParseArgs(s string) (args []string)

分析字符串中的参数

Types

type AlertLevel

type AlertLevel = string

监控级别

type AlertTarget

type AlertTarget interface {
	SetOptions(options map[string]interface{}) error // 设置选项
	Send(message string) error                       // 发送消息
}

报警发送目标

type App

type App struct {
	Id        string // 唯一ID,通常系统会自动生成
	Name      string
	Developer string
	Site      string
	DocSite   string
	Version   string
	Icon      []byte

	Cmdline string

	Processes  []*Process    // 进程列表
	Operations []*Operation  // TODO
	Monitors   []*Monitor    // TODO
	Statistics []*Statistics // TODO
	Logs       []*Log        // TODO

	IsRunning bool
	// contains filtered or unexported fields
}

App定义

func (*App) AddAllProcess

func (this *App) AddAllProcess(process ...*Process)

添加进程,包括子进程

func (*App) AddProcess

func (this *App) AddProcess(process ...*Process)

添加进程,不包括子进程

func (*App) OnReload

func (this *App) OnReload(f func() error)

设置reload回调

func (*App) OnStop

func (this *App) OnStop(f func() error)

设置进程停止时回调

func (*App) Reload

func (this *App) Reload() error

刷新App

func (*App) ResetProcesses

func (this *App) ResetProcesses()

重置进程

type AppInterface

type AppInterface interface {
	Start() error
	Stop() error
}

接口

type CPUUsage

type CPUUsage struct {
	Percent float64 // CPU占用比例,是一个小数,比如 0.215
}

CPU占用

type Event

type Event struct {
	Type string
}

事件

type Listen

type Listen struct {
	Network string
	Addr    string
}

type Log

type Log struct {
	Id     string    // 唯一ID,通常系统会自动生成
	Name   string    // 日志名
	Path   string    // 文件路径
	Type   LogType   // 类型
	Format LogFormat // 文件格式
}

日志定义

type LogFormat

type LogFormat = string

type LogType

type LogType = string

type LsofResult

type LsofResult struct {
	Command         string
	Pid             int32
	User            string
	Fd              string
	Type            string
	Protocol        string
	Name            string
	ConnectionState string
}

func Lsof

func Lsof(pid int32) (results []*LsofResult, err error)

func (*LsofResult) IsCwd

func (this *LsofResult) IsCwd() bool

func (*LsofResult) IsEstablished

func (this *LsofResult) IsEstablished() bool

func (*LsofResult) IsIPv4

func (this *LsofResult) IsIPv4() bool

func (*LsofResult) IsIPv6

func (this *LsofResult) IsIPv6() bool

func (*LsofResult) IsListening

func (this *LsofResult) IsListening() bool

func (*LsofResult) IsRegularFile

func (this *LsofResult) IsRegularFile() bool

func (*LsofResult) IsTCP

func (this *LsofResult) IsTCP() bool

func (*LsofResult) LAddr

func (this *LsofResult) LAddr() string

func (*LsofResult) Listen

func (this *LsofResult) Listen() string

func (*LsofResult) RAddr

func (this *LsofResult) RAddr() string

type MemoryUsage

type MemoryUsage struct {
	RSS     uint64  // RSS
	VMS     uint64  // VMS
	Percent float64 // 百分比
}

内存使用

type Monitor

type Monitor struct {
	ProcessPids []uint32  // 监控的进程PID
	Files       []string  // 监控的文件
	EventTypes  []string  // 监控的事件
	Sockets     []*Socket // 监控的Socket端口
	URLs        []string  // 监控的URL
	PingHosts   []string  // 通过ICMP监控
	Scripts     []string  // 监控脚本

	Timeout  float64 // 超时时间,单位为秒
	Interval float64 // 间隔时间
	MaxFails uint32  // 最大失败次数,在达到此失败次数后才会报警

	Level AlertLevel // 级别

	Targets []*AlertTarget // 报警发送目标
}

监控设置

type Operation

type Operation struct {
	Id            string // 唯一ID,通常系统会自动生成
	Code          string // 代号
	Name          string // 名称
	IsEnabled     bool   // 是否启用
	ShouldConfirm bool   // 操作是否确认
	ConfirmText   string // 操作确认文字
	// contains filtered or unexported fields
}

对App的操作定义

func (*Operation) OnRun

func (this *Operation) OnRun(f func() error)

设置运行时回调函数

func (*Operation) Run

func (this *Operation) Run() error

运行此操作

type Process

type Process struct {
	Name string
	Pid  int32
	Ppid int32
	Cwd  string

	User string
	Uid  int32
	Gid  int32

	CreateTime  int64 // 时间戳
	Cmdline     string
	File        string // 命令行文件路径
	Dir         string // 命令行文件所在目录
	CPUUsage    *CPUUsage
	MemoryUsage *MemoryUsage

	OpenFiles   []string
	Connections []string
	Listens     []*Listen

	IsRunning bool
}

func NewProcess

func NewProcess(pid int32) *Process

func PsChildren

func PsChildren(parentPid int32) (result []*Process, err error)

func PsLookup

func PsLookup(lookup string, matchPatterns []string, onlyParent bool) (result []*Process, err error)

func PsPid

func PsPid(pid int32) (*Process, error)

func (*Process) ChangeName

func (this *Process) ChangeName(newName string)

修改命令的名称

func (*Process) Reload

func (this *Process) Reload() error

刷新状态

func (*Process) StatOpenFiles

func (this *Process) StatOpenFiles()

open files, connections, ...

type Socket

type Socket struct {
	Network string
	Address string
}

Socket定义

type Statistics

type Statistics struct {
}

统计 TODO

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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