Skip to content

Commit

Permalink
Merge pull request #21 from paulgear/feature/debian-packaging
Browse files Browse the repository at this point in the history
First cut at Debian package
  • Loading branch information
paulgear authored Oct 3, 2023
2 parents 251ba06 + c5d657b commit c7a4b70
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tarballs
*.pyc
__pycache__
buildroot
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Changelog

Notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]


## [2.0.0] - 2023-09-28

### Added

- auto-detection of NTP implementation
- chrony support
- collectd support
- detection of hours and days in "when" field
- gnuplot-based scripts for loopstats and peerstats and intersection algorithm visualisation
- juju charms reactive layer
- ntpd system metrics (from "ntpq -nc readvar")
- prometheus exporter
- standalone parser for chrony statistics files
- systemd service template
- telegraf support
- unit tests expanded and improved (still needs more work)
- updated documentation

### Fixed

- correctly detect when no NTP server is running
- fix incorrect reversal of WARNING & CRITICAL thresholds
- various display quirks and inconsistencies
- code reformatted for flake8 fixes
- report metrics in seconds rather than milliseconds, to prevent confusion when graphing
- report survivors-offset-mean instead of syncpeer-offset-mean; more closely corresponds with old behaviour

### Removed

- trace checks are now disabled by default, and marked as deprecated
40 changes: 36 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
# This file is part of ntpmon - see COPYING.txt for license.
PYTHONPATH=$(PWD)/src

BUILDROOT=buildroot
DESTDIR=/
NAME=ntpmon
PREFIX=/usr/local
SHAREDIR=share/$(NAME)
VERSION=2.0.0

test: pytest datatest

pytest:
python3 -m unittest -b unit_tests/test_classifier.py unit_tests/test_peers.py
PYTHONPATH=./src python3 -m unittest -b unit_tests/test_classifier.py unit_tests/test_peers.py

datatest:
./testdata/testdata.sh
PYTHONPATH=./src ./testdata/testdata.sh

push:
git push github

clean:
find . -type f -name '*.pyc' -print0 | xargs --null rm -f
find . -type f -name '*.pyc' -delete
find . -type d -name '__pycache__' -delete

install:
install -d $(DESTDIR)/$(PREFIX)/ $(DESTDIR)/$(PREFIX)/$(SHAREDIR)/
install -m 0644 src/*.py $(DESTDIR)/$(PREFIX)/$(SHAREDIR)/
chmod 0755 $(DESTDIR)/$(PREFIX)/$(SHAREDIR)/*ntpmon.py
install -d -m 0755 $(DESTDIR)/$(PREFIX)/bin
cd $(DESTDIR)/$(PREFIX)/bin; \
ln -s ../$(SHAREDIR)/ntpmon.py $(NAME); \
ln -s ../$(SHAREDIR)/check_ntpmon.py check_$(NAME)

buildenv:
mkdir -p $(BUILDROOT)
git archive --format=tar.gz --prefix=$(NAME)-$(VERSION)/ HEAD > $(BUILDROOT)/$(NAME)_$(VERSION).orig.tar.gz

package: buildenv
cd $(BUILDROOT); \
tar -xf $(NAME)_$(VERSION).orig.tar.gz; \
cd $(NAME)-$(VERSION)/; \
debuild

srcpackage: buildenv
cd $(BUILDROOT); \
tar -xf $(NAME)_$(VERSION).orig.tar.gz; \
cd $(NAME)-$(VERSION)/; \
debuild -S
34 changes: 34 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ntpmon (2.0.0-1) unstable; urgency=medium

* Apparently I had previously tagged a version of ntpmon as v1.0.0, so I'm
declaring this a breaking change, semver-wise, even though it probably is
99% backwards compatible. The remaining changelog is lightly edited from
an auto-generated changelog from git history.
* Added:
- auto-detection of NTP implementation
- chrony support
- collectd support
- detection of hours and days in "when" field
- gnuplot-based scripts for loopstats and peerstats and intersection
algorithm visualisation
- juju charms reactive layer
- ntpd system metrics (from "ntpq -nc readvar")
- prometheus exporter
- standalone parser for chrony statistics files
- systemd service template
- telegraf support
- unit tests expanded and improved (still needs more work)
- updated documentation
* Fixed:
- correctly detect when no NTP server is running
- fix incorrect reversal of WARNING & CRITICAL thresholds
- various display quirks and inconsistencies
- code reformatted for flake8 fixes
- report metrics in seconds rather than milliseconds, to prevent confusion
when graphing
- report survivors-offset-mean instead of syncpeer-offset-mean; more
closely corresponds with old behaviour
* Removed:
- trace checks are now disabled by default, and marked as deprecated

-- Paul Gear <[email protected]> Thu, 28 Sep 2023 08:29:19 +1000
22 changes: 22 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Source: ntpmon
Section: python
Priority: optional
Maintainer: Paul Gear <[email protected]>
Build-Depends:
debhelper-compat (= 13),
dh-python,
python3-all,
python3-docutils
Standards-Version: 4.6.0
Homepage: https://github.com/paulgear/ntpmon
# X-Python3-Version: >= 3.7
Rules-Requires-Root: no

Package: ntpmon
Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}, chrony | ntp, python3-prometheus-client, python3-psutil
Suggests: collectd, nagios-nrpe-server, telegraf
Description: Monitor/check NTP metrics
This application is a flexible monitor/checker for the health of an
NTP daemon, supporting chronyd and ntpd. It supports reporting metrics
to collectd, Nagios, prometheus, and telegraf.
24 changes: 24 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ntpmon
Upstream-Author: Paul Gear <[email protected]>
Source: https://github.com/paulgear/ntpmon

Files: *
Copyright: 2015-2023 Paul D. Gear.
2017-2018 Canonical, Ltd. (juju layer)
License: GPL-3.0+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
.
On Debian systems, the complete text of the GNU General
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
2 changes: 2 additions & 0 deletions debian/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHANGELOG.md
README.md
41 changes: 41 additions & 0 deletions debian/manpage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
:Version: 2.0.0
:Date: 2023-09-28
:Copyright: 2015-2023 Paul Gear
:Title: ntpmon
:Subtitle: NTP metrics monitor
:Manual group: NTP metrics monitor
:Manual section: "8"

Summary
#######

``ntpmon`` is a metrics collector for NTP which periodically queries data from
the running NTP service and sends it to ``collectd``, ``prometheus``, or
``telegraf`` for graphing or further processing.

Usage
#####

ntpmon.py [-h] [--mode {collectd,prometheus,telegraf}] [--connect CONNECT]
[--interval INTERVAL] [--port PORT]

Common Options
##############

Options:

-h, --help show this help message and exit

--mode {collectd,prometheus,telegraf}
Collectd is the default if collectd environment
variables are detected

--connect CONNECT Connect string (in host:port format) to use when sending
data to telegraf (default: 127.0.0.1:8094)

--interval INTERVAL How often to report statistics (default: the value of
the COLLECTD_INTERVAL environment variable, or 60
seconds if COLLECTD_INTERVAL is not set)

--port PORT TCP port on which to listen when acting as a prometheus
exporter (default: 9648)
12 changes: 12 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/make -f
# -*- makefile -*-

NAME=ntpmon

%:
dh $@ --with python3

override_dh_auto_install:
$(MAKE) DESTDIR=$$(pwd)/debian/$(NAME) PREFIX=/usr install
rst2man debian/manpage.rst > debian/$(NAME).8
dh_installman debian/$(NAME).8
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)
20 changes: 10 additions & 10 deletions testdata/testdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ runtest()
echo -n "."
#echo "Testing $FILE $REVERSE"
if ./src/check_ntpmon.py --test < $FILE >$TMPFILE 2>&1; then
if [ -n "$REVERSE" ]; then
echo "ERROR: $FILE should have failed for $@:"
cat $TMPFILE
return 1
fi
if [ -n "$REVERSE" ]; then
echo "ERROR: $FILE should have failed for $@:"
cat $TMPFILE
return 1
fi
else
if [ -z "$REVERSE" ]; then
echo "ERROR: $FILE FAILED:"
cat $TMPFILE
return 1
fi
if [ -z "$REVERSE" ]; then
echo "ERROR: $FILE FAILED:"
cat $TMPFILE
return 1
fi
fi
return 0
}
Expand Down

0 comments on commit c7a4b70

Please sign in to comment.