Last active
September 29, 2018 19:27
-
-
Save ykzts/3a76b90cf492a9e9947e968eeb409598 to your computer and use it in GitHub Desktop.
[WIP]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MastodonMetricsHandler | |
def call(env) | |
host = env['HTTP_HOST'] | |
instance = fetch_instance_meta(host) | |
stats = instance['stats'] | |
headers = { | |
'Content-Type' => 'text/plain; charset=UTF-8', | |
} | |
body = [ | |
'# HELP mastodon_domain_count todo', | |
'# TYPE mastodon_domain_count counter', | |
"mastodon_domain_count #{stats['domain_count']}", | |
'# HELP mastodon_status_count todo', | |
'# TYPE mastodon_status_count counter', | |
"mastodon_status_count #{stats['status_count']}", | |
'# HELP mastodon_user_count todo', | |
'# TYPE mastodon_user_count counter', | |
"mastodon_user_count #{stats['user_count']}", | |
'# HELP mastodon_version_info todo', | |
'# TYPE mastodon_version_info gauge', | |
"mastodon_version_info{version=\"#{instance['version']}\"} 1", | |
].join("\n") | |
[200, headers, [body]] | |
end | |
private | |
def fetch_instance_meta(host) | |
req = http_request("https://#{host}/api/v1/instance") | |
status, headers, body = req.join | |
begin | |
JSON.parse(body.join) | |
rescue | |
{} | |
end | |
end | |
end | |
MastodonMetricsHandler.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mappings: | |
- match: Mastodon\.([^.]*)\.web\.(.*Controller)\.([^.]*)\.([^.]*)\.status\.(\d{3}) | |
match_type: regex | |
name: mastodon_web_request | |
labels: | |
environment: $1 | |
controller: $2 | |
action: $3 | |
format: $4 | |
status: $5 | |
- match: Mastodon\.([^.]*)\.web\.(.*Controller)\.([^.]*)\.([^.]*)\.([^.]*) | |
match_type: regex | |
name: mastodon_web_${5} | |
labels: | |
environment: $1 | |
controller: $2 | |
action: $3 | |
format: $4 | |
- match: "Mastodon.*.db.tables.*.queries.*.duration" | |
name: mastodon_db_${3}_duration | |
labels: | |
environment: $1 | |
table_name: $2 | |
- match: "Mastodon.*.cache.*.duration" | |
name: mastodon_cache_${2}_duration | |
labels: | |
environment: $1 | |
- match: Mastodon\.([^.]*)\.sidekiq\.(.*(?:Worker|Scheduler))\.([^.]*) | |
match_type: regex | |
name: mastodon_sidekiq_${3} | |
labels: | |
environment: $1 | |
worker_name: $2 | |
- match: "Mastodon.*.sidekiq.queues.*.*" | |
name: mastodon_sidekiq_queues_${3} | |
labels: | |
environment: $1 | |
queue_name: $2 | |
- match: "Mastodon.*.sidekiq.*" | |
name: mastodon_sidekiq_${2} | |
labels: | |
environment: $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment