- Rework logger - Remove deprecated functions - Split Logger to sub package (fields, level, config, ...) - Optimize dependencies - Rework Hookfile: fix error like FD still opened - Rework Hooksyslog: use same model like Hookfile, use network/protocol instead of self lib - Rework HookStd: use independent hook for std out & std err - Fix std config make generic options for files & syslog - Apply formatter to hook instead of main logger entry - optimize code Package ioutils: - rework PathCheckCreate funct: optimize code & fix some error Package Network: - create sub package protocol for all network protocl use - add encode function Package httpcli: - remove file network - use package network/protocol instead of network file Package archive: - apply change following rework of logger Package aws: - apply change following rework of logger Package cluster: - apply change following rework of logger Package cobra: - apply change following rework of logger Package Config Component: - apply change following rework of logger to component log - fix logger for monitoring - fix component following fix of package request / monitoring Package context: - apply change following rework of logger Package database: - apply change following rework of logger Package httpserver: - apply change following rework of logger Package ldap: - apply change following rework of logger Package monitor: - apply change following rework of logger - fix logger for monitoring - fix minor bugs Package nats: - apply change following rework of logger Package nutsdb: - apply change following rework of logger Package request: - apply change following rework of logger - fix minor bug - fix missing logger for monitoring - add one line for healthcheck (info or error) Package router: - apply change following rework of logger Package static: - apply change following rework of logger Package status: - apply change following rework of logger - fix bug with mandatory component Package viper: - apply change following rework of logger Other: - bump dependencies - github action workflow fix
Network package
This package is useful to retrieve network interface information and counter.
The information available are :
nameof the interface (cannot be empty)physicaladdress (or hardware address) (can be empty for example virtual ip or bridge)MTU(Maximu Transmission Unit) is the maximum size of packets could be transmitAddris the list of all network address (can be empty)Indexis the index for the current interface into the list all interface for current osFlagsare capabilities supported by the interface. You can find const for all flags available in golang/x/net package :FlagUp: interface is upFlagBroadcast: interface supports broadcast access capabilityFlagLoopback: interface is a loopback interfaceFlagPointToPoint: interface belongs to a point-to-point linkFlagMulticast: interface supports multicast access capability
Example of implement
You can get all interface with filter.
In this example we will search all interface who's have physical address and having at least on address =and match the list of flags composed here with only FlagUp :
// GetAllInterfaces(context.Context, onlyPhysical, hasAddr bool, atLeastMTU int, withFlags ...net.Flags)
list, err := network.GetAllInterfaces(context.Background(), true, true, 0, net.FlagUp)
You can also retrieve on interface based on his name or his phyisical address :
//NewInterface(context.Context, name, physical string)
i, e := NewInterface(context.Context, "eth0", "")
When you have you interface variable, you can use it to print for example the counter of received data.
The available statistics are grouped by way : In or Out In each group, the stats are :
StatBytes: Traffic in BytesStatPackets: Number of PacketsStatFifo: Number of packet in FIFOStatDrop: Number of packet droppedStatErr: Number of packet in Error
Stats are given as map[Stats]Number :
Statsis a self defined to map constant with a statement.Numberare still self defined type to allow formatting.Bytesis closed similar to Number but with different unit
This translation between bytes and number included into each type :
Number.AsBytesBytes.AsNumber
You can also convert this type as uint64 or as float64.
Now, we have all information to understand this example who's print all stat of sending traffic with unit :
fmt.Print("\tOut: \n")
l = i.GetStatOut()
for _, k := range network.ListStatsSort() {
s := network.Stats(k)
if v, ok := l[s]; ok {
fmt.Printf("\t\t%s\n", s.FormatLabelUnitPadded(v))
} else {
fmt.Printf("\t\t%s\n", s.FormatLabelUnitPadded(0))
}
}
Example
You can find an example in test/test-network
There result of this example is like this :
iface 'eth0' [00:15:5d:66:60:dd] :
Flags: up broadcast multicast
Addrs: {"addr":"172.25.59.95/20"} {"addr":"fe80::215:5dff:fe66:60dd/64"}
In:
Traffic: 27.33 GB
Packets: 20 M
Fifo: 0
Drop: 0
Error: 0
Out:
Traffic: 28.03 GB
Packets: 1118 K
Fifo: 0
Drop: 0
Error: 0