{"id":17026297,"url":"https://github.com/st3v3nmw/pocketses","last_synced_at":"2025-03-22T19:15:52.481Z","repository":{"id":215251650,"uuid":"738389318","full_name":"st3v3nmw/pocketses","owner":"st3v3nmw","description":"Learning about Snaps \u0026 Snapcraft","archived":false,"fork":false,"pushed_at":"2024-01-05T09:38:14.000Z","size":177,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T23:18:19.036Z","etag":null,"topics":["metrics","pub-sub","publisher-subscriber","pubsub","python","snap","snapcraft","snapd"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/st3v3nmw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-03T05:44:11.000Z","updated_at":"2024-03-05T19:55:21.000Z","dependencies_parsed_at":"2024-10-14T07:31:43.956Z","dependency_job_id":null,"html_url":"https://github.com/st3v3nmw/pocketses","commit_stats":null,"previous_names":["st3v3nmw/hello-snaps"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st3v3nmw%2Fpocketses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st3v3nmw%2Fpocketses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st3v3nmw%2Fpocketses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st3v3nmw%2Fpocketses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/st3v3nmw","download_url":"https://codeload.github.com/st3v3nmw/pocketses/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245007238,"owners_count":20546143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["metrics","pub-sub","publisher-subscriber","pubsub","python","snap","snapcraft","snapd"],"created_at":"2024-10-14T07:31:38.882Z","updated_at":"2025-03-22T19:15:52.435Z","avatar_url":"https://github.com/st3v3nmw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"snap/gui/gollum.png\" width=\"150\" /\u003e\n    \u003ch1\u003ePocketses\u003c/h1\u003e\n    \u003ci\u003eWhat has it got in its pocketses, precious?!\u003c/i\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\nThis is a project I'm using to learn snaps, Snapcraft, Ubuntu Core, \u0026 landscape. It runs the following \"services\":\n\n- A collector to pull CPU, memory, and network statistics from the host, and\n- A publisher to push the metrics to all subscribed clients\n\nAreas covered:\n\n- [x] Python snap plugin\n- [x] Interfaces\n- [x] Pub/Sub with the [Twisted](https://twisted.org/) framework\n- [x] Remote builds\n- [x] Snap configuration\n- [x] Hooks\n- [x] Snapd REST API\n- [x] Model assertions\n\n### Etymology\n\nWhat'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 🙂.\n\n_Moving on swiftly..._\n\n## Installation\n\n### Source\n\nA few pre-reqs, make sure the following are installed:\n\n- [Snapcraft](https://snapcraft.io/docs/snapcraft-overview)\n- [yq](https://github.com/mikefarah/yq)\n\nThen run `git clone git@github.com:st3v3nmw/pocketses.git` to clone this repository and run `make build \u0026\u0026 make install`.\n\n### Snap store\n\nThe 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.\n\nIf you'd still like to take the path less traveled by, run `sudo snap install pocketses --channel=candidate`.\n\n## Setup\n\nConnect the snap to the `system-observe`, `network-observe` \u0026 `snapd-control` interfaces (`sudo snap connect pocketses:\u003cinterface-name\u003e`)\n\n## Usage\n\nAs 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).\n\n```console\n$ sudo pocketses --help\nusage: pocketses-cli [-h] [--port PORT] [--interval INTERVAL]\n\noptions:\n  -h, --help           show this help message and exit\n  --port PORT          Port to run server\n  --interval INTERVAL  Interval in seconds to collect metrics\n```\n\nOn one terminal, start pocketses:\n\n```console\n$ sudo pocketses\nStarting publisher...\nCollecting and sending stats...\nCollecting and sending stats...\n```\n\nOn two separate terminals, subscribe with two clients:\n\n```console\n$ telnet localhost 8888\nTrying 127.0.0.1...\nConnected to localhost.\nEscape character is '^]'.\n{\"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\"]}}}\n{\"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\"]}}}\n```\n\nYou should see some output after the interval elapses (default interval = 60 seconds).\n\n## Bugs/Features\n\n1. Subscribed clients can \"publish\" and this output is echoed back too all clients (sender included lol)\n\n## Upgrading Ubuntu Core\n\n- Get the model assertion: `snap known --remote model series=16 brand-id=canonical model=ubuntu-core-22-amd64 \u003e uc22.model`\n- Start the upgrade: `sudo snap remodel uc22.model`\n- Use `snap changes` \u0026 `snap change \u003cchange-id\u003e` to monitor the process\n\nCount your lucky stars if it passes. Mine didn't:\n\n```console\n$ snap change 29\nStatus  Spawn               Ready               Summary\nDone    today at 09:04 UTC  today at 09:11 UTC  Request new device serial\nDone    today at 09:04 UTC  today at 09:11 UTC  Prepare remodeling\nDone    today at 09:04 UTC  today at 09:11 UTC  Ensure prerequisites for \"pc-kernel\" are available\nUndone  today at 09:04 UTC  today at 09:11 UTC  Download snap \"pc-kernel\" (1540) from channel \"22/stable\"\nDone    today at 09:04 UTC  today at 09:11 UTC  Fetch and check assertions for snap \"pc-kernel\" (1540)\n\n[...]\n\nMount snap \"pc\" (146)\n\n2024-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])\n```\n\n## Resources\n\n- [Create your first snap](https://ubuntu.com/tutorials/create-your-first-snap)\n- [Adding Snapcraft parts](https://snapcraft.io/docs/adding-parts)\n- [Snap confinement](https://snapcraft.io/docs/snap-confinement)\n- [Snap commands and aliases](https://snapcraft.io/docs/commands-and-aliases)\n- [The Python snap plugin](https://snapcraft.io/docs/python-plugin)\n- [Python command line scripts](https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html)\n- [Snap interface management](https://snapcraft.io/docs/interface-management)\n- [Build snaps from GitHub](https://snapcraft.io/docs/build-from-github)\n- [Snapcraft hook support](https://snapcraft.io/docs/snapcraft-hook-support)\n- [Adding snap configuration](https://snapcraft.io/docs/adding-snap-configuration)\n- [Supported snap hooks](https://snapcraft.io/docs/supported-snap-hooks)\n- [Snapd REST API](https://snapcraft.io/docs/snapd-api)\n- [Snapcraft.yaml reference](https://snapcraft.io/docs/snapcraft-yaml-reference)\n- [Using the snapctl tool](https://snapcraft.io/docs/using-snapctl)\n- [Install Ubuntu Core on KVM](https://ubuntu.com/download/kvm)\n- [Upgrade Ubuntu Core](https://ubuntu.com/core/docs/upgrade)\n- [Assertions](https://ubuntu.com/core/docs/reference/assertions)\n- [Model assertion](https://ubuntu.com/core/docs/reference/assertions/model)\n- [Sign a model assertion](https://ubuntu.com/core/docs/sign-model-assertion)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst3v3nmw%2Fpocketses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fst3v3nmw%2Fpocketses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst3v3nmw%2Fpocketses/lists"}