teaagents

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT, MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProcessEventStart  = "start"
	ProcessEventStdout = "stdout"
	ProcessEventStderr = "stderr"
	ProcessEventStop   = "stop"
)

Variables

View Source
var HTTPClient = &http.Client{
	Timeout: 60 * time.Second,
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
		MaxIdleConnsPerHost: 5,
	},
}

公用的HTTP客户端

View Source
var LongHTTPClient = &http.Client{
	Timeout: 300 * time.Second,
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
		MaxIdleConnsPerHost: 5,
	},
}

长时间的HTTP客户端

Functions

func PushEvent

func PushEvent(event EventInterface)

func Start

func Start()

启动

Types

type App

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

func NewApp

func NewApp(config *agents.AppConfig) *App

type EventInterface

type EventInterface interface {
	AsJSON() (data []byte, err error)
}

type Item

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

监控项定义

func NewItem

func NewItem(appId string, config *agents.Item) *Item

获取新任务

func (*Item) Run

func (this *Item) Run() (value interface{}, err error)

运行一次

func (*Item) Schedule

func (this *Item) Schedule()

定时运行

func (*Item) Stop

func (this *Item) Stop()

停止运行

type ItemEvent

type ItemEvent struct {
	Event     string      `json:"event"`
	AgentId   string      `json:"agentId"`
	AppId     string      `json:"appId"`
	ItemId    string      `json:"itemId"`
	Value     interface{} `json:"value"`
	Error     string      `json:"error"`
	BeginAt   int64       `json:"beginAt"`
	Timestamp int64       `json:"timestamp"`
	CostMs    float64     `json:"costMs"`
}

监控项事件

func NewItemEvent

func NewItemEvent(agentId string, appId string, itemId string, value interface{}, err error, beginAt int64, costMs float64) *ItemEvent

获取新监控项事件

func (*ItemEvent) AsJSON

func (this *ItemEvent) AsJSON() ([]byte, error)

转换为JSON

type Process

type Process struct {
	UniqueId string
	Pid      int

	Env  []*shared.Variable
	Cwd  string
	File string
	// contains filtered or unexported fields
}

func NewProcess

func NewProcess() *Process

获取新进程

func (*Process) Kill

func (this *Process) Kill() error

Kill进程

func (*Process) OnStart

func (this *Process) OnStart(f func())

on start

func (*Process) OnStop

func (this *Process) OnStop(f func())

on stop

func (*Process) Run

func (this *Process) Run() (stdout string, stderr string, err error)

立即运行

func (*Process) RunWriter

func (this *Process) RunWriter(stdout io.Writer, stderr io.Writer) (err error)

使用自定义stdout, stderr运行

type ProcessEvent

type ProcessEvent struct {
	Event     string           `json:"event"`
	AgentId   string           `json:"agentId"`
	AppId     string           `json:"appId"`
	TaskId    string           `json:"taskId"`
	UniqueId  string           `json:"uniqueId"`
	Pid       int              `json:"pid"`
	EventType ProcessEventType `json:"eventType"`
	Data      string           `json:"data"`
	Timestamp int64            `json:"timestamp"`
}

进程日志

func NewProcessEvent

func NewProcessEvent(eventType ProcessEventType, appId string, taskId string, uniqueId string, pid int, data []byte) *ProcessEvent

新日志对象

func (*ProcessEvent) AsJSON

func (this *ProcessEvent) AsJSON() ([]byte, error)

转换为JSON

type ProcessEventType

type ProcessEventType = string

日志类型

type Server

type Server struct {
	Addr string
	// contains filtered or unexported fields
}

Agent提供的Web Server,可以用来读取状态、进行控制等

func NewServer

func NewServer() *Server

获取新服务对象

func (*Server) Shutdown

func (this *Server) Shutdown()

关闭

func (*Server) Start

func (this *Server) Start() error

启动

type StderrLogWriter

type StderrLogWriter struct {
	AppId    string
	TaskId   string
	UniqueId string
	Pid      int
}

func (*StderrLogWriter) Write

func (this *StderrLogWriter) Write(p []byte) (n int, err error)

type StdoutLogWriter

type StdoutLogWriter struct {
	AppId    string
	TaskId   string
	UniqueId string
	Pid      int
}

日志写入器

func (*StdoutLogWriter) Write

func (this *StdoutLogWriter) Write(p []byte) (n int, err error)

type Task

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

任务定义

func NewTask

func NewTask(appId string, config *agents.TaskConfig) *Task

获取新任务

func (*Task) IsRunning

func (this *Task) IsRunning() bool

是否正在运行

func (*Task) Run

func (this *Task) Run() (proc *Process, stdout string, stderr string, err error)

立即运行

func (*Task) RunLog

func (this *Task) RunLog() (err error)

运行并向Master发送日志

func (*Task) Schedule

func (this *Task) Schedule(fromTimer ...bool)

定时运行

func (*Task) ShouldBoot

func (this *Task) ShouldBoot() bool

是否应该启动

func (*Task) Stop

func (this *Task) Stop() error

停止

Jump to

Keyboard shortcuts

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