-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #722 from Meepoljdx/main
add: add timeout config for ntp input plugin
- Loading branch information
Showing
4 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
# # ntp servers | ||
# ntp_servers = ["ntp.aliyun.com"] | ||
|
||
# # response time out seconds | ||
# timeout = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ntp | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
"time" | ||
|
||
"github.com/toolkits/pkg/nux" | ||
) | ||
|
||
func TestGetTwoTime(t *testing.T) { | ||
orgTime := time.Now() | ||
log.Println("Begin") | ||
serverReciveTime, serverTransmitTime, err := nux.NtpTwoTime("ntp1.aliyun.com", 20) | ||
if err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
dstTime := time.Now() | ||
|
||
// https://en.wikipedia.org/wiki/Network_Time_Protocol | ||
duration := ((serverReciveTime.UnixNano() - orgTime.UnixNano()) + (serverTransmitTime.UnixNano() - dstTime.UnixNano())) / 2 | ||
|
||
delta := duration / 1e6 // convert to ms | ||
log.Println(delta) | ||
} |