Documentation
¶
Overview ¶
Package subping provides a utility for concurrently pinging multiple IP addresses and collecting the results.
The package includes functionality for running ping operations on multiple IP addresses concurrently, calculating ping statistics, and partitioning data for parallel processing.
Example usage:
// Create options for Subping
opts := &subping.Options{
LogLevel: "info",
Subnet: "192.168.0.0/24",
Count: 5,
Interval: time.Second,
Timeout: 2 * time.Second,
MaxWorkers: 10,
}
// Create a new Subping instance
sp, err := subping.NewSubping(opts)
if err != nil {
log.Fatalf("Failed to create Subping instance: %v", err)
}
// Run the Subping process
sp.Run()
// Get the online hosts and their statistics
onlineHosts, total := sp.GetOnlineHosts()
fmt.Printf("Online Hosts: %v\n", onlineHosts)
fmt.Printf("Total Online Hosts: %d\n", total)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// LogLevel sets the log levels for the Subping instance.
LogLevel string
// Subnet is the subnet to scan for IP addresses to ping.
Subnet string
// Count is the number of ping requests to send for each target.
Count int
// Interval is the time duration between each ping request.
Interval time.Duration
// Timeout specifies the timeout duration before exiting each target.
Timeout time.Duration
// MaxWorkers specifies the maximum number of concurrent workers to use.
MaxWorkers int
}
Options holds the configuration options for creating a new Subping instance.
type Result ¶ added in v1.0.0
type Result struct {
// AvgRtt is the average round-trip time of the ping requests.
AvgRtt time.Duration
// PacketLoss is the percentage of packets lost during the ping operation.
PacketLoss float64
// PacketsSent is the number of packets sent for the ping operation.
PacketsSent int
// PacketsRecv is the number of packets received for the ping operation.
PacketsRecv int
// PacketsRecvDuplicates is the number of duplicate packets received.
PacketsRecvDuplicates int
}
Result contains the statistics and metrics for a single ping operation.
type Subping ¶
type Subping struct {
// TargetsIterator is an iterator for the target IP addresses to ping.
TargetsIterator *network.SubnetHostsIterator
// Count is the number of ping requests to send for each target.
Count int
// Interval is the time duration between each ping request.
Interval time.Duration
// Timeout specifies the timeout duration before exiting each target.
Timeout time.Duration
// BatchSize is the number of concurrent ping jobs to execute.
BatchSize int64
// Results stores the ping results for each target IP address.
Results map[string]Result
// TotalResults represents the total number of ping results collected.
TotalResults int
// MaxWorkers specifies the maximum number of concurrent workers to use.
MaxWorkers int
// contains filtered or unexported fields
}
Subping is a utility for concurrently pinging multiple IP addresses and collecting the results.
func NewSubping ¶
NewSubping creates a new Subping instance with the provided options.
func (*Subping) GetOnlineHosts ¶
GetOnlineHosts returns a map of online hosts and their corresponding ping results, as well as the total number of online hosts.
