Git Product home page Git Product logo

ping-to-timescaledb's Introduction

Network pinger to TimescaleDB

Simple program that pings multiple hosts and saves results to TimescaleDB for analysis.

By sending packets at a fixed interval regardless of outstanding requests it tries to avoid the Coordinated Omission problem. *

Usage

See below how to run and set up TimecaleDB.

git clone https://github.com/StianOvrevage/ping-to-timescaledb # Download files 
cd ping-to-timescaledb
go mod tidy # Download dependencies
export PING_TIMESCALEDB_CONNSTR=postgres://myuser:mypassword@timescaledb:5432/mydatabase
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
go run main.go

Assumes you already have golang installed, version 1.21.5 or newer.

Optional configuration:

# Ping each host every interval. Regardless of whether there are outstanding requests.
export PING_INTERVAL=200ms
# Timeout. If requests time out their latency will be set to this number, and the `timeout` field in DB will be true.
export PING_TIMEOUT=2s
# Comma separated list of destination hosts to ping
export PING_DESTINATIONS=www.vg.no,192.168.1.1,test.hkg1.servers.com
# Override hostname of local machine
export PING_SOURCE_HOSTNAME=desktop

The program runs in the foreground forever. You can use screen to run it in the background after disconnection from a terminal session.

Analyzing data

Use Grafana and add TimescaleDB as a data source. Then import the very simple Pings dashboard into Grafana.

Here we see latency of wired (nuc) vs wireless (desktop) to the local router (192.168.1.1).

TimescaleDB preparation

Run TimescaleDB as a container:

docker run -d --name timescaledb -p 5432:5432 \
  -e POSTGRES_PASSWORD=myPassword timescale/timescaledb-ha:pg16-all

PS: This is without persistence since I'm strugling how to get volume mounts and postgres to work in podman.

Connect to the database with psql or pgAdmin

Create a new database (mydatabase above). Create a new user (myuser above) with a password (mypassword above) and permission to log in.

Create the table and hypertable:

CREATE TABLE pings (
  time TIMESTAMPTZ NOT NULL,
  from_host TEXT NOT NULL,
  to_host TEXT NOT NULL,
  interface TEXT NOT NULL, -- Not implemented yet
  error TEXT, -- Not implemented yet
  timeout BOOL NOT NULL DEFAULT FALSE,
  latency_ms DOUBLE PRECISION NULL
);

SELECT create_hypertable('pings', by_range('time'));

Ensure that the new user has permissions to the database and table.

Optionally create a read-only user for the table to use with Grafana.

Caveats

If we are writing data to TimescaleDB close to capacity and there are bursts of requests that suddenly finish, we may not be fast enough to flush the results. If that condition lasts long enough for the result collection queue (size 1000 results) to fill up we will have a coordinated omission problem. Even though I believe this is unlikely the program will print the current size of the queue every 5 seconds.

Background

I've had some issues with my wireless Hi-Fi (KEF LS50 & System Audio Focus SA-5).

Intermittently there will be random issues with noise on one or both speakers. Speakers becoming unavailable to Spotify Connect for a little while. And so on.

The issue has persisted between changing my wireless setup three times. I'm now on Unify Amplify Mesh. And moving between three different places, first an appartment complex and now in a free standing house. And two separate Hi-Fi systems are having issues.

I always have my trusty ping -t vg.no running in the background and have noticed that network reliability isn't as good as it should be. What if this is related?

I'm not too keen on spending even more money on this by investing in a Wi-Fi spectrum analyzer that costs from $1.000 and infinitely upwards.

Can we just fire away a bunch of pings (at a steady rate to avoid the coordinated omission proble) from all of my machines (Intel NUC server, wired. Desktop, wireless. Laptop, wireless) and see any correlation when the sound is having problems?

At least it could verify that I'm not going insane! If I find something I can start the process of elimination turning of and disconnecting everything and use the ping data as guidance instead of me intermittently listening ot music waiting for intermittent problems, which would take months.

I also wanted to collect Wi-Fi information but I haven't been able to get the Intel NUC Wi-Fi adapter to cooperate.

ping-to-timescaledb's People

Contributors

stianovrevage avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.