Bonum Certa Men Certa

Using a Single-Board Computer to Monitor IPFS

IPFS lights-based monitoring on self-hosted SBC
IPFS lights-based monitoring on self-hosted SBC (blue is for status, green and red for upstream and downstream payloads)



Summary: IPFS is light and simple enough to run from one's home, even on a low-voltage machine, and the code below can be used as a baseline for monitoring IPFS activity 24/7




#!/usr/bin/python3
# 2019-04-22
# 2020-11-07



from blinkt import set_pixel, show from random import randint,random,shuffle,randrange from time import sleep import argparse import signal

def solid(r,g,b,s): while True: for pixel in range(8): set_pixel(pixel, r, g, b) show() sleep(0.1)

def random_lights3(): while True: for pixel in range(8): r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) set_pixel(pixel, r, g, b) show() sleep(0.1)

def random_lights2(): while True: p=range(8) p=sorted(p, key=lambda x: random()) for pixel in p: r = randrange(0, 255, 16) g = randrange(0, 255, 16) b = randrange(0, 255, 16) set_pixel(pixel, r, g, b) show() sleep(0.1)

def random_lights1(): while True: p=range(8) p=sorted(p, key=lambda x: random()) for pixel in p: r = randrange(0, 255, 8) g = randrange(0, 255, 8) b = randrange(0, 255, 8) set_pixel(pixel, r, g, b) show() sleep(0.1)

def spacer(r,g,b,seconds): while True: for pixel in range(8): set_pixel(pixel, r, g, b) next = (pixel+1)%8 set_pixel(next, 0, 0, 0) show() sleep(seconds)

def reversed_spacer(r,g,b,seconds): while True: for pixel in reversed(range(8)): set_pixel(pixel, r, g, b) prev = (pixel-1)%8 set_pixel(prev, 0, 0, 0) show() sleep(seconds)

def cylon(r,g,b,seconds): while True: for pixel in reversed(range(8)): set_pixel(pixel, r, g, b) prev = (pixel-1)%8 if prev < pixel: set_pixel(prev, 0, 0, 0) show() sleep(seconds) for pixel in range(8): set_pixel(pixel, r, g, b) next = (pixel+1)%8 if next > pixel: set_pixel(next, 0, 0, 0) show() sleep(seconds)

def pulsed_bar(r,g,b,seconds): steps=8 while True: for fade in reversed(range(steps)): r2=r*(fade+1)/steps g2=g*(fade+1)/steps b2=b*(fade+1)/steps # print (fade) for pixel in range(8): set_pixel(pixel, r2, g2, b2)

show() sleep(seconds) for fade in range(int(steps/1)): r2=r*(fade+1)/steps g2=g*(fade+1)/steps b2=b*(fade+1)/steps for pixel in range(8): set_pixel(pixel, r2, g2, b2)

show() sleep(seconds*0.5)

def ipfs(r,g,b,seconds): steps=4 # how many stages in gradient brightness=0.5 # how bright the lights will get bluebright=100 # the brightness of the blue light in the middle (0-255), albeit overriden by input dim=1 # increase to dim down the lights run = 0 # running count for periodic file access while True: # run always (until interruption) run=run+1 # first, open from files the required values, which change over time if (int(run) % 50 == 1): with open(r'~/RateIn', 'r') as f: # open from file the IN value # print(r) lines = f.read().splitlines() r=int(lines[-1]) # read the value # r=int(map(int, f.readline().split())) # prototype, for multiples (stale)

with open(r'~/RateOut', 'r') as f: # open from file OUT value # print(g) # show values, debugging lines = f.read().splitlines() g=int(lines[-1])

with open(r'~/Swarm', 'r') as f: # open from file Swarm value # print(g) # show values, debugging lines = f.read().splitlines() bluebright=int(lines[-1])/2 # print(bluebright)

for fade in reversed(range(steps)): # fade in effect # print(g2) # show values again, debugging # print(r2) r2=r*(fade+1)/steps/dim g2=g*(fade+1)/steps/dim b2=b*(fade+1)/steps/dim

# print(g2) # show values again, debugging # print(r2)

# print (fade) for pixel in range(3): # first 3 LED lights set_pixel(pixel, r2/20, (g2*brightness)+(pixel*1), b2/20)

for pixel in range(5,8): # the other/last 3 lights set_pixel(pixel, (r2*brightness)+(pixel*1), g2/20, b2/20) if (bluebright==0): set_pixel(3, 255, 255, 255) set_pixel(4, 255, 255, 255) else: set_pixel(3, 0, 0, 0) set_pixel(4, 0, 0, bluebright)

show() sleep(seconds/r*r+0.1) for fade in range(int(steps/1)): # fade out effect r2=r*(fade+1)/steps/dim g2=g*(fade+1)/steps/dim b2=b*(fade+1)/steps/dim

for pixel in range(3): set_pixel(pixel, r2/20, (g2*brightness)+(pixel*1), b2/20)

for pixel in range(5,8): set_pixel(pixel, (r2*brightness)+(pixel*1), g2/20, b2/20) set_pixel(3, 0, 0, bluebright) set_pixel(4, 0, 0, 0) show() sleep(seconds/g*g+0.1)

def flashed_bar(r,g,b,seconds): while True: for half in range(4): set_pixel(half,r,g,b) for half in range(4,8): set_pixel(half,0,0,0) show() sleep(seconds) for half in range(4,8): set_pixel(half,r,g,b) for half in range(4): set_pixel(half,0,0,0) show() sleep(seconds)

def handler(signum, frame): print("\nSignal handler called with signal", signum) exit(0)

signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGINT, handler)

# read run-time options

parser = argparse.ArgumentParser(description="Drive 'blinkt' 8-pixel display.") parser.add_argument("pattern", help="name of light pattern: \ random[1-3], spacer, reversed_spacer, cylon, pulsed_bar, flashed_bar") parser.add_argument("r", metavar="r", type=int, help="red channel, 0-255") parser.add_argument("g", metavar="g", type=int, help="green channel, 0-255") parser.add_argument("b", metavar="b", type=int, help="blue channel, 0-255") parser.add_argument("timing", metavar="s", type=float, \ help="rate of binking in seconds") options = parser.parse_args()

pattern = options.pattern.lower() r = options.r g = options.g b = options.b s = options.timing

if pattern == "solid": solid(r,b,g,s) elif pattern == "random3": random_lights3() elif pattern == "random2": random_lights2() elif pattern == "random1" or pattern == "random": random_lights1() elif pattern == "spacer": spacer(r,g,b,s) elif pattern == "reversed_spacer": reversed_spacer(r,g,b,s) elif pattern == "cylon": cylon(r,g,b,s) elif pattern == "pulsed_bar": pulsed_bar(r,g,b,s) elif pattern == "ipfs": ipfs(r,g,b,s) elif pattern == "flashed_bar": flashed_bar(r,g,b,s) else: print("Unknown pattern") exit(1)

exit(0)





Example runtime: run-blinkt-ipfs.py ipfs 0 0 0 0.00

Based on or derived from baseline blinkt scripts; requires the hardware and accompanying libraries being installed on the system.

For the code to run properly in the above form, given that it takes input from files, the IPFS values need to be periodically written to disk/card, e.g. for every minute of the day:

* * * * * ipfs stats bw | grep RateIn | cut -d ' ' -f 2 | cut -d '.' -f 1 >> ~/RateIn * * * * * ipfs stats bw | grep RateOut | cut -d ' ' -f 2 | cut -d '.' -f 1 >> ~/RateOut * * * * * ipfs swarm peers | wc -l >> ~/Swarm

These lists of numbers can, in turn, also produce status reports to be shown in IRC channels. When our git repository becomes public it'll be included (AGPLv3).

Recent Techrights' Posts

[Video] Richard Stallman Explains What Intelligence in Computing Really Means and How Old That Is (Story About 1975, 50 Years Ago)
Uploaded 11 hours ago by Manuel Cuda News
Links 05/03/2025: Prioritising Science, Patents Squashed
Links for the day
New Short Clip of Richard Stallman's Thoughts on the "Hey Hi" (AI) Hype, Courtesy of Manuel Cuda News
about 6 hrs ago
What Microsoft and GitHub Really, Really, REALLY Do Not Want You to See or Know About
They're trying to misuse law in a completely different continent or to allege that reporting important facts is in breach of privacy law
Slopwatch: linuxsecurity.com and Other 'Linux' Sites With LLM Slop
SEO spam with machine-generated fodder, plus a person to whom English isn't a first language
Just Because Common Currencies (Including the US Dollar) Are Considered Uncertain Doesn't Mean People Should Adopt Volatile Multi-Level (Pyramid) Schemes
the scammers are trying to "go mainstream"
 
Dr. Andy Farnell on Brutality and (or of) Brute-Force Computing
"Understandably, the ecological cost of compute was never really on the minds of pure computer scientists"
IBM Absorbs More of Red Hat and There Are Several Layoff Rumours
Those are just rumours for now
Gemini Links 06/03/2025: Digg, Project Failure, and More
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, March 05, 2025
IRC logs for Wednesday, March 05, 2025
Gemini Links 05/03/2025: News Processing, Misbehaving, and Git
Links for the day
GNU/Linux Cracking Past the 4% Barrier in Hungary
There are still quite a few very famous developers and Free software projects from Hungary
Meanwhile in the Matrix Room #dei:fedoraproject.org
Remember that IBM does a lot of perception manipulation
Rumour About Red Hat Layoffs Yesterday
Can somebody from Red Hat or someone who knows someone there (impacted or not) confirm that there are layoffs this week at Red Hat?
What is fixated behavior? Stalker or just a fan of Emma Raducanu?
Reprinted with permission from Daniel Pocock
In Iran, GNU/Linux Reaches New Highs, According to statCounter
Does that make sense? In light of geopolitics? Probably.
Always Safety First
We have some reasons to suspect that one of several parties (possibly not in the UK but having connections here), having suffered major and very expensive setbacks, may look to harm the messenger one way or another
Links 05/03/2025: Starbucks Debt Soars and CFO Changed, Apple Pretends to Value Privacy, "Cloudflare Blocking Privacy Focused Users From Accessing Third-Party Websites"
Links for the day
Canonical's Latest Love Letter to Microsoft (Ubuntu Promoting Proprietary Spyware With Back Doors)
Typical Canonical, promoting Microsoft (and sometimes Windows) instead of competing against them
GNU/Linux Climbs to Record Levels in Switzerland. Can the EU, Norway, the UK, and Switzerland Divorce GAFAM?
Germany openly speaks about becoming independent from the US. How about Switzerland?
Gemini Links 05/03/2025: Living in Interesting Times, Font, and Social Control Media with Gos v1.0.0
Links for the day
Use RSS Readers Instead of Social Control Media
RSS readers were designed to save time. Social Control Media was designed to waste time.
The 'Windows Era' Already Came to an End
Microsoft said to shareholders everything would be alright because of "clown computing" and then "hey hi"
The Fall of the Open Source Initiative (OSI): Microsoft Committing the Largest GPL Violation in Human History, Then OSI Covering That Up on Microsoft's Payroll
LLMs don't make GPL violations any more noble or acceptable; it's not hard to see what OSI was paid by Microsoft for
Social Control Media as a Rapid Race to the Bottom - Part II - Think Before You Talk
The 'socmed' nonsense does not exist in our home
Links 04/03/2025: Hardware, Health, Data Breaches, Politics
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Tuesday, March 04, 2025
IRC logs for Tuesday, March 04, 2025
Luxembourg: GNU/Linux at 8% Based on Estimates
steady increases this year
Gemini Links 04/03/2025: Bicycle, Photos, and Motorola 6809 Assemblers
Links for the day
Crossbow tragedy, bigger than Kyle Clifford, social media culture
Reprinted with permission from Daniel Pocock
Microsoft OSI Apparently Still Reading Techrights Closely, Trying to Make Face-Saving PR Moves
They have long had this reactionary rhythm, wherein it feels like we can 'control' what they publish and when by merely highlighting facts about them
Links 04/03/2025: Microsoft/Korea Game Industry Association Workforce Cuts, Outlook and 365 Outage Affects Very Many
Links for the day
Transcript of Richard Stallman's Interview With Manuel Cuda News in Italy (Debunking Fake "AI")
A rough draft, but checked by two people
Chad: All-Time Lows for Windows, According to statCounter
According to statCounter, many in Chad moved to Android
Links 04/03/2025: Universities Are Under Attack, Windows Attracts Ransom Against Ministry of Health
Links for the day
Microsoft Collapses While GNU/Linux Rises in Bulgaria, According to statCounter
Microsoft is losing across all sectors
The Fall of the Open Source Initiative (OSI): An Introduction
In a nutshell: there's a massive conflict inside the OSI and the OSI stooges (staff serving Big Sponsors like Microsoft) try to hide it
Paraguay: GNU/Linux Surging to New Usage Levels (7%), According to statCounter
Notice that the gains are at Microsoft Windows' expense
Social Control Media as a Rapid Race to the Bottom - Part I - That Sinking Feeling
When you realise you made an error and things you adopted more than 15 years ago became utterly bad
Microsoft's Entryism as Mortal Risk/Danger: The Example of the Open Source Initiative (OSI)
Microsoft is a cult
Links 04/03/2025: Microsoft Issues Policy Instructions to the Cheeto Mussolini Administration, Cloudflare Engages in Mass Censorship Again
Links for the day
Gemini Links 04/03/2025: Athens, Fedora 41, and Yelling at Clouds
Links for the day
FSF Amicus Brief: Aspose.PDF for .NET 24.2.0, OOXML (.docx), and Microsoft Word (Proprietary)
Could the FSF not find any law firm that, in addition to talking about or for Free software, does not use .NET, OOXML, and almost everything Microsoft?
New Interview With Richard Stallman in Italy (Manuel Cuda News)
Due to Google's growing aggression against Free software and proper APIs, this cannot be downloaded and converted to a free format
The Free Software Foundation (FSF) Belatedly Comments on Case That Tests Copyleft in the United States
"The Free Software Foundation (FSF) announced today it has submitted an amicus brief in the case entitled Neo4j"
If They Try to Censor You on Some Topic, Then You Should Cover This Topic Even More
OSI is only a small part of it
The UEFI hype and Microsoft's lies
By Sami Tikkanen
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Monday, March 03, 2025
IRC logs for Monday, March 03, 2025
Thorsten Glaser & Open Source Initiative (OSI) resignations due to AI whitewashing
Reprinted with permission from Daniel Pocock