scrape

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RUNNING   = "RUNNING"
	EXCEPTION = "EXCEPTION"
	OPEN      = "OPEN"
	CLOSED    = "CLOSED"
)
View Source
const (
	UseCache = 0
	Reload   = 1
)
View Source
const (
	Bad  = 0
	Good = 1
)
View Source
const TimeLayout = "2006-01-02 15:04:05"

Variables

View Source
var (
	CollectorMap = map[string]Collector{
		"process":   p,
		"namespace": p,
	}
	WrapperFuncMap = map[string]WrapperFunc{
		"process":   NewWrapper,
		"namespace": NewNSWrapper,
	}
)
View Source
var (
	SendMail = make(chan struct{})
)

Functions

func FromPortStateDesc

func FromPortStateDesc(desc string) int64

func FromProcessStateDesc

func FromProcessStateDesc(desc string) int64

func GetBootTime

func GetBootTime(conn *ssh.Connection) (int64, error)

func GetPortStateDesc

func GetPortStateDesc(state int64) string

func GetProcessStateDesc

func GetProcessStateDesc(state int64) string

func GetProcesses

func GetProcesses(w http.ResponseWriter, req *http.Request)

func Init

func Init()

func ProcessHandler

func ProcessHandler(w http.ResponseWriter, req *http.Request)

func RawConnect

func RawConnect(host string, port int64) bool

func Stop

func Stop()

func Suspend

func Suspend(s string) bool

Types

type Alert

type Alert struct {
	URL              string
	IgnoreTimeString []string
	// contains filtered or unexported fields
}

func (*Alert) Chan

func (a *Alert) Chan() chan []byte

func (*Alert) ConvertTime added in v0.1.5

func (a *Alert) ConvertTime(ts []string) error

func (*Alert) PortAlert

func (a *Alert) PortAlert(data []Group)

func (*Alert) ProcessAlert

func (a *Alert) ProcessAlert(data []Group)

func (*Alert) TableDataChanged

func (a *Alert) TableDataChanged(rows render.Rows)

func (*Alert) TableLoadFailed

func (a *Alert) TableLoadFailed(err error)

type Annotations

type Annotations struct {
	Summary     string `json:"summary"`
	Description string `json:"description"`
}

type CachePort

type CachePort struct {
	Number string `json:"number"`
	State  int64  `json:"state"`
}

type CacheProcess

type CacheProcess struct {
	Name      string      `json:"name"`
	Host      string      `json:"host"`
	Path      string      `json:"path"`
	Flag      string      `json:"flag"`
	Ports     []CachePort `json:"ports"`
	State     int64       `json:"state"`
	StartTime string      `json:"start_time"`
	TimeStamp string      `json:"time_stamp"`
	Suspend   bool        `json:"suspend"`
}

func (*CacheProcess) String

func (cp *CacheProcess) String() string

type Collector

type Collector interface {
	// Start 开启后台收集任务
	Start() error
	// Stop 停止收集
	Stop()
	// Refresh 负责手动刷新
	Refresh()
	// Peek Peek返回未加工的数据
	Peek() render.Rows
	Running() bool
	// AddListener 注册数据订阅者
	AddListener(TableListener)
	// RemoveListener 移除订阅者
	RemoveListener(TableListener)
	SendCommand(int64)
}

Collector 收集数据

type Command

type Command struct {
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(t Target, p Process) *Command

func (*Command) GetPID

func (c *Command) GetPID() (string, error)

func (*Command) GetProcessStat

func (c *Command) GetProcessStat() (*ProcessState, error)

type Config

type Config struct {
	Processes []ProcessConfig
}

type Group

type Group struct {
	Name      string          `json:"name"`
	Processes []*CacheProcess `json:"processes"`
}

func (Group) CountNormal

func (g Group) CountNormal() int

func (Group) CountPortException

func (g Group) CountPortException() int

func (Group) CountProcessException

func (g Group) CountProcessException() int

func (Group) CountSuspend

func (g Group) CountSuspend() int

type Instances

type Instances struct {
	sync.RWMutex
	Set map[string]Target
}

func (*Instances) AddConn

func (i *Instances) AddConn(key string, conn *ssh.Connection)

func (*Instances) Clear

func (i *Instances) Clear()

func (*Instances) GetTarget

func (i *Instances) GetTarget(key string) (*Target, bool)

type Labels

type Labels struct {
	AlertName string `json:"alertname"`
	Service   string `json:"service"`
	Severity  string `json:"severity"`
	Instance  string `json:"instance"`
}

type Message

type Message struct {
	Status      string      `json:"status"`
	Labels      Labels      `json:"labels"`
	Annotations Annotations `json:"annotations"`
}

type NSWrapper

type NSWrapper struct {
	serialize.Serializable
	// contains filtered or unexported fields
}

func (NSWrapper) Chan

func (w NSWrapper) Chan() chan []byte

func (NSWrapper) TableDataChanged

func (w NSWrapper) TableDataChanged(data render.Rows)

func (NSWrapper) TableLoadFailed

func (w NSWrapper) TableLoadFailed(err error)

type NameSpace

type NameSpace struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewNameSpace

func NewNameSpace() *NameSpace

func (*NameSpace) Erect

func (n *NameSpace) Erect(rows render.Rows)

func (*NameSpace) Exist

func (n *NameSpace) Exist(ns string) ([]Group, bool)

func (*NameSpace) Flat

func (n *NameSpace) Flat(ns string) [][]string

func (*NameSpace) Groups

func (n *NameSpace) Groups() []Group

func (*NameSpace) SetGroups

func (n *NameSpace) SetGroups(g []Group)

func (*NameSpace) Suck

func (n *NameSpace) Suck(ns string, rows *render.Rows)

type Port

type Port struct {
	Number string
	State  int64
}

type PortState

type PortState struct {
	Process
	States    []*Port
	Timestamp int64
}

type ProcStat

type ProcStat struct {
	// The process ID.
	PID int
	// The filename of the executable.
	Comm string
	// The process state.
	State string
	// The PID of the parent of this process.
	PPID int
	// The process group ID of the process.
	PGRP int
	// The session ID of the process.
	Session int
	// The controlling terminal of the process.
	TTY int
	// The ID of the foreground process group of the controlling terminal of
	// the process.
	TPGID int
	// The kernel flags word of the process.
	Flags uint
	// The number of minor faults the process has made which have not required
	// loading a memory page from disk.
	MinFlt uint
	// The number of minor faults that the process's waited-for children have
	// made.
	CMinFlt uint
	// The number of major faults the process has made which have required
	// loading a memory page from disk.
	MajFlt uint
	// The number of major faults that the process's waited-for children have
	// made.
	CMajFlt uint
	// Amount of time that this process has been scheduled in user mode,
	// measured in clock ticks.
	UTime uint
	// Amount of time that this process has been scheduled in kernel mode,
	// measured in clock ticks.
	STime uint
	// Amount of time that this process's waited-for children have been
	// scheduled in user mode, measured in clock ticks.
	CUTime uint
	// Amount of time that this process's waited-for children have been
	// scheduled in kernel mode, measured in clock ticks.
	CSTime uint
	// For processes running a real-time scheduling policy, this is the negated
	// scheduling priority, minus one.
	Priority int
	// The nice value, a value in the range 19 (low priority) to -20 (high
	// priority).
	Nice int
	// Number of threads in this process.
	NumThreads int
	// The time the process started after system boot, the value is expressed
	// in clock ticks.
	Starttime uint64
	// Virtual memory size in bytes.
	VSize uint
	// Resident set size in pages.
	RSS int
}

ProcStat provides status information about the process, read from /proc/[pid]/stat.

func NewProcStat

func NewProcStat(data []byte) (ProcStat, error)

NewProcStat returns the current status information of the process.

func (ProcStat) StartTime

func (p ProcStat) StartTime(bootTime int64) int64

func (ProcStat) Stat

func (p ProcStat) Stat() string

type Process

type Process struct {
	OSUser  string
	Name    string
	Path    string
	Ports   []int64
	Group   string
	Host    string
	PIDFile string
	Flag    string
	Suspend bool
}

func (*Process) GetConnectionKey

func (p *Process) GetConnectionKey(host string) string

type ProcessCache

type ProcessCache struct {
	// contains filtered or unexported fields
}

func (*ProcessCache) Empty

func (c *ProcessCache) Empty() bool

func (*ProcessCache) FetchPort

func (c *ProcessCache) FetchPort() []*PortState

func (*ProcessCache) FetchPro

func (c *ProcessCache) FetchPro() []*ProcessState

func (*ProcessCache) List

func (c *ProcessCache) List() []Group

func (*ProcessCache) MergeSort

func (c *ProcessCache) MergeSort(pros []*ProcessState, ports []*PortState) []Group

func (*ProcessCache) Render

func (c *ProcessCache) Render() render.Rows

func (*ProcessCache) SyncPort

func (c *ProcessCache) SyncPort(collection []*PortState)

func (*ProcessCache) SyncPro

func (c *ProcessCache) SyncPro(collection []*ProcessState)

type ProcessConfig

type ProcessConfig struct {
	Host    string
	Process []Process
}

type ProcessDetail

type ProcessDetail struct {
	*ProcessCache

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewProcessDetail

func NewProcessDetail() *ProcessDetail

func (*ProcessDetail) AddListener

func (p *ProcessDetail) AddListener(l TableListener)

func (*ProcessDetail) Peek

func (p *ProcessDetail) Peek() render.Rows

func (*ProcessDetail) Peep

func (p *ProcessDetail) Peep(rows render.Rows) render.Rows

func (*ProcessDetail) Refresh

func (p *ProcessDetail) Refresh()

func (*ProcessDetail) RemoveListener

func (p *ProcessDetail) RemoveListener(l TableListener)

func (*ProcessDetail) Running

func (p *ProcessDetail) Running() bool

func (*ProcessDetail) SendCommand

func (p *ProcessDetail) SendCommand(i int64)

func (*ProcessDetail) Start

func (p *ProcessDetail) Start() error

func (*ProcessDetail) Stop

func (p *ProcessDetail) Stop()

type ProcessState

type ProcessState struct {
	Process
	State         int64
	StateDescribe string
	StartTime     int64
	Timestamp     int64
}

func (*ProcessState) Clone added in v0.1.4

func (p *ProcessState) Clone(ps *ProcessState)

type Report

type Report struct {
	Title              string
	ReportName         string
	ReportDate         string
	Reporter           string
	NormalCount        int
	PlanStopCount      int
	PortExceptionCount int
	PIDExceptionCount  int
	Groups             []Group
}

func (*Report) Render

func (r *Report) Render(gps []Group) (string, error)

type Result

type Result struct {
	Status string `json:"status"`
}

type State

type State struct{}

func (*State) Drain

func (s *State) Drain(kind *pb.Kind, stream pb.State_DrainServer) error

func (*State) GetDomain

func (s *State) GetDomain(ctx context.Context, empty *pb.Empty) (*pb.Domain, error)

func (*State) SendCommand

func (s *State) SendCommand(ctx context.Context, command *pb.Command) (*pb.Empty, error)

type TableListener

type TableListener interface {
	// TableDataChanged notifies the model data changed.
	TableDataChanged(rows render.Rows)

	// TableLoadFailed notifies the load failed.
	TableLoadFailed(error)

	Chan() chan []byte
}

func NewNSWrapper

func NewNSWrapper(s serialize.Serializable) TableListener

type Target

type Target struct {
	Conn *ssh.Connection
	// used to compute process start time
	BootTime int64
}

func (Target) Close

func (t Target) Close()

type Wrapper

type Wrapper struct {
	serialize.Serializable
	// contains filtered or unexported fields
}

func (Wrapper) Chan

func (w Wrapper) Chan() chan []byte

func (Wrapper) TableDataChanged

func (w Wrapper) TableDataChanged(data render.Rows)

func (Wrapper) TableLoadFailed

func (w Wrapper) TableLoadFailed(err error)

type WrapperFunc

type WrapperFunc func(serialize.Serializable) TableListener

Jump to

Keyboard shortcuts

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