libsysd

package module
v0.0.0-...-420d70a Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

README

libsysd

A simple wrapper on top go-systemd module to poll or subscribe to systemd events for a list of systemd units / services.


Interface

type Watcher interface {

    // Poll is used for polling all the systemd metrics for a list of systemd services in every n interval.
    Poll(opts ...WatcherOpts)
    // Sub is used for making a subscription to a list of systemd services. This results in a subscription model, where if there is a change in the subscribed systemd service, then it will send to the buffer channel.
    Sub(opts ...WatcherOpts)
}


// Options available for configuration
WatcherOpts struct {
    HostNameMethod string
    PollTimeOut int
    MetricsBufferLimit int
}

// A systemdEvent structure 
SystemdEvent struct {
    Timestamp int64   // Timestamp of when did we receive the event
    PropertyUpdate map[string]interface{} // Property systemd property name:value/systemd property values map  

    UnitName       string                 // UnitName  
    Hostname       string
}

Usage

example/main.go


Documentation

Overview

Package libsysd is a simple wrapper on top of go-systemd module

Index

Constants

This section is empty.

Variables

View Source
var (
	// EventsOut is a channel where systemd events are being pushed
	EventsOut = make(chan *SystemDEvent)

	// ErrCh is a channel where any errors are pushed
	ErrCh = make(chan error)
)

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	ListUnitsByPattern(states, patterns []string) ([]dbus.UnitStatus, error)
	GetPropertiesForUnit(unit string) (map[string]interface{}, error)
	GetPropertiesForAUnitType(unit, unitType string) (map[string]interface{}, error)
	GetPropertyForService(unitName, propertyName string) (*dbus.Property, error)
	RestartService(serviceName string) (*dbus.UnitStatus, error)
	StartService(serviceName string) error
	StopService(serviceName string) error
	ReloadService(serviceName string) error
	SubscribeToUnitProperties(sysEventCh chan *dbus.PropertiesUpdate, errCh chan error) error
	GetVersion() (int, error)
	ReloadDaemon() error
	Close()
}

Adapter implements a systemd adapter

func NewSystemDAdapter

func NewSystemDAdapter() Adapter

NewSystemDAdapter provides a new systemd adapter

type SystemDEvent

type SystemDEvent struct {
	Timestamp      int64                  // Timestamp of when did we receive the event
	PropertyUpdate map[string]interface{} // Property systemd property name:value/systemd property values map
	UnitName       string                 // UnitName of the systemd service
	Hostname       string                 // Hostname of the current machine
}

SystemDEvent represents a single systemd service event

type Watcher

type Watcher interface {
	// Poll method will poll for the systemd properties at a certain interval
	Poll(opts ...WatcherOps)
	// Sub method is an event based method.
	// If and only if there is an event occurred in the systemd managed services these will be captured by this method
	Sub(opts ...WatcherOps)
}

Watcher implements a watch mechanism with poll and sub functions

func New

func New(watcherList []string, opts ...WatcherOps) Watcher

New returns a new watcher

type WatcherOps

type WatcherOps func(*watcher)

WatcherOps sets optional parameters to a watcher

func WithHostNameMethod

func WithHostNameMethod(method string) WatcherOps

WithHostNameMethod sets the hostname method used to get the machine hostname Valid methods are "RFQDN", "FQDN", "OS" and "CMD" Uses: github.com/acceldata-io/goutils/netutils

func WithMetricsBufferLimit

func WithMetricsBufferLimit(limit int64) WatcherOps

WithMetricsBufferLimit set buffer limit for the number of systemd events

func WithPollInterval

func WithPollInterval(interval int64) WatcherOps

WithPollInterval sets poll interval

Jump to

Keyboard shortcuts

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