system

package
v0.0.0-...-3f388d4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

-------------------------------------------------------------------------

*
* cpu.go
*    Read process cpu info in procfs
*
*
* Copyright (c) 2021, Alibaba Group Holding Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* IDENTIFICATION
*           common/system/cpu.go
*-------------------------------------------------------------------------

-------------------------------------------------------------------------

*
* disk.go
*    Read process disk info in procfs
*
*
* Copyright (c) 2021, Alibaba Group Holding Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* IDENTIFICATION
*           common/system/disk.go
*-------------------------------------------------------------------------

-------------------------------------------------------------------------

*
* io.go
*    Read process io info in procfs
*
*
* Copyright (c) 2021, Alibaba Group Holding Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* IDENTIFICATION
*           common/system/io.go
*-------------------------------------------------------------------------

-------------------------------------------------------------------------

*
* mem.go
*    Read process mem info in procfs
*
*
* Copyright (c) 2021, Alibaba Group Holding Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* IDENTIFICATION
*           common/system/mem.go
*-------------------------------------------------------------------------

-------------------------------------------------------------------------

*
* system.go
*    Read process other info in procfs
*
*
* Copyright (c) 2021, Alibaba Group Holding Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* IDENTIFICATION
*           common/system/system.go
*-------------------------------------------------------------------------

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeletedFilesSize

func DeletedFilesSize(port int, pidsMap *sync.Map) (int64, int64, uint32, error)

func DirSize

func DirSize(path string) (int64, int64, error)

DirSizeExcludeHardLink calculate the file size one by one(hard link only calculate once) and return file count also

func FilteredDirSize

func FilteredDirSize(path, regex string) (int64, int64, error)

DirSize calculate the file size one by one and return file count also

func GetBinName

func GetBinName(path string, buf []byte, stat *ProcessStat) error

GetBinName get binary name, is kernel ""

func GetCPUCount

func GetCPUCount() (int64, error)

GetCPUCount return cpu count

func GetClkTck

func GetClkTck() (int64, error)

GetClkTck return the system clock ticks this will return the same as C.sysconf(C._SC_CLK_TCK)

func GetCmdLine

func GetCmdLine(path string, buf *bytes.Buffer, stat *ProcessStat, fp *os.File) (*os.File, error)

GetCmdLine get cmdline, if kernel cmd

func GetHostname

func GetHostname() string

GetHostname return the os hostname of this machine

func GetIP

func GetIP() string

func GetPageSize

func GetPageSize() (int64, error)

GetPageSize return the pagesize on this machine

func GetPid

func GetPid(port int, pidFile string) (pid uint32, err error)

func GetSysconf

func GetSysconf(scID int) (int64, error)

GetSysconf return the sysconf value associated with th scID

func ReadFile

func ReadFile(filename string, buf *bytes.Buffer, fp *os.File) (*os.File, error)

ReadFile reads the filename to buf

func ReadIOStat

func ReadIOStat(path string, buf *bytes.Buffer, stat *IOStat, fp *os.File) (*os.File, error)

ReadIOStat read statm from /proc/pid/io

func ReadMemStat

func ReadMemStat(path string, buf *bytes.Buffer, stat *MemoryStat, fp *os.File) (*os.File, error)

ReadMemStat read statm from /proc/pid/statm

func ReadProcessStat

func ReadProcessStat(path string, buf *bytes.Buffer, stat *ProcessStat, fp *os.File) (*os.File, error)

ReadProcessStat reads stat from /proc/pid/stat

func ValidPid

func ValidPid(pid uint32, pattern string) bool

Types

type Cpu

type Cpu struct {
	ClkTck int64

	Stat *ProcessStat
	// contains filtered or unexported fields
}

func NewCpu

func NewCpu(buf *bytes.Buffer) *Cpu

func (*Cpu) Close

func (c *Cpu) Close()

func (*Cpu) CpuStatByPid

func (c *Cpu) CpuStatByPid(pid uint32) error

CpuStatByPid get process stat by pid

func (*Cpu) Reset

func (c *Cpu) Reset()

func (*Cpu) ThreadCpuStat

func (c *Cpu) ThreadCpuStat(pid uint32) error

type IO

type IO struct {
	Stat *IOStat
	// contains filtered or unexported fields
}

func NewIO

func NewIO(buf *bytes.Buffer) *IO

func (*IO) Close

func (i *IO) Close()

func (*IO) IOStatByPid

func (i *IO) IOStatByPid(pid uint32) error

func (*IO) Reset

func (i *IO) Reset()

type IOStat

type IOStat struct {
	Rchar               uint64
	Wchar               uint64
	Syscr               uint64
	Syscw               uint64
	ReadBytes           uint64
	WriteBytes          uint64
	CancelledWriteBytes uint64
}

type Mem

type Mem struct {
	PageSize uint64

	Stat *MemoryStat
	// contains filtered or unexported fields
}

Mem the memory size in bytes

func NewMem

func NewMem(buf *bytes.Buffer) *Mem

func (*Mem) Close

func (m *Mem) Close()

func (*Mem) MemStatByPid

func (m *Mem) MemStatByPid(pid uint32) error

func (*Mem) Reset

func (m *Mem) Reset()

type MemoryStat

type MemoryStat struct {
	Size     uint64
	Resident uint64
	Shared   uint64
	Text     uint64
	Data     uint64
	// contains filtered or unexported fields
}

type ProcessStat

type ProcessStat struct {
	Pid       uint64 // 0
	PPid      uint64
	Comm      string // 1
	Status    byte
	Tgid      uint64 // 4
	MinFault  uint64 // 10
	MajFault  uint64 // 12
	Utime     uint64 // 13
	Stime     uint64 // 14
	Starttime uint64 // 21

	// /proc/pid/cmd
	CmdLine string
	// /proc/pid/exe
	BinName string
}

Jump to

Keyboard shortcuts

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