├── .gitignore ├── spec ├── spec_helper.cr └── mastodon-stats_spec.cr ├── src ├── mastodon-stats │ ├── version.cr │ ├── instance.cr │ └── scrape.cr └── mastodon-stats.cr ├── shard.yml ├── shard.lock ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /doc/ 2 | /lib/ 3 | /bin/ 4 | /.shards/ 5 | /*.sublime* 6 | -------------------------------------------------------------------------------- /spec/spec_helper.cr: -------------------------------------------------------------------------------- 1 | require "spec" 2 | require "../src/mastodon-stats" 3 | -------------------------------------------------------------------------------- /src/mastodon-stats/version.cr: -------------------------------------------------------------------------------- 1 | module Mastodon::Stats 2 | VERSION = "0.1.0" 3 | end 4 | -------------------------------------------------------------------------------- /src/mastodon-stats.cr: -------------------------------------------------------------------------------- 1 | require "./mastodon-stats/*" 2 | 3 | module Mastodon::Stats 4 | end 5 | 6 | Mastodon::Stats::Scrape.new.go 7 | -------------------------------------------------------------------------------- /spec/mastodon-stats_spec.cr: -------------------------------------------------------------------------------- 1 | require "./spec_helper" 2 | 3 | describe Mastodon::Stats do 4 | # TODO: Write tests 5 | 6 | it "works" do 7 | false.should eq(true) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /shard.yml: -------------------------------------------------------------------------------- 1 | name: mastodon-stats 2 | version: 0.1.0 3 | 4 | crystal: 0.21.1 5 | 6 | license: MIT 7 | 8 | authors: 9 | - Don Park 10 | 11 | targets: 12 | mastodon-stats: 13 | main: src/mastodon-stats.cr 14 | 15 | -------------------------------------------------------------------------------- /shard.lock: -------------------------------------------------------------------------------- 1 | version: 1.0 2 | shards: 3 | kemal: 4 | github: kemalcr/kemal 5 | commit: 0b4856b7417592743a27fc3e30867fd141395bf6 6 | 7 | kilt: 8 | github: jeromegn/kilt 9 | version: 0.3.3 10 | 11 | radix: 12 | github: luislavena/radix 13 | version: 0.3.8 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mastodon-stats 2 | 3 | TODO: Write a description here 4 | 5 | ## Installation 6 | 7 | TODO: Write installation instructions here 8 | 9 | ## Usage 10 | 11 | TODO: Write usage instructions here 12 | 13 | ## Development 14 | 15 | TODO: Write development instructions here 16 | 17 | ## Contributing 18 | 19 | 1. Fork it ( https://github.com/[your-github-name]/mastodon-stats/fork ) 20 | 2. Create your feature branch (git checkout -b my-new-feature) 21 | 3. Commit your changes (git commit -am 'Add some feature') 22 | 4. Push to the branch (git push origin my-new-feature) 23 | 5. Create a new Pull Request 24 | 25 | ## Contributors 26 | 27 | - [[your-github-name]](https://github.com/[your-github-name]) Don Park - creator, maintainer 28 | -------------------------------------------------------------------------------- /src/mastodon-stats/instance.cr: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | module Mastodon::Stats 4 | class Instance 5 | @name = nil 6 | @uptime = nil 7 | @up = nil 8 | @ipv6 = nil 9 | @openRegistrations = nil 10 | @users = nil 11 | @statuses = nil 12 | @connections = nil 13 | property name, up, users, statuses, connections 14 | 15 | JSON.mapping( 16 | name: String?, 17 | uptime: Float64?, 18 | up: Bool?, 19 | ipv6: Bool?, 20 | openRegistrations: Bool?, 21 | users: Int64?, 22 | statuses: Int64?, 23 | connections: Int64? 24 | ) 25 | 26 | def initialize 27 | end 28 | 29 | def to_json 30 | JSON.build do |json| 31 | json.object do 32 | json.field "name", @name 33 | json.field "up", @up 34 | json.field "users", @users 35 | json.field "statuses", @statuses 36 | json.field "connections", @connections 37 | end 38 | end 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Don Park 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/mastodon-stats/scrape.cr: -------------------------------------------------------------------------------- 1 | require "http/client" 2 | require "xml" 3 | require "json" 4 | 5 | module Mastodon::Stats 6 | class Scrape 7 | def go 8 | url = "https://instances.mastodon.xyz/instances.json" 9 | response = HTTP::Client.get url 10 | instances = Array(Instance).from_json(response.body) 11 | instances_up = instances.reject { |i| !i.up }.size 12 | instances_open = instances.reject { |i| !i.openRegistrations }.size 13 | instances_users = instances.sum { |i| i.users || 0 } 14 | instances_statuses = instances.sum { |i| i.statuses || 0 } 15 | instances_connections = instances.sum { |i| i.connections || 0 } 16 | puts "#{instances.size} instances. " + 17 | "#{instances_up} up. " + 18 | "#{instances_open} open. " + 19 | "#{instances_users} users. " + 20 | "#{instances_statuses} statuses. " + 21 | "#{instances_connections} connections." 22 | stat_url = "http://localhost:8086/write?db=mastodon" 23 | HTTP::Client.post(stat_url, nil, "instances_count value=#{instances.size}") 24 | HTTP::Client.post(stat_url, nil, "instances_up value=#{instances_up}") 25 | HTTP::Client.post(stat_url, nil, "instances_open value=#{instances_open}") 26 | HTTP::Client.post(stat_url, nil, "instances_users value=#{instances_users}") 27 | HTTP::Client.post(stat_url, nil, "instances_statuses value=#{instances_statuses}") 28 | HTTP::Client.post(stat_url, nil, "instances_connections value=#{instances_connections}") 29 | end 30 | end 31 | end 32 | --------------------------------------------------------------------------------