Linux Engineer @ Snow
twitter.com/@erwindekeijzer
github.com/gnur
https://snow.nl
Erwin de Keijzer
learning anything is a lot easier to be motivated about if you have a problem to solve
Raspberry pi
zero wifi ->
usb -> p1 cable
smart meter
p1 port ->
Text
[Unit]
Description=Limited resources Slice
DefaultDependencies=no
Before=slices.target
[Slice]
CPUShares=1024
MemoryLimit=512M
[Unit]
Description=golpje agent
Requires=network-online.target
After=network-online.target
[Service]
Environment=GOMAXPROCS=2
User=upload
Group=upload
Restart=always
ExecStart=/usr/local/bin/golpje start
KillSignal=SIGINT
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=full
ReadWriteDirectories=/var/lib/golpje /mnt/video
Slice=golpje.slice
CPUAccounting=true
MemoryAccounting=true
[Install]
WantedBy=multi-user.target
golpje.slice
golpje.service
live demo
type Searchmetrics struct {
Enabled bool
Searches prometheus.Counter
FailedSearches prometheus.Counter
SearchResults prometheus.Counter
}
var sm searcher.Searchmetrics
if con.config.GetBool("metrics_enabled") {
sm = searcher.Searchmetrics{
Enabled: true,
Searches: prometheus.NewCounter(
prometheus.CounterOpts{
Name: "golpje_searches",
Help: "total number of searches",
},
),
FailedSearches: prometheus.NewCounter(
prometheus.CounterOpts{
Name: "golpje_failed_searches",
Help: "total number of searches that failed",
},
),
SearchResults: prometheus.NewCounter(
prometheus.CounterOpts{
Name: "golpje_search_results",
Help: "total number of results that have been found",
},
),
}
prometheus.MustRegister(sm.Searches)
prometheus.MustRegister(sm.FailedSearches)
prometheus.MustRegister(sm.SearchResults)
}
func Start(db *storm.DB, piratebayURL string, results chan Searchresult, searchInterval time.Duration, m Searchmetrics) {
pb := piratebay.New(piratebayURL)
for {
shows, err := shows.All(db)
if err != nil {
continue
}
for _, show := range shows {
if m.Enabled {
m.Searches.Inc()
}
torrents, err := pb.Search(show.Name)
if err != nil {
if m.Enabled {
m.FailedSearches.Inc()
}
continue
}
for _, torrent := range torrents {
if m.Enabled {
m.SearchResults.Inc()
}
results <- Searchresult{
Title: torrent.Title,
Magnetlink: torrent.MagnetLink,
Vipuser: torrent.VIP,
Seeders: torrent.Seeders,
ShowID: show.ID,
}
}
}
time.Sleep(searchInterval)
}
}
if con.config.GetBool("metrics_enabled") {
go func() {
http.Handle(con.config.GetString("metrics_path"), promhttp.Handler())
log.Fatal(http.ListenAndServe(con.config.GetString("metrics_port"), nil))
}()
}
Another demo