psutilsql

package module
v0.0.5 Latest Latest
Warning

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

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

README

psutilsql

PkgGoDev

CLI tool that can be processed by SQL using gopsutil library.

SQL input/output is handled by trdsql. Therefore, CSV, JSON, LTSV, MarkDown, Raw, Vertical, and TBLN can be selected as the output format.

psutilsql.gif

install

go get -u github.com/noborus/psutilsql...

psutilsql depends on go-sqlite3. Therefore, gcc is required to build.

Usage

psutilsql command
SQL

The query command(<query> can be omitted) can execute SQL.

$ psutilsql query "SELECT Total,Used,Free FROM virtualmemory"
or     
$ psutilsql "SELECT Total,Used,Free FROM virtualmemory"       

+-------------+------------+------------+
|    Total    |    Used    |    Free    |
+-------------+------------+------------+
| 16687091712 | 6468083712 | 2399399936 |
+-------------+------------+------------+
Table list

List of table names that can be used.

Displayed with the following command:

psutilsql table
name
cpuinfo
cpupercent
cputime
diskpartition
diskusage
docker
hostinfo
hosttemperature
hostuser
loadavg
loadmisc
net
process
processex
swapmemory
virtualmemory
Command

Display values using command and options without using SQL.

$ psutilsql host --users
+---------+----------+------+------------+
|  User   | Terminal | Host |  Started   |
+---------+----------+------+------------+
| noborus | tty7     | :0   | 1564096509 |
+---------+----------+------+------------+
$ psutilsql --help
SQL for running processes and system utilization.

SQL can be executed on the information acquired using gopsutil library.
Default SQL is provided, so you can omit SQL if you select a command.

Usage:
  psutilsql [flags]
  psutilsql [command]

Available Commands:
  completion  Generates bash/zsh completion scripts
  cpu         CPU information
  disk        DISK information
  docker      docker information
  help        Help about any command
  host        host information
  load        load information
  mem         memory information
  net         net information
  process     process information
  query       SQL query command
  table       table list

Flags:
  -d, --Delimiter string   output delimiter (CSV only) (default ",")
  -O, --Header             output header (CSV only)
  -o, --OutFormat string   output format=at|csv|ltsv|json|tbln|raw|md|vf (default "at")
  -q, --Query string       query
  -h, --help               help for psutilsql
  -t, --toggle             Help message for toggle

Use "psutilsql [command] --help" for more information about a command.
cpu

--time: cpu time(default)

CPU User System Idle Nice Iowait Irq Softirq Steal Guest GuestNice

--info, -i: cpu info

CPU VendorID Family Model Stepping PhysicalID CoreID Cores ModelName Mhz CacheSize Flags Microcode

--percent,-p: cpu percent

disk

--partition: disk partition(default)

Device Mountpoint Fstype Opts

--usage [disk]: disk usage

Path Fstype Total Free Used UsedPercent InodesTotal InodesUsed InodesFree InodesUsedPercent
docker
ContainerID Name Image Status Running
host

--info: host information(default)

Hostname Uptime BootTime Procs OS Platform PlatformFamily PlatformVersion KernelVersion VirtualizationSystem VirtualizationRole HostID

--user,-u: user information

User Terminal Host Started

--temperatures, -t: SensorsTemperatures

SensorKey Temperature
load
Load1 Load5 Load15

--misc,-m: miscellaneous host-wide statistics

ProcsTotal ProcsRunning ProcsBlocked Ctxt
mem

VirtualMemory(default)

Total Available Used UsedPercent Free Active Inactive Wired Laundry Buffers Cached Writeback Dirty WritebackTmp Shared Slab SReclaimable SUnreclaim PageTables SwapCached CommitLimit CommittedAS HighTotal HighFree LowTotal LowFree SwapTotal SwapFree Mapped VMallocTotal VMallocUsed VMallocChunk HugePagesTotal HugePagesFree HugePageSize

--swap, -s: SwapMemory

Total Used Free UsedPercent Sin Sout PgIn PgOut PgFault
net
Fd Family Type LaddrIP LaddrPort RaddrIP RaddrPort status Uids Pid
process
pid name CPU MEM STATUS START USER RSS VMS Data Stack locked Swap COMMAND

--ex: memory info ex

pid name CPU MEM STATUS START USER RSS VMS Shared Text Lib Data Dirty COMMAND

Documentation

Overview

Package psutilsql execute SQL queries on system information.

psutilsql can process gopsutil results in SQL and output them in various formats.

Index

Constants

View Source
const (
	PID pColumnNum = iota
	NAME
	CPU
	MEM
	STATUS
	START
	USER
	CWD
	EXE
	TERMINAL
	IONICE
	NICE
	NUMFDS
	NUMTHREADS
	PPID
	TGID
	UIDS
	GIDS
	MEMORYINFOEX
	MEMORYINFO
	IOCOUNTERS
	FOREGROUND
	BACKGROUND
	ISRUNNING
	COMMAND
)

Variables

View Source
var (
	ErrNotSupport  = errors.New("not support")
	ErrNoSuchTable = errors.New("no such table")
)

Functions

func CPUInfoQuery

func CPUInfoQuery(query string, w trdsql.Writer) error

CPUInfoQuery executes SQL on cpu.Info.

func CPUInfoReader

func CPUInfoReader() (*trdsql.SliceReader, error)

CPUInfoReader returns cpu.Info result as trdsql.SliceReader.

func CPUPercentQuery

func CPUPercentQuery(total bool, query string, w trdsql.Writer) error

CPUPercentQuery executes SQL on cpu.Percent.

func CPUPercentReader

func CPUPercentReader(total bool) (*trdsql.SliceReader, error)

CPUPercentReader returns cpu.Percent result as trdsql.SliceReader.

func CPUTimeQuery

func CPUTimeQuery(total bool, query string, w trdsql.Writer) error

CPUTimeQuery executes SQL on cpu.Time.

func CPUTimeReader

func CPUTimeReader(total bool) (*trdsql.SliceReader, error)

CPUTimeReader returns cpu.Times result as trdsql.SliceReader.

func DiskPartitionQuery

func DiskPartitionQuery(all bool, query string, w trdsql.Writer) error

DiskPartitionQuery executes SQL on disk.Partitions.

func DiskPartitionReader

func DiskPartitionReader(all bool) (*trdsql.SliceReader, error)

DiskPartitionReader returns disk.Partitions result as trdsql.SliceReader.

func DiskUsageQuery

func DiskUsageQuery(usage string, query string, w trdsql.Writer) error

DiskUsageQuery executes SQL on disk.Usage.

func DiskUsageReader

func DiskUsageReader(usage string) (*trdsql.SliceReader, error)

DiskUsageReader returns disk.Usage result as trdsql.SliceReader.

func DockerQuery

func DockerQuery(query string, w trdsql.Writer) error

DockerQuery executes SQL on docker.GetDockerStat.

func DockerReader

func DockerReader() (*trdsql.SliceReader, error)

DockerReader returns docker.GetDockerStat result as trdsql.SliceReader.

func HostInfoReader

func HostInfoReader() (*trdsql.SliceReader, error)

HostInfoReader returns host.Info result as trdsql.SliceReader.

func HostQuery

func HostQuery(tempera bool, users bool, query string, w trdsql.Writer) error

HostQuery executes SQL on host.Info or host.Users or host.SensorsTemperatures.

func HostTemperatureReader

func HostTemperatureReader() (*trdsql.SliceReader, error)

HostTemperatureReader returns host.SensorsTemperatures result as trdsql.SliceReader.

func HostUsersReader

func HostUsersReader() (*trdsql.SliceReader, error)

HostUsersReader returns host.Users result as trdsql.SliceReader.

func LoadAvgReader

func LoadAvgReader() (*trdsql.SliceReader, error)

LoadAvgReader returns load.Avg result as trdsql.SliceReader.

func LoadMiscReader

func LoadMiscReader() (*trdsql.SliceReader, error)

LoadMiscReader returns load.Misc result as trdsql.SliceReader.

func LoadQuery

func LoadQuery(misc bool, query string, w trdsql.Writer) error

LoadQuery executes SQL on Load.Avg or Load.Misc.

func MEMQuery

func MEMQuery(memory bool, query string, w trdsql.Writer) error

MEMQuery executes SQL on mem.VirtualMemory or mem.SwapMemory.

func NetQuery

func NetQuery(query string, w trdsql.Writer) error

NetQuery executes SQL on net.Connections.

func NetReader

func NetReader() (*trdsql.SliceReader, error)

NetReader returns net.Connections result as trdsql.SliceReader.

func PSTableQuery

func PSTableQuery(tableName string, query string, w trdsql.Writer) error

PSTableQuery executes SQL on tables.

func ProcessQuery

func ProcessQuery(ex bool, query string, w trdsql.Writer) error

ProcessQuery executes SQL on process.Processes.

func QueryExec

func QueryExec(query string, writer trdsql.Writer) error

QueryExec actually executes the passed query and writes it to the writer.

func SwapMemoryReader

func SwapMemoryReader() (*trdsql.SliceReader, error)

SwapMemoryReader returns mem.SwapMemory result as trdsql.SliceReader.

func TableReader

func TableReader() (*trdsql.SliceReader, error)

TableReader return table name as trdsql.SliceReader.

func VirtualMemoryReader

func VirtualMemoryReader() (*trdsql.SliceReader, error)

VirtualMemoryReader returns mem.VirtualMemory result as trdsql.SliceReader.

Types

type MultiImporter

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

MultiImporter is a structure for importing multiple readers.

func NewMultiImporter

func NewMultiImporter(readers ...Reader) (*MultiImporter, error)

NewMultiImporter takes multiple readers as arguments and returns a MultiImporter.

func (*MultiImporter) Import

func (i *MultiImporter) Import(db *trdsql.DB, query string) (string, error)

Import executes import.

func (*MultiImporter) ImportContext added in v0.0.2

func (i *MultiImporter) ImportContext(ctx context.Context, db *trdsql.DB, query string) (string, error)

ImportContext executes import.

type ProcessReader

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

The ProcessReader structure represents a process and satisfies the trdsql.Reader interface.

func NewProcessReader

func NewProcessReader(ex bool) (*ProcessReader, error)

NewProcessReader returns process.Processes result as ProcessReader.

func (*ProcessReader) Names

func (p *ProcessReader) Names() ([]string, error)

Names returns column names.

func (*ProcessReader) PreReadRow

func (p *ProcessReader) PreReadRow() [][]any

PreReadRow is returns entity of the data.

func (*ProcessReader) ReadRow

func (p *ProcessReader) ReadRow(row []any) ([]any, error)

ReadRow only returns EOF.

func (*ProcessReader) TableName

func (p *ProcessReader) TableName() (string, error)

TableName returns TableName.

func (*ProcessReader) Types

func (p *ProcessReader) Types() ([]string, error)

Types returns column types.

type Reader

type Reader interface {
	TableName() (string, error)
	Names() ([]string, error)
	Types() ([]string, error)
	PreReadRow() [][]any
	ReadRow([]any) ([]any, error)
}

Reader is an interface that can be passed to MultiImporter.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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