Last active
February 9, 2024 05:01
-
-
Save SanariSan/3459f53388755a911d27088ad6756a09 to your computer and use it in GitHub Desktop.
ntp hints (ru)
This file contains hidden or 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
Leap: normal - корректировка мирового времени между электромагнитыми атомическими часами и определяемыми по планетам, не важно | |
Version: 4 - версия ntp протокола, последняя 4, не важно | |
Stratum: 1 - номер сервера в иерархии серверов синхронизации, 0 = атомические часы, 1 = сервер подключенный к ним локально, 2 = сервер подключенный по сети (уже плохо), играет роль, 1 - хорошо | |
Reference: PPS - указывает ориджин времени, PPS = Generic pulse-per-second, атомические часы на пульсации электронов, не важно) | |
Precision: 4us (-18) - сколько требуется микросекунд для доступа к системному времени | |
Root distance - Максимально возможное ДОП. отклонение Offset значения | |
Offset - идут локальные часы вперед от сервера или назад и на сколько | |
Delay - он же пинг в мире ntp протокола | |
jitter - Среднее отклонение, берется при сравнении всех доступных ресурсов | |
Frequency - Потенциальное доп отклонение времени, вроде из-за железа локального |
This file contains hidden or 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
const { promisify } = require('util'); | |
const exec = promisify(require('child_process').exec); | |
const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); | |
async function init() { | |
while (1) { | |
await exec(`sudo systemctl restart systemd-timesyncd`).catch((e) => { | |
console.log(e); | |
}); | |
await sleep(5000); | |
const commandResponse = await exec(`timedatectl timesync-status`).catch((e) => { | |
console.log(e); | |
}); | |
if (!commandResponse) continue; | |
const commandResponseRaw = commandResponse.stdout.trim(); | |
const splitted = commandResponseRaw.split('\n').map((el) => el.trim()); | |
const targetFields = []; | |
let syncSuccess = false; | |
splitted.forEach((el) => { | |
const [param, value] = el.split(':').map((el) => el.trim()); | |
if (param === 'Root distance' || param === 'Stratum') { | |
syncSuccess = true; | |
targetFields.push({ param, value }); | |
} | |
}); | |
if (!syncSuccess) { | |
console.log('Sync failed'); | |
continue; | |
} | |
let badTiming = false; | |
for (let { param, value } of targetFields) { | |
console.log('%s | %s', param, value); | |
if (param === 'Stratum' && parseFloat(value) !== 1) { | |
badTiming = true; | |
} | |
if (param === 'Root distance' && !/[\d.]+us/.test(value)) { | |
badTiming = true; | |
} | |
} | |
if (!badTiming) { | |
console.log('Timig Found'); | |
console.log(commandResponseRaw); | |
return; | |
} | |
} | |
} | |
init(); |
This file contains hidden or 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
#!/bin/bash | |
sudo timedatectl timesync-status | |
sudo systemctl restart systemd-timesyncd | |
sleep 5 | |
sudo timedatectl timesync-status |
This file contains hidden or 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
#!/bin/bash | |
sudo bash -c 'cat <<EOT >/etc/systemd/timesyncd.conf | |
[Time] | |
NTP=ntp3.vniiftri.ru ntp.aas.ru 2.ru.pool.ntp.org 2.ua.pool.ntp.org ntp1.stratum1.ru | |
#FallbackNTP=ntp.ubuntu.com | |
RootDistanceMaxSec=50ms | |
PollIntervalMinSec=10y | |
PollIntervalMaxSec=12y | |
EOT | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment