From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 6BE971FF0B3 for ; Thu, 26 Nov 2026 14:43:29 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A26C721839; Thu, 26 Nov 2026 14:42:36 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH widget-toolkit 11/16] node: time: add window listing the current NTP sources Date: Thu, 26 Nov 2026 14:40:08 +0100 Message-ID: <20261126134128.316681-12-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126134128.316681-1-j.theisen@proxmox.com> References: <20261126134128.316681-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795700521222 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.067 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: RR3WTEC2V2N3KPQR45OQUVIOTUNY3SRO X-Message-ID-Hash: RR3WTEC2V2N3KPQR45OQUVIOTUNY3SRO X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a "Sources" button to the time view that opens a window listing the sources the time synchronization service currently uses, including the members of pools, with their selection state, stratum, polling interval, reachability, age of the last sample and offset. This helps to find out why the clock is not synchronized, or how far off a node is compared to its sources. Double clicking the clock synchronization row opens the window as well. The list refreshes every five seconds while the window is open. The button and the row action are only available if the API reports that the active service supports listing its sources, which also keeps them hidden for products whose time API does not provide it. Signed-off-by: Jonas Theisen --- src/Makefile | 1 + src/node/TimeView.js | 32 +++++++- src/window/NTPSources.js | 155 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 src/window/NTPSources.js diff --git a/src/Makefile b/src/Makefile index 24bd719..72bac69 100644 --- a/src/Makefile +++ b/src/Makefile @@ -91,6 +91,7 @@ JSSRC= \ window/PackageVersions.js \ window/PackageChangelog.js \ window/ServiceLog.js \ + window/NTPSources.js \ window/TaskViewer.js \ window/LanguageEdit.js \ window/DiskSmart.js \ diff --git a/src/node/TimeView.js b/src/node/TimeView.js index 0c08e31..ecae553 100644 --- a/src/node/TimeView.js +++ b/src/node/TimeView.js @@ -37,13 +37,26 @@ Ext.define('Proxmox.node.TimeView', { autoShow: true, }); - // double click or enter on the NTP service row shows its log instead of the editor, the rows - // with read-only status information have no action + let sources_supported = () => !!me.rstore.getById('ntp-sources-supported')?.data.value; + + let view_sources = () => + Ext.create('Proxmox.window.NTPSources', { + nodename: me.nodename, + autoShow: true, + }); + + // Double click or enter on the NTP service row shows its log instead of the editor, and on + // the clock synchronization row the sources it is synchronized to, if supported. The rows + // with read-only status information have no action otherwise. let run_row_action = () => { let key = me.getSelectionModel().getSelection()[0]?.data.key; if (key === 'ntp-service') { view_service_log(); - } else if (key !== 'localtime' && key !== 'ntp-synchronized') { + } else if (key === 'ntp-synchronized') { + if (sources_supported()) { + view_sources(); + } + } else if (key !== 'localtime') { run_editor(); } }; @@ -156,6 +169,13 @@ Ext.define('Proxmox.node.TimeView', { handler: confirm_sync, }); + // only shown if the API reports that the NTP service supports it + let sources_btn = new Ext.Button({ + text: gettext('Sources'), + hidden: true, + handler: view_sources, + }); + let rows = { timezone: { header: gettext('Time zone'), @@ -201,6 +221,10 @@ Ext.define('Proxmox.node.TimeView', { clustered: { visible: false, }, + // same for the sources button + 'ntp-sources-supported': { + visible: false, + }, 'ntp-synchronized': { header: gettext('Clock synchronized'), renderer: Proxmox.Utils.format_boolean, @@ -222,6 +246,7 @@ Ext.define('Proxmox.node.TimeView', { handler: run_editor, }, sync_btn, + sources_btn, syslog_btn, ], listeners: { @@ -240,6 +265,7 @@ Ext.define('Proxmox.node.TimeView', { me.mon(me.rstore, 'load', () => { syslog_btn.setVisible(!!get_ntp_service()); sync_btn.setVisible(!!me.rstore.getById('ntp-sync-supported')?.data.value); + sources_btn.setVisible(sources_supported()); }); me.on('activate', me.rstore.startUpdate); diff --git a/src/window/NTPSources.js b/src/window/NTPSources.js new file mode 100644 index 0000000..178bfbb --- /dev/null +++ b/src/window/NTPSources.js @@ -0,0 +1,155 @@ +Ext.define('proxmox-ntp-sources', { + extend: 'Ext.data.Model', + // not every service reports all values, keep missing ones null instead of converting to 0 + fields: [ + 'address', + 'name', + { + name: 'state', + // sort by how usable the source is, instead of alphabetically + sortType: (state) => + ['unusable', 'falseticker', 'candidate', 'combined', 'selected'].indexOf(state), + }, + { name: 'stratum', type: 'integer', allowNull: true }, + { name: 'poll', type: 'number', allowNull: true }, + { name: 'reach', type: 'integer', allowNull: true }, + { name: 'last-rx', type: 'integer', allowNull: true }, + { name: 'offset', type: 'number', allowNull: true }, + ], + idProperty: 'address', +}); + +Ext.define('Proxmox.window.NTPSources', { + extend: 'Ext.window.Window', + alias: 'widget.proxmoxNTPSources', + + title: gettext('NTP Sources'), + modal: true, + layout: 'fit', + width: 900, + height: 400, + + initComponent: function () { + let me = this; + + if (!me.nodename) { + throw 'no node name specified'; + } + + let rstore = Ext.create('Proxmox.data.UpdateStore', { + interval: 5000, + model: 'proxmox-ntp-sources', + proxy: { + type: 'proxmox', + url: `/api2/json/nodes/${me.nodename}/time/sources`, + }, + }); + + // updates the rows in place, so the grid does not show its load mask on every refresh + let store = Ext.create('Proxmox.data.DiffStore', { + rstore: rstore, + // best first, kept when sources are added or change their state on a refresh + sortAfterUpdate: true, + sorters: [ + { + property: 'state', + direction: 'DESC', + }, + ], + }); + + let renderOptional = (renderer) => (value) => + value === undefined || value === null ? '-' : renderer(value); + + let renderState = function (state) { + let [icon, text] = { + selected: ['check-circle good', gettext('Selected')], + combined: ['check-circle good', gettext('Combined')], + candidate: ['circle-o', gettext('Candidate')], + falseticker: ['exclamation-circle warning', gettext('Falseticker')], + unusable: ['times-circle critical', gettext('Unusable')], + }[state] ?? ['question-circle', Ext.htmlEncode(state)]; + + return ` ${text}`; + }; + + // the offset in the most readable unit, as it ranges from microseconds to seconds + let renderOffset = function (offset) { + let abs = Math.abs(offset); + let sign = offset < 0 ? '-' : '+'; + if (abs < 0.001) { + return `${sign}${(abs * 1e6).toFixed(0)} us`; + } else if (abs < 1) { + return `${sign}${(abs * 1e3).toFixed(3)} ms`; + } + return `${sign}${abs.toFixed(3)} s`; + }; + + Ext.apply(me, { + items: { + xtype: 'grid', + store: store, + emptyText: gettext('No sources'), + columns: [ + { + header: gettext('State'), + dataIndex: 'state', + width: 130, + renderer: renderState, + }, + { + header: gettext('Address'), + dataIndex: 'address', + flex: 1, + renderer: Ext.htmlEncode, + }, + { + header: gettext('Name'), + dataIndex: 'name', + flex: 1, + renderer: Ext.htmlEncode, + }, + { + header: gettext('Stratum'), + dataIndex: 'stratum', + width: 80, + renderer: renderOptional((value) => value), + }, + { + header: gettext('Poll interval'), + dataIndex: 'poll', + width: 100, + renderer: renderOptional(Proxmox.Utils.format_duration_human), + }, + { + // octal, like the NTP tools show it, i.e. 377 if all of the last 8 polls + // got a response + header: gettext('Reach'), + dataIndex: 'reach', + width: 70, + renderer: renderOptional((value) => value.toString(8)), + }, + { + header: gettext('Last sample'), + dataIndex: 'last-rx', + width: 100, + renderer: renderOptional(Proxmox.Utils.format_duration_human), + }, + { + header: gettext('Offset'), + dataIndex: 'offset', + width: 100, + align: 'right', + renderer: renderOptional(renderOffset), + }, + ], + }, + }); + + me.callParent(); + + Proxmox.Utils.monStoreErrors(me.down('grid'), rstore); + me.on('destroy', rstore.stopUpdate); + rstore.startUpdate(); + }, +}); -- 2.47.3