monitor

package module
v0.0.0-...-a19abee Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 18 Imported by: 0

README

monitor

Build Status | codecov | Go Report Card | GoDoc

A simple and centralized process monitor

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

With support for

  • Get process(es)
  • Create process
  • Update process
  • Update process status , Delete process(es)

Dependecy Management

Dep

Project dependencies are managed using Dep. Read more about Dep.

  • Install dependencies: dep ensure
  • Update dependencies: dep ensure -update
Go
go get github.com/joaosoft/monitor

Usage

This examples are available in the project at monitor/examples

import "github.com/joaosoft/monitor"

func main() {
	m, err := monitor.NewMonitor()
	if err != nil {
		panic(err)
	}

	if err := m.Start(); err != nil {
		panic(err)
	}
}

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeString

func EncodeString(s string) string

func Exists

func Exists(file string) bool

func GetEnv

func GetEnv() string

func ReadFile

func ReadFile(file string, obj interface{}) ([]byte, error)

func ReadFileLines

func ReadFileLines(file string) ([]string, error)

func WriteFile

func WriteFile(file string, obj interface{}) error

Types

type AppConfig

type AppConfig struct {
	Monitor *MonitorConfig `json:"monitor"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type Controller

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

func (*Controller) CreateProcessHandler

func (controller *Controller) CreateProcessHandler(ctx *web.Context) error

func (*Controller) DeleteProcessHandler

func (controller *Controller) DeleteProcessHandler(ctx *web.Context) error

func (*Controller) DeleteProcessesHandler

func (controller *Controller) DeleteProcessesHandler(ctx *web.Context) error

func (*Controller) DoNothing

func (controller *Controller) DoNothing(ctx *web.Context) error

func (*Controller) GetProcessHandler

func (controller *Controller) GetProcessHandler(ctx *web.Context) error

func (*Controller) GetProcessesHandler

func (controller *Controller) GetProcessesHandler(ctx *web.Context) error

func (*Controller) RegisterRoutes

func (controller *Controller) RegisterRoutes(w manager.IWeb) error

func (*Controller) UpdateProcessHandler

func (controller *Controller) UpdateProcessHandler(ctx *web.Context) error

func (*Controller) UpdateProcessStatusCheckHandler

func (controller *Controller) UpdateProcessStatusCheckHandler(ctx *web.Context) error

func (*Controller) UpdateProcessStatusHandler

func (controller *Controller) UpdateProcessStatusHandler(ctx *web.Context) error

type CreateProcessRequest

type CreateProcessRequest struct {
	Body struct {
		IdProcess   string         `json:"id_process" validate:"notzero"`
		Type        string         `json:"type" validate:"notzero"`
		Name        string         `json:"name" validate:"notzero"`
		Description string         `json:"description"`
		DateFrom    *types.Date    `json:"date_from" validate:"special={date}"`
		DateTo      *types.Date    `json:"date_to" validate:"special={date}"`
		TimeFrom    *types.Time    `json:"time_from" validate:"special={time}"`
		TimeTo      *types.Time    `json:"time_to" validate:"special={time}"`
		DaysOff     *types.ListDay `json:"days_off" validate:"options=monday;tuesday;wednesday;thursday;friday;saturday;sunday"`
		Monitor     string         `json:"monitor"`
		Status      *Status        `json:"status" validate:"options=stopped;running"`
	}
}

type DeleteProcessRequest

type DeleteProcessRequest struct {
	IdProcess string `json:"id_process" validate:"notzero"`
}

type ErrorResponse

type ErrorResponse struct {
	Code    web.Status `json:"code,omitempty"`
	Message string     `json:"message,omitempty"`
	Cause   string     `json:"cause,omitempty"`
}

type GetProcessRequest

type GetProcessRequest struct {
	IdProcess string `json:"id" validate:"notzero"`
}

type IStorageDB

type IStorageDB interface {
	GetProcess(idProcess string) (*Process, error)
	GetProcesses(values map[string][]string) (ListProcess, error)
	CreateProcess(newProcess *Process) error
	UpdateProcess(updProcess *Process) error
	UpdateProcessStatus(idProcess string, status Status) error
	DeleteProcess(idProcess string) error
	DeleteProcesses() error
}

type Interactor

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

func (*Interactor) CanExecute

func (interactor *Interactor) CanExecute(idProcess string) (bool, errors.ErrorList)

func (*Interactor) CreateProcess

func (interactor *Interactor) CreateProcess(newProcess *Process) error

func (*Interactor) DeleteProcess

func (interactor *Interactor) DeleteProcess(idProcess string) error

func (*Interactor) DeleteProcesses

func (interactor *Interactor) DeleteProcesses() error

func (*Interactor) GetProcess

func (interactor *Interactor) GetProcess(idProcess string) (*Process, error)

func (*Interactor) GetProcesses

func (interactor *Interactor) GetProcesses(values map[string][]string) (ListProcess, error)

func (*Interactor) UpdateProcess

func (interactor *Interactor) UpdateProcess(updProcess *Process) error

func (*Interactor) UpdateProcessStatus

func (interactor *Interactor) UpdateProcessStatus(idProcess string, status Status) errors.ErrorList

func (*Interactor) UpdateProcessStatusCheck

func (interactor *Interactor) UpdateProcessStatusCheck(idProcess string, status Status) errors.ErrorList

type ListProcess

type ListProcess []*Process

type Monitor

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

func NewMonitor

func NewMonitor(options ...MonitorOption) (*Monitor, error)

NewMonitor ...

func (*Monitor) NewController

func (monitor *Monitor) NewController(interactor *Interactor) *Controller

func (*Monitor) NewInteractor

func (monitor *Monitor) NewInteractor(storageDB IStorageDB) *Interactor

func (*Monitor) NewStoragePostgres

func (monitor *Monitor) NewStoragePostgres(connection manager.IDB) *StoragePostgres

func (*Monitor) Reconfigure

func (monitor *Monitor) Reconfigure(options ...MonitorOption)

Reconfigure ...

func (*Monitor) Start

func (m *Monitor) Start() error

Start ...

func (*Monitor) Stop

func (m *Monitor) Stop() error

Stop ...

type MonitorConfig

type MonitorConfig struct {
	Host      string                     `json:"host"`
	Db        manager.DBConfig           `json:"db"`
	Migration *migration.MigrationConfig `json:"migration"`
	Log       struct {
		Level string `json:"level"`
	} `json:"log"`
}

MonitorConfig ...

type MonitorOption

type MonitorOption func(client *Monitor)

MonitorOption ...

func WithConfiguration

func WithConfiguration(config *MonitorConfig) MonitorOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) MonitorOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) MonitorOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) MonitorOption

WithManager ...

type Process

type Process struct {
	IdProcess   string         `json:"id_process"`
	Name        string         `json:"name"`
	Type        string         `json:"type"`
	Description string         `json:"description"`
	DateFrom    *types.Date    `json:"date_from"`
	DateTo      *types.Date    `json:"date_to"`
	TimeFrom    *types.Time    `json:"time_from"`
	TimeTo      *types.Time    `json:"time_to"`
	DaysOff     *types.ListDay `json:"days_off"`
	Monitor     string         `json:"monitor"`
	Status      *Status        `json:"status"`
	UpdatedAt   time.Time      `json:"updated_at"`
	CreatedAt   time.Time      `json:"created_at"`
}

type Status

type Status string
const (
	DefaultURL = "http://localhost:8001"

	StatusStopped Status = "stopped"
	StatusRunning Status = "running"
)

func (*Status) Scan

func (s *Status) Scan(src interface{}) error

func (Status) Value

func (s Status) Value() (driver.Value, error)

type StoragePostgres

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

func (*StoragePostgres) CreateProcess

func (storage *StoragePostgres) CreateProcess(newProcess *Process) error

func (*StoragePostgres) DeleteProcess

func (storage *StoragePostgres) DeleteProcess(idProcess string) error

func (*StoragePostgres) DeleteProcesses

func (storage *StoragePostgres) DeleteProcesses() error

func (*StoragePostgres) GetProcess

func (storage *StoragePostgres) GetProcess(idProcess string) (*Process, error)

func (*StoragePostgres) GetProcesses

func (storage *StoragePostgres) GetProcesses(values map[string][]string) (ListProcess, error)

func (*StoragePostgres) UpdateProcess

func (storage *StoragePostgres) UpdateProcess(updProcess *Process) error

func (*StoragePostgres) UpdateProcessStatus

func (storage *StoragePostgres) UpdateProcessStatus(idProcess string, status Status) error

type UpdateProcessRequest

type UpdateProcessRequest struct {
	IdProcess string `json:"id_process" validate:"notzero"`

	Body struct {
		Type        string         `json:"type" validate:"notzero"`
		Name        string         `json:"name" validate:"notzero"`
		Description string         `json:"description"`
		DateFrom    *types.Date    `json:"date_from" validate:"special={date}"`
		DateTo      *types.Date    `json:"date_to" validate:"special={date}"`
		TimeFrom    *types.Time    `json:"time_from" validate:"special={time}"`
		TimeTo      *types.Time    `json:"time_to" validate:"special={time}"`
		DaysOff     *types.ListDay `json:"days_off" validate:"options=monday;tuesday;wednesday;thursday;friday;saturday;sunday"`
		Monitor     string         `json:"monitor"`
		Status      *Status        `json:"status" validate:"options=stopped;running"`
	}
}

type UpdateProcessStatusRequest

type UpdateProcessStatusRequest struct {
	IdProcess string `json:"id_process" validate:"notzero"`
	Status    Status `json:"status" validate:"options=stopped;running"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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