Recording GPSD Statistics
Now that we've added the GNSS receiver to the Raspberry Pi timeserver, we have an extra source of data to monitor. Recording the information from GPSD will help to see how the GNSS receiver is performing; this can help with debugging and is crucial for the optimisation experiments to come.
Installing the GPSD Prometheus exporter
Brendan Bank on GitHub has made an excellent GPSD exporter (linked below) which sends the information we need to Prometheus with minimal hassle.
The steps I outline here are almost exactly taken from the guide on GitHub, but with the small tweaks I had to make to get it running on the Raspberry Pi.
The first step is to update the package sources, and to install the packages we'll need for the exporter script to run.
sudo apt update
sudo apt install python3-prometheus-client
sudo apt install python3-gps
sudo apt install git
Once done, we use git to clone the repo, and we copy the key parts to where they need to be on the Raspberry Pi.
git clone https://github.com/brendanbank/gpsd-prometheus-exporter.git
cd gpsd-prometheus-exporter
sudo cp gpsd_exporter.defaults /etc/default
sudo cp gpsd_exporter.service /etc/systemd/system
sudo cp gpsd_exporter.py /usr/local/bin
Now we make the python script executable.
sudo chmod +x /usr/local/bin/gpsd_exporter.py
Next we open the exporter defaults file to set our location (optional, but it makes the Grafana dashboard work fully).
sudo nano /etc/default/gpsd_exporter.defaults
Replace the uncommented line with
GPSD_MON_OPTIONS="-v --pps-histogram --offset-from-geopoint --geopoint-lon [Your Longitude Here] --geopoint-lat [Your Latitude Here]"
Save the file and close.
Lastly we enable and start the exporter service.
sudo systemctl enable gpsd_exporter.service
sudo systemctl start gpsd_exporter.service
The exporter should immediately make the information available on port 9015. Navigate to your Pi's IP Address (port 9015) to see the output. It should be like the image below.

Adding the GPSD sources to Prometheus
Now that the Raspberry Pi is exposing the GPSD information, we can record it in Prometheus.
Add the following lines to your prometheus.yml file and restart Prometheus.
- job_name: 'gpsd_NTPi'
scrape_interval: 60s
static_configs:
- targets: ['[Your Pi's IP goes here]:9015']
Prometheus should show that the source is up within a minute or two.

Adding the GPSD sources to Grafana
Brendan Bank's gpsd-prometheus-exporter GitHub page includes an excellent Grafana dashboard in json format. There's no need to reinvent the wheel (especially when it's this good), so just make a new Grafana dashboard using the json file. (I've added a link to it below)
You should immediately see the excellent visualisations of the GPSD data.


With that, we've got a GNSS-backed Stratum 1 NTP server with excellent capability for experimentation, and the optimisation can begin!
In the next section of the guide, we'll explore the effects of all manner of tweaks and adjustments.