Created
May 30, 2012 19:47
-
-
Save bpo/2838527 to your computer and use it in GitHub Desktop.
stats
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
| require 'github_api' | |
| require 'statsd' | |
| github = Github.new login: 'bpo', password: "xxxxx" | |
| s = Statsd.new "stats.stovepipestudios.com" | |
| # Send stvp stats | |
| stvp = github.orgs.get "stvp" | |
| s.gauge "bpo.git.stvp.public_repos", stvp.public_repos | |
| s.gauge "bpo.git.stvp.private_repos", stvp.total_private_repos | |
| # Send bpo stats | |
| bpo = github.users.get "bpo" | |
| s.gauge "bpo.git.bpo.public_repos", bpo.public_repos | |
| s.gauge "bpo.git.bpo.private_repos", bpo.total_private_repos | |
| s.gauge "bpo.git.bpo.public_gists", bpo.public_gists | |
| s.gauge "bpo.git.bpo.private_gists", bpo.private_gists |
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 Stats | |
| metric_set "bpo" do | |
| metric_set "system" do | |
| require 'sys/cpu' | |
| # find size in pages; convert to bytes | |
| def parse_vm_stat(str) | |
| @vm_stat =~ /#{str}:\s*(\d+)\./ | |
| $1.to_i * 4096 | |
| end | |
| every 1.second do | |
| @vm_stat = `vm_stat` | |
| free = parse_vm_stat 'free' | |
| spec = parse_vm_stat 'speculative' | |
| inactive = parse_vm_stat 'inactive' | |
| gauge "free_ram", free + spec | |
| gauge "inactive_ram", inactive | |
| end | |
| every 1.second do | |
| gauge "load_avg", Sys::CPU.load_avg[0] | |
| end | |
| end | |
| metric_set "git" do | |
| require 'github_api' | |
| @github = ::Github.new login: 'bpo', password: "xxxxx" | |
| every 5.minutes do | |
| metric_set "bpo" do | |
| bpo = github.users.get "bpo" | |
| gauge "public_repos", bpo.public_repos | |
| gauge "private_repos", bpo.total_private_repos | |
| gauge "public_gists", bpo.public_gists | |
| gauge "private_gists", bpo.private_gists | |
| end | |
| metric_set "stvp" do | |
| stvp = github.orgs.get "stvp" | |
| gauge "public_repos", stvp.public_repos | |
| gauge "private_repos", stvp.total_private_repos | |
| end | |
| end | |
| end | |
| end | |
| end | |
| Stvp::Stats.run |
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
| while true | |
| pid = fork do | |
| require 'statsd' | |
| require 'sys/cpu' | |
| include Sys | |
| s = Statsd.new "stats.stovepipestudios.com" | |
| def parse(str) | |
| $vm_stat =~ /#{str}:\s*(\d+)\./ | |
| $1.to_i * 4096 | |
| end | |
| 1000.times do | |
| s.increment "bpo.alive" | |
| la = CPU.load_avg[0] | |
| s.gauge "bpo.load_avg", la | |
| $vm_stat = `vm_stat` | |
| free = parse 'free' | |
| spec = parse 'speculative' | |
| s.gauge "bpo.free_ram", free + spec | |
| s.gauge "bpo.inactive_ram", parse('inactive') | |
| sleep 1 | |
| end | |
| end | |
| Process.wait pid if pid | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment