parse_service_list

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: MIT Imports: 3 Imported by: 0

README

Fedora / Redhat Systemd Service List processor.

This is a module that can extract the running services and their status from

systemctl list-units 

or

ps -eo pid,user,ni,%cpu,%mem,args --sort=-%cpu,-%mem

into data structures.

To use, add as a module:
$ go get -u github.com/lechuhuuha/parse-service-list

Sample Application in the parse-service-list_test.go

Output

[
{"pid":1546,"user":"root","ni":0,"cpu":0.5,"mem":1.7,"command":"/root/go/bin/gopls"},{"pid":1489,"user":"root","ni":0,"cpu":0.3,"mem":2,"command":"/root/.vscode-server/bin/74f6148eb9ea00507ec113ec51c489d6ffb4b771/node"},{"pid":502,"user":"root","ni":0,"cpu":0.1,"mem":0.9,"command":"/snap/ubuntu-desktop-installer/1151/usr/bin/python3.10"},{"pid":1419,"user":"root","ni":0,"cpu":0.1,"mem":0.8,"command":"/root/.vscode-server/bin/74f6148eb9ea00507ec113ec51c489d6ffb4b771/node"}
]
[
{"serviceName":"apport.service","loaded":"loaded","state":"active","status":"exited","description":"LSB: automatic crash report generation"},{"serviceName":"console-getty.service","loaded":"loaded","state":"active","status":"running","description":"Console Getty"},{"serviceName":"console-setup.service","loaded":"loaded","state":"active","status":"exited","description":"Set console font and keymap"},{"serviceName":"cron.service","loaded":"loaded","state":"active","status":"running","description":"Regular background program processing daemon"}

]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskUsages added in v0.1.1

type DiskUsages struct {
	Source string `json:"source"`
	Target string `json:"target"`
	Perc   string `json:"pcent"`
	Used   string `json:"used"`
	Total  string `json:"itotal"`
}

func ParseDiskUsage added in v0.1.1

func ParseDiskUsage(output []byte) ([]DiskUsages, error)

type ProcessStatusItems

type ProcessStatusItems struct {
	PID     int     `json:"pid"`
	User    string  `json:"user"`
	Nice    int     `json:"ni"`
	CPU     float64 `json:"cpu"`
	Memory  float64 `json:"mem"`
	Command string  `json:"command"`
}

func ParsePSOutput

func ParsePSOutput(bytestream []byte) ([]ProcessStatusItems, error)

type SystemdItems

type SystemdItems struct {
	Name        string `json:"serviceName"`
	Loaded      string `json:"loaded"`
	State       string `json:"state"`
	Status      string `json:"status"`
	Description string `json:"description"`
}

func ParseSystemdOutput

func ParseSystemdOutput(bytestream []byte) ([]SystemdItems, error)

Jump to

Keyboard shortcuts

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