cagent

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

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 53 Imported by: 0

README

How to build from sources

go get -d -u github.com/4S7xfPcbp1Hfayz/cagent
go build -o cagent -ldflags="-X github.com/4S7xfPcbp1Hfayz/cagent.Version=$(git --git-dir=$GOPATH/src/github.com/4S7xfPcbp1Hfayz/cagent/.git describe --always --long --dirty --tag)" github.com/4S7xfPcbp1Hfayz/cagent/cmd/cagent

How to run

-r for one run only mode

./cagent -r -o result.out

Configuration

Check the example config

Default locations:

  • Mac OS: ~/.cagent/cagent.conf
  • Windows: ./cagent.conf
  • UNIX: /etc/cagent/cagent.conf

Logs location

  • Mac OS: ~/.cagent/cagent.log
  • Windows: ./cagent.log
  • UNIX: /var/log/cagent/cagent.log

Build binaries and deb/rpm packages

– Install goreleaser

make goreleaser-snapshot

Build MSI package

Should be done on Windows machine

  • Download go-msi and put it in the C:\Program Files\go-msi
  • Open command prompt(cmd.exe or powershell)
  • Go to cagent directory cd path_to_directory
  • Run make goreleaser-snapshot to build binaries
  • Run build-win.bat

Versioning model

Cagent uses <major>.<minor>.<buildnumber> version pattern for compatibility with a maximum number of package managers.

Starting from version 1.4.0 packages with even <minor> number are considered stable.

S.M.A.R.T monitoring documentation

S.M.A.R.T how to

Documentation

Index

Constants

View Source
const (
	IOModeFile = "file"
	IOModeHTTP = "http"

	OperationModeFull      = "full"
	OperationModeMinimal   = "minimal"
	OperationModeHeartbeat = "heartbeat"
)

Variables

View Source
var (
	Version            string
	LicenseInfo        = "released under MIT license. https://github.com/4S7xfPcbp1Hfayz/cagent/"
	SelfUpdatesFeedURL = "https://repo.cloudradar.io/windows/cagent/feed/rolling"
)

variables set on build. Example: go build -o cagent -ldflags="-X github.com/4S7xfPcbp1Hfayz/cagent.Version=$(git --git-dir=src/github.com/4S7xfPcbp1Hfayz/cagent/.git describe --always --long --dirty --tag)" github.com/4S7xfPcbp1Hfayz/cagent/cmd/cagent

View Source
var (
	// 429 error
	ErrHubTooManyRequests = errors.New("Hub replied with a 429 error code")

	// 5xx error code
	ErrHubServerError = errors.New("Hub replied with a 5xx error code")

	// 401 error code
	ErrHubUnauthorized = errors.New("Hub replied with a 401 error code")
)
View Source
var DefaultCfgPath string

Functions

func GenerateDefaultConfigFile

func GenerateDefaultConfigFile(mvc *MinValuableConfig, configFilePath string) error

func SaveConfigFile

func SaveConfigFile(cfg interface{}, configFilePath string) error

func TryUpdateConfigFromFile

func TryUpdateConfigFromFile(cfg *Config, configFilePath string) error

TryUpdateConfigFromFile applies values from file in configFilePath to cfg if given file exists. it rewrites all cfg keys that present in the file

func Uname

func Uname() (string, error)

Types

type CPUUtilisationAnalyser

type CPUUtilisationAnalyser struct {
	NumberOfProcesses int
	// contains filtered or unexported fields
}

func (*CPUUtilisationAnalyser) Results

type CPUUtilisationAnalysisConfig

type CPUUtilisationAnalysisConfig struct {
	Threshold                      float64 `toml:"threshold" comment:"target value to start the analysis" json:"threshold"`
	Function                       string  `toml:"function" comment:"threshold compare function, possible values: 'lt', 'lte', 'gt', 'gte'" json:"function"`
	Metric                         string  `toml:"metric" commend:"possible values: 'user','system','idle','iowait'" json:"metric"`
	GatheringMode                  string  `toml:"gathering_mode" comment:"should be one of values of cpu_utilisation_gathering_mode" json:"gathering_mode"`
	ReportProcesses                int     `toml:"report_processes" comment:"number of processes to return" json:"report_processes"`
	TrailingProcessAnalysisMinutes int     `` /* 193-byte string literal not displayed */
}

type CPUWatcher

type CPUWatcher struct {
	LoadAvg1  bool
	LoadAvg5  bool
	LoadAvg15 bool

	UtilAvg   TimeSeriesAverage
	UtilTypes []string

	ThresholdNotifiers []thresholdNotifier
}

func (*CPUWatcher) AddThresholdNotifier

func (cw *CPUWatcher) AddThresholdNotifier(percentage float64, metric string, operator string, gatheringMode string, ch chan float64) error

func (*CPUWatcher) Once

func (cw *CPUWatcher) Once() error

func (*CPUWatcher) Results

func (cw *CPUWatcher) Results() (common.MeasurementsMap, error)

func (*CPUWatcher) Run

func (cw *CPUWatcher) Run()

type Cagent

type Cagent struct {
	Config         *Config
	ConfigLocation string
	// contains filtered or unexported fields
}

func New

func New(cfg *Config, cfgPath string) (*Cagent, error)

func (*Cagent) CPUUtilisationAnalyser

func (ca *Cagent) CPUUtilisationAnalyser() *CPUUtilisationAnalyser

func (*Cagent) CPUWatcher

func (ca *Cagent) CPUWatcher() *CPUWatcher

func (*Cagent) CheckHubCredentials

func (ca *Cagent) CheckHubCredentials(ctx context.Context, fieldHubURL, fieldHubUser, fieldHubPassword string) error

CheckHubCredentials performs credentials check for a Hub config, returning errors that reference field names as in source config. Since config may be filled from file or UI, the field names can be different. Consider also localization of UI, we want to decouple credential checking logic from their actual view in UI.

Examples: * for TOML: CheckHubCredentials(ctx, "hub_url", "hub_user", "hub_password") * for WinUI: CheckHubCredentials(ctx, "URL", "User", "Password")

func (*Cagent) GetFileSystemWatcher

func (ca *Cagent) GetFileSystemWatcher() *fs.FileSystemWatcher

func (*Cagent) GetNetworkWatcher

func (ca *Cagent) GetNetworkWatcher() *networking.NetWatcher

func (*Cagent) HostInfoResults

func (ca *Cagent) HostInfoResults() (common.MeasurementsMap, error)

func (*Cagent) MemResults

func (ca *Cagent) MemResults() (common.MeasurementsMap, *mem.VirtualMemoryStat, error)

func (*Cagent) PortsResult

func (ca *Cagent) PortsResult(processList []*processes.ProcStat) (common.MeasurementsMap, error)

PortsResult lists all active connections

func (*Cagent) PostResultToHub

func (ca *Cagent) PostResultToHub(ctx context.Context, result *Result) error

func (*Cagent) Run

func (ca *Cagent) Run(outputFile *os.File, interrupt chan struct{})

func (*Cagent) RunHeartbeat

func (ca *Cagent) RunHeartbeat(interrupt chan struct{})

func (*Cagent) RunOnce

func (ca *Cagent) RunOnce(outputFile *os.File, fullMode bool) error

func (*Cagent) SetLogLevel

func (ca *Cagent) SetLogLevel(lvl LogLevel)

Sets Log level and corresponding logrus level

func (*Cagent) Shutdown

func (ca *Cagent) Shutdown()

func (*Cagent) SwapResults

func (ca *Cagent) SwapResults() (common.MeasurementsMap, error)

type Cleaner

type Cleaner interface {
	Cleanup() error
}

type Config

type Config struct {
	OperationMode     string  `` /* 405-byte string literal not displayed */
	Interval          float64 `toml:"interval" comment:"interval to push metrics to the HUB"`
	HeartbeatInterval float64 `toml:"heartbeat" comment:"send a heartbeat without metrics to the HUB every X seconds"`
	Sleep             float64 `toml:"sleep" comment:"sleep duration after failed communication with the HUB"`

	PidFile   string `toml:"pid" comment:"pid file location"`
	LogFile   string `toml:"log,omitempty" required:"false" comment:"log file location"`
	LogSyslog string `toml:"log_syslog" comment:"\"local\" for local unix socket or URL e.g. \"udp://localhost:514\" for remote syslog server"`

	MinValuableConfig

	HubGzip           bool   `toml:"hub_gzip" comment:"enable gzip when sending results to the HUB"`
	HubRequestTimeout int    `` /* 200-byte string literal not displayed */
	HubProxy          string `toml:"hub_proxy" commented:"true"`
	HubProxyUser      string `toml:"hub_proxy_user" commented:"true"`
	HubProxyPassword  string `toml:"hub_proxy_password" commented:"true"`

	CPULoadDataGather []string `toml:"cpu_load_data_gathering_mode" comment:"default ['avg1']"`
	CPUUtilDataGather []string `toml:"cpu_utilisation_gathering_mode" comment:"default ['avg1']"`
	CPUUtilTypes      []string `toml:"cpu_utilisation_types" comment:"default ['user','system','idle','iowait']"`

	FSTypeInclude                 []string `toml:"fs_type_include" comment:"default ['ext3','ext4','xfs','jfs','ntfs','btrfs','hfs','apfs','fat32','smbfs','nfs']"`
	FSPathExclude                 []string `toml:"fs_path_exclude" comment:"Exclude file systems by name, disabled by default"`
	FSPathExcludeRecurse          bool     `` /* 268-byte string literal not displayed */
	FSMetrics                     []string `` /* 166-byte string literal not displayed */
	FSIdentifyMountpointsByDevice bool     `` /* 303-byte string literal not displayed */

	NetInterfaceExclude             []string `toml:"net_interface_exclude" commented:"true"`
	NetInterfaceExcludeRegex        []string `` /* 180-byte string literal not displayed */
	NetInterfaceExcludeDisconnected bool     `toml:"net_interface_exclude_disconnected" comment:"default true"`
	NetInterfaceExcludeLoopback     bool     `toml:"net_interface_exclude_loopback" comment:"default true"`

	NetMetrics           []string `toml:"net_metrics" comment:"default ['in_B_per_s','out_B_per_s','total_out_B_per_s','total_in_B_per_s']"`
	NetInterfaceMaxSpeed string   `` /* 535-byte string literal not displayed */

	SystemFields []string `toml:"system_fields" comment:"default ['uname','os_kernel','os_family','os_arch','cpu_model','fqdn','memory_total_B']"`

	VirtualMachinesStat []string `toml:"virtual_machines_stat" comment:"default ['hyper-v'], available options 'hyper-v'"`

	HardwareInventory bool `toml:"hardware_inventory" comment:"default true"`

	DiscoverAutostartingServicesOnly bool `toml:"discover_autostarting_services_only" comment:"default true"`

	CPUUtilisationAnalysis CPUUtilisationAnalysisConfig `toml:"cpu_utilisation_analysis"`

	TemperatureMonitoring bool `toml:"temperature_monitoring" comment:"default true"`

	SoftwareRAIDMonitoring bool `` /* 149-byte string literal not displayed */

	SMARTMonitoring bool            `toml:"smart_monitoring" comment:"Enable S.M.A.R.T monitoring of hard disks\ndefault false"`
	SMARTCtl        string          `` /* 330-byte string literal not displayed */
	Logs            LogsFilesConfig `toml:"logs,omitempty"`

	StorCLI StorCLIConfig `` /* 358-byte string literal not displayed */

	JobMonitoring JobMonitoringConfig `toml:"jobmon,omitempty" comment:"Settings for the jobmon wrapper for the job monitoring"`

	SystemUpdatesChecks UpdatesMonitoringConfig `` /* 318-byte string literal not displayed */

	MysqlMonitoring mysql.Config `` /* 192-byte string literal not displayed */

	ProcessMonitoring processes.Config `` /* 238-byte string literal not displayed */

	Updates UpdatesConfig `toml:"self_update" comment:"Control how cagent installs self-updates. Windows-only"`

	DockerMonitoring DockerMonitoringConfig `` /* 172-byte string literal not displayed */

	MemMonitoring bool `` /* 258-byte string literal not displayed */

	CPUMonitoring bool `toml:"cpu_monitoring" comment:"Turn on/off any CPU related monitoring including the cpu_utilisation_analysis"`

	FSMonitoring bool `toml:"fs_monitoring" comment:"Turn on/off any disk- and filesystem-related monitoring like fill levels and iops"`

	NetMonitoring bool `toml:"net_monitoring" comment:"Turn on/off any network-related monitoring"`

	OnHTTP5xxRetries       int     `toml:"on_http_5xx_retries" comment:"Number of retries if server replies with a 5xx code"`
	OnHTTP5xxRetryInterval float64 `toml:"on_http_5xx_retry_interval" comment:"Interval in seconds between retries to contact server in case of a 5xx code"`
}

func HandleAllConfigSetup

func HandleAllConfigSetup(configFilePath string) (*Config, error)

HandleAllConfigSetup prepares Config for Cagent with parameters specified in file if Config file does not exist default one is created in form of MinValuableConfig

func NewConfig

func NewConfig() *Config

func (*Config) DumpToml

func (cfg *Config) DumpToml() string

func (*Config) GetParsedNetInterfaceMaxSpeed

func (cfg *Config) GetParsedNetInterfaceMaxSpeed() (uint64, error)

type ConfigDeprecated

type ConfigDeprecated struct {
	WindowsUpdatesWatcherInterval int `toml:"windows_updates_watcher_interval" comment:""`
}

type DockerMonitoringConfig

type DockerMonitoringConfig struct {
	Enabled bool `toml:"enabled" comment:"Set 'false' to disable docker monitoring'"`
}

type JobMonitoringConfig

type JobMonitoringConfig struct {
	SpoolDirPath string          `toml:"spool_dir" comment:"Path to spool dir"`
	RecordStdErr bool            `toml:"record_stderr" comment:"Record the last 4 KB of the error output. Default: true"`
	RecordStdOut bool            `toml:"record_stdout" comment:"Record the last 4 KB of the standard output. Default: false"`
	Severity     jobmon.Severity `toml:"severity" comment:"Failed jobs will be processed as alerts. Possible values alert, warning or none. Default: alert"`
}

func (*JobMonitoringConfig) Validate

func (j *JobMonitoringConfig) Validate() error

type LogLevel

type LogLevel string
const (
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelError LogLevel = "error"
)

func (LogLevel) IsValid

func (lvl LogLevel) IsValid() bool

func (LogLevel) LogrusLevel

func (lvl LogLevel) LogrusLevel() logrus.Level

type LogsFilesConfig

type LogsFilesConfig struct {
	HubFile string `toml:"hub_file,omitempty" comment:"log hub objects send to the hub"`
}

type MinValuableConfig

type MinValuableConfig struct {
	LogLevel    LogLevel `toml:"log_level" comment:"\"debug\", \"info\", \"error\" verbose level; can be overridden with -v flag"`
	IOMode      string   `toml:"io_mode" commented:"true"`
	OutFile     string   `` /* 188-byte string literal not displayed */
	HubURL      string   `toml:"hub_url" commented:"true"`
	HubUser     string   `toml:"hub_user" commented:"true"`
	HubPassword string   `toml:"hub_password" commented:"true"`
}

func NewMinimumConfig

func NewMinimumConfig() *MinValuableConfig

type PortStat

type PortStat struct {
	Protocol     string `json:"proto"`
	LocalAddress string `json:"addr"`
	PID          int32  `json:"pid,omitempty"`
	ProgramName  string `json:"program,omitempty"`
}

type Result

type Result struct {
	Timestamp    int64                  `json:"timestamp"`
	Measurements common.MeasurementsMap `json:"measurements"`
	Message      interface{}            `json:"message"`
}

type StorCLIConfig

type StorCLIConfig struct {
	BinaryPath string `` /* 158-byte string literal not displayed */
}

type TimeSeriesAverage

type TimeSeriesAverage struct {
	TimeSeries []TimeValue
	// contains filtered or unexported fields
}

func (*TimeSeriesAverage) Add

func (tsa *TimeSeriesAverage) Add(t time.Time, valuesMap ValuesMap)

func (*TimeSeriesAverage) Average

func (tsa *TimeSeriesAverage) Average() map[int]ValuesMap

func (*TimeSeriesAverage) Percentage

func (tsa *TimeSeriesAverage) Percentage() (map[int]ValuesMap, error)

func (*TimeSeriesAverage) SetDurationsMinutes

func (tsa *TimeSeriesAverage) SetDurationsMinutes(durations ...int)

type TimeValue

type TimeValue struct {
	Time   time.Time
	Values ValuesMap
}

type TimeoutError

type TimeoutError struct {
	Origin  string
	Timeout time.Duration
}

func (TimeoutError) Error

func (err TimeoutError) Error() string

type UpdatesConfig

type UpdatesConfig struct {
	Enabled       bool   `toml:"enabled" comment:"Set 'false' to disable self-updates"`
	URL           string `toml:"url" comment:"URL for updates feed"`
	CheckInterval uint32 `toml:"check_interval" comment:"Cagent will check for new versions every N seconds"`
}

func (*UpdatesConfig) GetCheckInterval

func (u *UpdatesConfig) GetCheckInterval() time.Duration

func (*UpdatesConfig) Validate

func (u *UpdatesConfig) Validate() error

type UpdatesMonitoringConfig

type UpdatesMonitoringConfig struct {
	Enabled       bool   `toml:"enabled" comment:"Set 'false' to disable checking available updates"`
	FetchTimeout  uint32 `` /* 130-byte string literal not displayed */
	CheckInterval uint32 `toml:"check_interval" comment:"Check for available updates every N seconds. Minimum is 300 seconds"`
}

func (*UpdatesMonitoringConfig) Validate

func (l *UpdatesMonitoringConfig) Validate() error

type ValuesCount

type ValuesCount map[string]int

type ValuesMap

type ValuesMap map[string]float64

Jump to

Keyboard shortcuts

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