common

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToGB

func BytesToGB(bytes uint64) float64

BytesToGB converts bytes to GB.

func BytesToUnit

func BytesToUnit(value uint64) string

BytesToUnit converts a float64 value (representing bytes) to a human-readable unit (KB, MB, GB, TB) based on its magnitude

func ConstructJsonFieldDescription

func ConstructJsonFieldDescription() map[string]string

ConstructJsonFieldDescription reads the data from the JSON file.

func ConvertBytes

func ConvertBytes(bytes uint64, unit string) float64

ConvertBytes converts bytes to the specified unit.

func ConvertBytesToUnit

func ConvertBytesToUnit(bytes float64, unit string) float64

ConvertBytesToUnit converts bytes to the specified unit and returns the result as a float64.

func ConvertToMB added in v0.0.2

func ConvertToMB(value string) (float64, error)

Helper function to convert values to MB

func ConvertToReadableSize

func ConvertToReadableSize(bytes uint64) (float64, string)

convertToReadableSize converts bytes into a more human-readable format (MB, GB).

func ConvertToReadableUnit

func ConvertToReadableUnit(value interface{}) string

ConvertToReadableUnit converts the input value to a more human-readable unit.

func DefaultFloatIfZero added in v0.0.2

func DefaultFloatIfZero(val, def float64) float64

Helper function to set default float value

func DefaultIfEmpty added in v0.0.2

func DefaultIfEmpty(val, def string) string

Helper function to set default string value

func DefaultIntIfZero added in v0.0.2

func DefaultIntIfZero(val, def int) int

Helper function to set default integer value

func GetBasePath

func GetBasePath() string

GetBasePath returns the base path for storage.

func GetCPULoad

func GetCPULoad() (serviceCPU, systemCPU, totalCPU string)

GetCPULoad calculates the CPU load for the service, system, and total.

func GetDataRetentionPeriod

func GetDataRetentionPeriod() time.Duration

GetDataRetentionPeriod returns the retention period.

func GetDirSize

func GetDirSize(folderPath string) string

GetDirSize returns the size of the directory.

func GetMemoryLoad

func GetMemoryLoad() (serviceMem, systemMem, totalMem string)

GetMemoryLoad calculates the memory load for the service, system, and total.

func GetProcessDetails

func GetProcessDetails() (int32, *process.Process)

GetProcessDetails returns the process ID and process object.

func GetProcessId

func GetProcessId() int32

GetProcessId returns the process ID.

func GetProcessObject

func GetProcessObject() *process.Process

GetProcessObject returns the process object.

func GetServiceInfo

func GetServiceInfo() models.ServiceInfo

GetServiceInfo returns the service info.

func GetServiceStartTime

func GetServiceStartTime() time.Time

GetServiceStartTime returns the service start time.

func GetVirtualMemory

func GetVirtualMemory() (*mem.VirtualMemoryStat, error)

GetVirtualMemory returns the virtual memory statistics.

func ParseFloat64ToString

func ParseFloat64ToString(value float64) string

ParseFloat64ToString converts float64 to string.

func ParseStringToFloat64

func ParseStringToFloat64(value string) float64

ParseStringToFloat64 converts string to float64.

func ParseUint64ToFloat64

func ParseUint64ToFloat64(value uint64) float64

ParseUint64ToFloat64 converts uint64 to float64.

func RoundFloat64

func RoundFloat64(value float64, precision int) float64

RoundFloat64 rounds the float64 value to the specified precision.

func SetServiceInfo

func SetServiceInfo(serviceName string, serviceStartTime time.Time, goVersion string, processId int32, rentainPeriod string)

sets the service info.

Types

type Cache added in v0.0.2

type Cache struct {
	Data map[string]time.Time
}

Cache is the struct to store the cache data

func (*Cache) LoadFromFile added in v0.0.2

func (c *Cache) LoadFromFile(filename string) error

LoadFromFile loads the cache from a file, or starts fresh if the file does not exist or an error occurs

func (*Cache) SaveToFile added in v0.0.2

func (c *Cache) SaveToFile(filename string) error

SaveToFile saves the cache to a file

Jump to

Keyboard shortcuts

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