v0.10.4 Latest Latest

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

Go to latest
Published: Nov 28, 2021 License: BSD-3-Clause, MIT Imports: 14 Imported by: 0




This section is empty.


This section is empty.


func Kill

func Kill(pid int) error

Kill kills process pid


type DayLimits added in v0.10.1

type DayLimits map[string]time.Duration

DayLimits maps days to time limit The key (days) can be - "*" (meaing 'any day of the week') - space separated string of three-letter abbreviations of the days of week, i.e. Mon Tue Wed Thu Fri Sat Sun - a concreate date in the format YYYY-MM-DD - space separated list of dates - a combination of all of the above

func (DayLimits) MarshalJSON added in v0.10.1

func (dtl DayLimits) MarshalJSON() ([]byte, error)

MarshalJSON marshals dtl using 12h35m46s duration format

func (*DayLimits) UnmarshalJSON added in v0.10.1

func (dtl *DayLimits) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals dtl, lowercasing the key and using 12h35m46s duration format

type Downtime added in v0.10.1

type Downtime map[string][]string

Downtime maps days to a list of downtime periods See DayLimits for the meaning of the key of this map The values (downtime periods) are strings like this: "12:00..12:30" - for a 30 minutes downtime "..10:00" - downtime up until 10:00 in the morning "18:00.." - downtime after 6:00PM

type ProcessGroupDayBalance added in v0.10.1

type ProcessGroupDayBalance struct {
	PG           []string       `json:"processes"`
	Limit        prettyDuration `json:"limit"`
	LimitDefined bool           `json:"limit_defined"`
	Balance      prettyDuration `json:"balance"`
	Downtime     []string       `json:"downtime"`
	Blocked      bool           `json:"blocked"`
	TimeStamp    string         `json:"timestamp"`

ProcessGroupDayBalance describes day limits and monitored properties of a process group PG

type ProcessGroupDayLimit added in v0.10.1

type ProcessGroupDayLimit struct {
	PG []string  `json:"processes"`
	DL DayLimits `json:"limits"`
	DT Downtime  `json:"downtime"`

ProcessGroupDayLimit specifies day time limit DL and downtime periods DT for one or more processes in PG

type ProcessHunter

type ProcessHunter struct {
	// contains filtered or unexported fields

func NewProcessHunter

func NewProcessHunter(
	checkPeriod time.Duration,
	balancePath string,
	savePeriod time.Duration,
	killer func(int) error,
	cfgPath string) *ProcessHunter

NewProcessHunter initializes and returns a new ProcessHunter

func (*ProcessHunter) GetBalance added in v0.10.4

func (ph *ProcessHunter) GetBalance() dayTimeBalance

GetBalance returns balance

func (*ProcessHunter) GetLatestPGroupsBalance added in v0.6.0

func (ph *ProcessHunter) GetLatestPGroupsBalance() []ProcessGroupDayBalance

GetLatestPGroupsBalance returns pgroups

func (*ProcessHunter) GetLatestProcessesBalance added in v0.6.0

func (ph *ProcessHunter) GetLatestProcessesBalance() TimeBalance

GetLatestProcessesBalance returns processes

func (*ProcessHunter) GetLimits

func (ph *ProcessHunter) GetLimits() ([]ProcessGroupDayLimit, uint32)

GetLimits returns current day limits (which are normally loaded from a config file) and its hash

func (*ProcessHunter) LoadBalance

func (ph *ProcessHunter) LoadBalance() error

LoadBalance loads the balance from provided path

func (*ProcessHunter) LoadConfig

func (ph *ProcessHunter) LoadConfig() error

LoadConfig loads ProcessHunder configuration from path

func (*ProcessHunter) Run

func (ph *ProcessHunter) Run(ctx context.Context, wg *sync.WaitGroup)

Run is a goroutine that periodically checks running processes

func (*ProcessHunter) SaveBalance

func (ph *ProcessHunter) SaveBalance() error

SaveBalance saves balance in a thread-safe way

func (*ProcessHunter) SetConfig added in v0.9.1

func (ph *ProcessHunter) SetConfig(b []byte) error

SetConfig sets configuration b (represented as json) and saves it to the ph.cfgPath if ph.cfgPath is "", then the call succeeds without saving config file if ph.cfgPath cannot be written, the call fails and new config is not set.

type TimeBalance added in v0.6.0

type TimeBalance map[string]time.Duration

TimeBalance maps process name to running time

func (TimeBalance) MarshalJSON added in v0.6.0

func (tb TimeBalance) MarshalJSON() ([]byte, error)

MarshalJSON marshals tb using 12h35m46s duration format

func (*TimeBalance) UnmarshalJSON added in v0.6.0

func (tb *TimeBalance) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals dtl using 12h35m46s duration format

Jump to

Keyboard shortcuts

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