Compare commits

...

6 Commits

Author SHA1 Message Date
Emilien Devos a0052d6eaa use directly the exception message when priting the error message 2024-04-21 22:40:36 +02:00
Emilien Devos 496acbdd7f add comment for read only key 2024-04-21 22:39:36 +02:00
Emilien Devos 51513d16a8 errorStats parameter does not exist anymore removing 2024-04-21 22:38:45 +02:00
Emilien Devos 177c403a89 add support for updown.io 2024-04-21 22:36:04 +02:00
TheFrenchGhosty a4c097175f Updown debut implementation - currently broken 2024-04-21 21:38:25 +02:00
Émilien (perso) bd6bfce1c3
update crystal version + shards lib (#48) 2024-04-21 21:36:03 +02:00
6 changed files with 33 additions and 44 deletions

View File

@ -16,9 +16,9 @@ jobs:
- uses: actions/checkout@v2
- name: Install Crystal
uses: oprypin/install-crystal@v1
uses: crystal-lang/install-crystal@v1.8.1
with:
crystal: 1.0.0
crystal: 1.10.1
- name: Cache Shards
uses: actions/cache@v2

View File

@ -1,12 +1,12 @@
FROM docker.io/crystallang/crystal:1.0.0-alpine AS builder
FROM crystallang/crystal:1.10.1-alpine AS builder
WORKDIR /app
COPY ./shard.yml ./shard.yml
RUN shards install
COPY ./src/ ./src/
RUN crystal build ./src/instances.cr --release
FROM alpine:latest
RUN apk add --no-cache gc pcre libgcc
FROM alpine:3.18
RUN apk add --no-cache gc pcre2 libgcc
WORKDIR /app
RUN addgroup -g 1000 -S invidious && \
adduser -u 1000 -S invidious -G invidious

View File

@ -2,21 +2,16 @@ version: 2.0
shards:
backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.1
version: 1.2.2
exception_page:
git: https://github.com/crystal-loot/exception_page.git
version: 0.2.0
version: 0.3.1
kemal:
git: https://github.com/kemalcr/kemal.git
version: 1.0.0+git.commit.218be2422172d330feb62c6a8abc7df5402fdb84
kilt:
git: https://github.com/jeromegn/kilt.git
version: 0.6.1
version: 1.4.0
radix:
git: https://github.com/luislavena/radix.git
version: 0.4.1

View File

@ -1,8 +1,9 @@
name: instances
version: 0.1.0
version: 0.2.0
authors:
- Omar Roth <omarroth@protonmail.com>
- Invidious team
targets:
instances:
@ -11,8 +12,8 @@ targets:
dependencies:
kemal:
github: kemalcr/kemal
branch: master
version: ~> 1.4.0
crystal: 1.0.0
crystal: 1.10.1
license: AGPLv3

View File

@ -31,25 +31,18 @@ INSTANCES = {} of String => Instance
spawn do
loop do
monitors = [] of JSON::Any
page = 1
loop do
begin
client = HTTP::Client.new(URI.parse("https://stats.uptimerobot.com/89VnzSKAn"))
client.connect_timeout = 10.seconds
client.read_timeout = 10.seconds
response = JSON.parse(client.get("/api/getMonitorList/89VnzSKAn?page=#{page}").body)
monitors += response["psp"]["monitors"].as_a
page += 1
break if response["psp"]["perPage"].as_i * (page - 1) + 1 > response["psp"]["totalMonitors"].as_i
rescue ex
error_message = response.try &.as?(String).try &.["errorStats"]?
error_message ||= ex.message
puts "Error pulling monitors: #{error_message}"
break
end
begin
client = HTTP::Client.new(URI.parse("https://updown.io/p/wqufo"))
client.connect_timeout = 10.seconds
client.read_timeout = 10.seconds
# Read only key for accessing the uptime checks
response = JSON.parse(client.get("/api/checks?api-key=ro-52iHyp6LBqQq7rGp4N7p").body)
monitors += response.as_a
rescue ex
puts "Error pulling monitors: #{ex.message}"
break
end
begin
body = HTTP::Client.get(URI.parse("https://raw.githubusercontent.com/iv-org/documentation/master/docs/instances.md")).body
rescue ex
@ -98,7 +91,7 @@ spawn do
end
end
monitor = monitors.try &.select { |monitor| monitor["name"].try &.as_s == host }[0]?
monitor = monitors.try &.select { |monitor| monitor["alias"].try &.as_s == host }[0]?
instances[host] = {flag: flag, region: region, stats: stats, cors: cors, api: api, type: type, uri: uri.to_s, monitor: monitor || instances[host]?.try &.[:monitor]?}
end
@ -151,15 +144,15 @@ static_headers do |response, filepath, filestat|
end
SORT_PROCS = {
"health" => ->(name : String, instance : Instance) { -(instance[:monitor]?.try &.["30dRatio"]["ratio"].as_s.to_f || 0.0) },
"location" => ->(name : String, instance : Instance) { instance[:region]? || "ZZ" },
"health" => ->(alias : String, instance : Instance) { -(instance[:monitor]?.try &.["uptime"].as_s.to_f || 0.0) },
"location" => ->(alias : String, instance : Instance) { instance[:region]? || "ZZ" },
"name" => ->(name : String, instance : Instance) { name },
"signup" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
"type" => ->(name : String, instance : Instance) { instance[:type] },
"cors" => ->(name : String, instance : Instance) { instance[:cors] == nil ? 2 : instance[:cors] ? 0 : 1 },
"api" => ->(name : String, instance : Instance) { instance[:api] == nil ? 2 : instance[:api] ? 0 : 1 },
"users" => ->(name : String, instance : Instance) { -(instance[:stats]?.try &.["usage"]?.try &.["users"]["total"].as_i || 0) },
"version" => ->(name : String, instance : Instance) { instance[:stats]?.try &.["software"]?.try &.["version"].as_s.try &.split("-", 2)[0].split(".").map { |a| -a.to_i } || [0, 0, 0] },
"signup" => ->(alias : String, instance : Instance) { instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? 0 : 1 } || 2 },
"type" => ->(alias : String, instance : Instance) { instance[:type] },
"cors" => ->(alias : String, instance : Instance) { instance[:cors] == nil ? 2 : instance[:cors] ? 0 : 1 },
"api" => ->(alias : String, instance : Instance) { instance[:api] == nil ? 2 : instance[:api] ? 0 : 1 },
"users" => ->(alias : String, instance : Instance) { -(instance[:stats]?.try &.["usage"]?.try &.["users"]["total"].as_i || 0) },
"version" => ->(alias : String, instance : Instance) { instance[:stats]?.try &.["software"]?.try &.["version"].as_s.try &.split("-", 2)[0].split(".").map { |a| -a.to_i } || [0, 0, 0] },
}
def sort_instances(instances, sort_by)

View File

@ -121,7 +121,7 @@
<td><%= instance[:stats]?.try &.["usage"]?.try &.["users"]["total"] || "-" %></td>
<td><%= instance[:stats]?.try &.["openRegistrations"]?.try { |bool| bool.as_bool ? "✔" : "❌" } || "-" %></td>
<td><%= instance[:flag]? ? "#{instance[:flag]} #{instance[:region]}" : "-" %></td>
<td><%= instance[:monitor]?.try &.["30dRatio"]["ratio"] || "-" %></td>
<td><a href='https://updown.io/<%= instance[:monitor]?.try &.["token"] || "p/resvf" %>'><%= instance[:monitor]?.try &.["uptime"] || "-" %></a></td>
<td><%= instance[:cors] == nil ? "-" : instance[:cors] ? "✔" : "❌" %></td>
<td><%= instance[:api] == nil ? "-" : instance[:api] ? "✔" : "❌" %></td>
</tr>