Skip to content

st3v3nmw/pocketses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pocketses

What has it got in its pocketses, precious?!

This is a project I'm using to learn snaps, Snapcraft, Ubuntu Core, & landscape. It runs the following "services":

  • A collector to pull CPU, memory, and network statistics from the host, and
  • A publisher to push the metrics to all subscribed clients

Areas covered:

  • Python snap plugin
  • Interfaces
  • Pub/Sub with the Twisted framework
  • Remote builds
  • Snap configuration
  • Hooks
  • Snapd REST API
  • Model assertions

Etymology

What's with the project's name I hear you ask? Well, I've been reading Tolkien's legendarium and naming things is hard (sobs), as someone famously quipped. There's an open challenge to come up with a better name. And if it loses, what then? Well, if it loses, precious, then we eats it whole 🙂.

Moving on swiftly...

Installation

Source

A few pre-reqs, make sure the following are installed:

Then run git clone git@github.com:st3v3nmw/pocketses.git to clone this repository and run make build && make install.

Snap store

The version on the snap store is far behind (I disabled the automatic GitHub + Launchpad builds since we're using the super privileged snapd-control interface and you'll get rejections from the snap store). We're using the snapd-control interface to get pocketses' snap configuration.

If you'd still like to take the path less traveled by, run sudo snap install pocketses --channel=candidate.

Setup

Connect the snap to the system-observe, network-observe & snapd-control interfaces (sudo snap connect pocketses:<interface-name>)

Usage

As mentioned before, this snap has to be run as root since we need to connect to the /run/snapd.socket socket through the snapd-control interface. Yes, we should probably switch to the snapctl tool but parsing the output seems unwieldy (plus HTTP/JSON is convenient).

$ sudo pocketses --help
usage: pocketses-cli [-h] [--port PORT] [--interval INTERVAL]

options:
  -h, --help           show this help message and exit
  --port PORT          Port to run server
  --interval INTERVAL  Interval in seconds to collect metrics

On one terminal, start pocketses:

$ sudo pocketses
Starting publisher...
Collecting and sending stats...
Collecting and sending stats...

On two separate terminals, subscribe with two clients:

$ telnet localhost 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
{"cpu": {"count": 8, "utilization": {"overall": 34.3, "per_cpu": [27.6, 51.0, 46.9, 27.8, 28.7, 36.1, 26.3, 29.7]}, "frequency": {"current": 800.0, "max": 4800.0, "min": 400.0}}, "memory": {"virtual": {"total": "15.4G", "used": "42.3%", "available": "8.9G"}, "swap": {"total": "8.0G", "used": "2.9%", "available": "7.8G"}}, "network": {"traffic": {"sent": "1.4G", "recv": "1.9G"}, "addresses": {"lo": ["127.0.0.1"], "wlp108s0": ["192.168.0.104"], "docker0": ["172.17.0.1"], "lxdbr0": ["10.131.100.1"]}}}
{"cpu": {"count": 8, "utilization": {"overall": 14.6, "per_cpu": [14.0, 7.0, 15.8, 9.4, 12.1, 11.2, 19.2, 28.0]}, "frequency": {"current": 500.0, "max": 4800.0, "min": 400.0}}, "memory": {"virtual": {"total": "15.4G", "used": "42.1%", "available": "8.9G"}, "swap": {"total": "8.0G", "used": "2.9%", "available": "7.8G"}}, "network": {"traffic": {"sent": "1.4G", "recv": "1.9G"}, "addresses": {"lo": ["127.0.0.1"], "wlp108s0": ["192.168.0.104"], "docker0": ["172.17.0.1"], "lxdbr0": ["10.131.100.1"]}}}

You should see some output after the interval elapses (default interval = 60 seconds).

Bugs/Features

  1. Subscribed clients can "publish" and this output is echoed back too all clients (sender included lol)

Upgrading Ubuntu Core

  • Get the model assertion: snap known --remote model series=16 brand-id=canonical model=ubuntu-core-22-amd64 > uc22.model
  • Start the upgrade: sudo snap remodel uc22.model
  • Use snap changes & snap change <change-id> to monitor the process

Count your lucky stars if it passes. Mine didn't:

$ snap change 29
Status  Spawn               Ready               Summary
Done    today at 09:04 UTC  today at 09:11 UTC  Request new device serial
Done    today at 09:04 UTC  today at 09:11 UTC  Prepare remodeling
Done    today at 09:04 UTC  today at 09:11 UTC  Ensure prerequisites for "pc-kernel" are available
Undone  today at 09:04 UTC  today at 09:11 UTC  Download snap "pc-kernel" (1540) from channel "22/stable"
Done    today at 09:04 UTC  today at 09:11 UTC  Fetch and check assertions for snap "pc-kernel" (1540)

[...]

Mount snap "pc" (146)

2024-01-05T09:09:54Z ERROR cannot remodel to an incompatible gadget: incompatible layout change: incompatible structure #4 ("ubuntu-save") change: new valid structure size range [33554432, 33554432] is not compatible with current ([16777216, 16777216])

Resources