utility

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationToHoursAndMinutes

func DurationToHoursAndMinutes(duration time.Duration) string

DurationToHoursAndMinutes converts a duration in milliseconds to a formatted string representing hours and minutes.

func FormatDate

func FormatDate(date time.Time, timeZone string) string

FormatDate formats a time.Time value to a string using a specific date and time layout string and the specified time zone.

func GetDirSize

func GetDirSize(path string) (float64, error)

GetDirSize returns the size of the directory at the specified path. It takes the path of the directory as input and returns the size of the directory in gigabytes and an error if any. It walks through the directory and sums up the size of all the files within it. If an error occurs during the process, it returns the error.

func GetDurationTillTime

func GetDurationTillTime(start time.Time, duration time.Duration) (time.Duration, error)

GetDurationTillTime calculates the duration between a specified start time and the current time and returns it as a time.Duration value.

func GetVolumeSize

func GetVolumeSize(volumeName string) (float64, error)

GetVolumeSize returns the size of the specified volume. It takes the volumeName as input and returns the size of the volume in gigabytes and an error if any. It uses the Docker client to inspect the volume and retrieve its size. If the volume does not exist or if there is an error during the process, it returns the error.

func ParseEpochTime

func ParseEpochTime(epoch string) (*time.Time, error)

ParseEpochTime parses a string representing an epoch time and returns a pointer to a time.Time value.

func ParseIntFromString

func ParseIntFromString(str string) (int, error)

ParseIntFromString extracts the integer part from a string that may have a suffix. The suffix can be any non-digit characters at the end of the string. If the string cannot be parsed, an error is returned.

func StringMsToDuration

func StringMsToDuration(durationString string) (time.Duration, error)

StringMsToDuration converts a string representing a duration in milliseconds to a time.Duration value.

Types

type NetworkUsage

type NetworkUsage struct {
	Recv float64
	Sent float64
}

func GetNetworkUsage

func GetNetworkUsage() (*NetworkUsage, error)

GetNetworkUsage returns the network usage statistics. It retrieves the number of bytes received and sent over the network interface. It returns a pointer to NetworkUsage and an error if any. It uses the net package to fetch the network I/O counters.

type UsageData

type UsageData struct {
	Total          int
	Free           int
	Used           int
	PercentageUsed int
}

func GetCPUUsage

func GetCPUUsage() (*UsageData, error)

GetCPUUsage returns the CPU usage statistics. It retrieves the total number of CPU cores and the percentage of CPU usage. It returns a pointer to UsageData and an error if any.

func GetDiskUsage

func GetDiskUsage() (*UsageData, error)

GetDiskUsage returns the disk usage information for the root directory. It calculates the total, free, used, and percentage used space on the disk. It returns a pointer to UsageData and an error if any.

func GetMemoryUsage

func GetMemoryUsage() (*UsageData, error)

GetMemoryUsage returns the memory usage statistics. It retrieves the total, free, used memory in gigabytes, and the percentage of memory used. It returns a pointer to UsageData and an error if any. It uses the mem package to fetch the virtual memory statistics.

Jump to

Keyboard shortcuts

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