Module: ShieldPressTracker::Metrics

Defined in:
lib/shieldpress_tracker/collectors.rb

Class Method Summary collapse

Class Method Details

.dependenciesObject



113
114
115
116
117
# File 'lib/shieldpress_tracker/collectors.rb', line 113

def self.dependencies
  specs = Gem.loaded_specs.values
  { totalDeps: specs.length, totalVulnerabilities: 0, bySeverity: {}, vulnerabilities: [], outdatedCount: 0,
    lastAuditAt: Time.now.utc.iso8601, packages: specs.first(200).map { |s| { name: s.name, version: s.version.to_s } } }
end

.environmentObject



108
109
110
111
112
# File 'lib/shieldpress_tracker/collectors.rb', line 108

def self.environment
  names = ENV.keys.select { |k| k.match?(/KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL/i) }.first(50)
  { rubyVersion: RUBY_VERSION, rubyPlatform: RUBY_PLATFORM, debugModeEnabled: !!$DEBUG,
    envVarWarnings: names.map { |k| "Potential secret present in environment variable: #{k}" }, securityHeaders: [], opensslVersion: defined?(OpenSSL) ? OpenSSL::OPENSSL_VERSION : nil }
end

.runtimeObject



105
106
107
# File 'lib/shieldpress_tracker/collectors.rb', line 105

def self.runtime
  { threadCount: Thread.list.length, gcCount: GC.stat[:count], heapLiveSlots: GC.stat[:heap_live_slots], rubyEngine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby" }
end

.systemObject



99
100
101
102
103
104
# File 'lib/shieldpress_tracker/collectors.rb', line 99

def self.system
  { cpuPercent: 0, cpuCount: Etc.nprocessors, memUsedMb: 0, memTotalMb: 0, memPercent: 0,
    uptimeSeconds: Process.clock_gettime(Process::CLOCK_MONOTONIC).round, loadAvg: [0, 0, 0], platform: RUBY_PLATFORM,
    rubyVersion: RUBY_VERSION, pid: Process.pid, osName: RbConfig::CONFIG["host_os"], osArch: RbConfig::CONFIG["host_cpu"],
    hostname: Socket.gethostname, cwd: Dir.pwd, execPath: RbConfig.ruby }
end