Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Process memory usage and fix process state update #1516

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix lint warnings and reformat output
bensheldon committed Nov 16, 2024

Verified

This commit was signed with the committer’s verified signature.
vbudhram Vijay Budhram
commit f1d8e46af3f7d0921c4d686e2e6a73156c796d77
36 changes: 17 additions & 19 deletions app/models/good_job/process.rb
Original file line number Diff line number Diff line change
@@ -14,25 +14,23 @@ class Process < BaseRecord
EXPIRED_INTERVAL = 5.minutes
PROCESS_MEMORY = case RUBY_PLATFORM
when /linux/
->(pid) {
begin
File.readlines("/proc/#{pid}/smaps_rollup").each do |line|
next unless line.start_with?('Pss:')

break line.split[1].to_i
end
rescue Errno::ENOENT
File.readlines("/proc/#{pid}/status").each do |line|
next unless line.start_with?('VmRSS:')

break line.split[1].to_i
end
end
}
lambda do |pid|
File.readlines("/proc/#{pid}/smaps_rollup").each do |line|
next unless line.start_with?('Pss:')

break line.split[1].to_i
end
rescue Errno::ENOENT
File.readlines("/proc/#{pid}/status").each do |line|
next unless line.start_with?('VmRSS:')

break line.split[1].to_i
end
end
when /darwin|bsd/
->(pid) {
`ps -o pid,rss -p #{pid}`.lines.last.split.last.to_i
}
lambda do |pid|
`ps -o pid,rss -p #{pid.to_i}`.lines.last.split.last.to_i
end
else
->(_pid) { 0 }
end
@@ -81,7 +79,7 @@ def self.cleanup
end

def self.memory_usage(pid)
(PROCESS_MEMORY.call(pid) / 1024).to_i
PROCESS_MEMORY.call(pid)
end

def self.find_or_create_record(id:, with_advisory_lock: false)
2 changes: 1 addition & 1 deletion app/views/good_job/processes/index.html.erb
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
<span class="badge rounded-pill bg-body-secondary text-secondary"><%= process.state["pid"] %></span>
<span class="text-muted small">@</span>
<span class="badge rounded-pill bg-body-secondary text-secondary"><%= process.state["hostname"] %></span>
<span class="badge rounded-pill bg-body-secondary text-secondary"><%= process.state["memory"] %>mb</span>
<span class="badge rounded-pill bg-body-secondary text-secondary"><%= (process.state["memory"] / 1024).to_i %> MB</span>
</div>
</div>
<div class="col">
29 changes: 26 additions & 3 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@
"check_name": "SQL",
"message": "Possible SQL injection",
"file": "app/models/good_job/job.rb",
"line": 140,
"line": 135,
"link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",
"code": "Arel.sql(\"(CASE #{queues.map.with_index do\n sanitize_sql_array([\"WHEN queue_name = ? THEN ?\", queue_name, index])\n end.join(\" \")} ELSE #{queues.size} END)\")",
"render_path": null,
@@ -68,8 +68,31 @@
89
],
"note": "Developer provided value, queue_name, is sanitized."
},
{
"warning_type": "Command Injection",
"warning_code": 14,
"fingerprint": "dbb80167f57edebfd9da72e1278d425095a0329755e24d3c50e0fda6bb21c097",
"check_name": "Execute",
"message": "Possible command injection",
"file": "app/models/good_job/process.rb",
"line": 32,
"link": "https://brakemanscanner.org/docs/warning_types/command_injection/",
"code": "`ps -o pid,rss -p #{pid.to_i}`",
"render_path": null,
"location": {
"type": "method",
"class": "Process",
"method": null
},
"user_input": "pid.to_i",
"confidence": "Medium",
"cwe_id": [
77
],
"note": ""
}
],
"updated": "2024-07-18 18:05:56 -0700",
"brakeman_version": "6.1.2"
"updated": "2024-11-16 17:00:20 -0600",
"brakeman_version": "6.2.1"
}