diff --git a/Gemfile b/Gemfile old mode 100644 new mode 100755 diff --git a/Gemfile.lock b/Gemfile.lock old mode 100644 new mode 100755 index 97c7593..7d3779d --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,14 @@ GEM remote: https://rubygems.org/ specs: + byebug (11.1.3) curb (1.0.5) ethon (0.16.0) ffi (>= 1.15.0) ffi (1.15.5) pastel (0.8.0) tty-color (~> 0.5) + rdebug (0.1) rexml (3.2.6) speedtest_net (0.9.2) curb (>= 0.9, < 2.0) @@ -30,6 +32,8 @@ PLATFORMS x86_64-linux DEPENDENCIES + byebug (~> 11.1) + rdebug (~> 0.1) speedtest_net (~> 0.9.2) tty-prompt (~> 0.23.1) diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 30b4be5..bf39361 --- a/README.md +++ b/README.md @@ -1,3 +1,35 @@ -# arch-info +# System Information Gatherer -A Ruby program for giving info about your Arch Linux system! \ No newline at end of file +## Overview + +This project is a Ruby-based system information gatherer designed to collect various types of system metrics and details. It is built to run on Linux systems and aims to provide a comprehensive view of the system's hardware and software configurations. + +## Features + +- Gather CPU Information +- Collect Disk Information +- Retrieve RAM Details +- Fetch Network Information +- And more... + +## Requirements + +- Ruby >= 3.0 +- Linux-based Operating System +- Sudo permissions for certain metrics + +## Installation + +### Coming Soon + +## Usage + +### Coming Soon + +## Contributing + +Contributions are NOT welcome! Pull Requests will not be merged! + +## License + +This project is licensed under the PixelRidge-BEGPULSE License. See the `LICENSE` file for details. diff --git a/bin/runtime_log.log b/bin/runtime_log.log new file mode 100644 index 0000000..1367f13 --- /dev/null +++ b/bin/runtime_log.log @@ -0,0 +1,10 @@ +Starting system info gathering... \n +Gathering CPU info \n +Gathering RAM info \n +Gathering Disk info \n +Gathering GPU info \n +Gathering Kernel info \n +Gathering Network info \n +Gathering NIC info \n +Gathering OS info \n +Gathering Uptime info \n diff --git a/bin/system_info.log b/bin/system_info.log new file mode 100644 index 0000000..8893454 --- /dev/null +++ b/bin/system_info.log @@ -0,0 +1,36 @@ +{ + "cpu": { + "model": "Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz", + "speed": "3.36 GHz", + "cores": 4, + "threads": 4 + }, + "ram": { + "total_ram": 23, + "used_ram": 4, + "ram_type": "None", + "ram_speed": "2133 MT/s" + }, + "disks": [ + { + "model": "SAMSUNG MZ7PD256", + "type": "SSD", + "transport": "ata" + }, + { + "model": "ST2000DM006-2DM1", + "type": "HDD", + "transport": "ata" + }, + { + "model": "Timetec 30TT253X", + "type": "SSD", + "transport": "ata" + } + ], + "gpu": { + "model": "NVIDIA Corporation GP106 [GeForce GTX 1060 6GB] (rev a1)", + "opengl_driver_version": "4.6.0 NVIDIA 535.104.05", + "vulkan_driver_version": "1.3.264" + } +} diff --git a/bin/systeminfo b/bin/systeminfo old mode 100644 new mode 100755 index 8aa78b4..a6579f3 --- a/bin/systeminfo +++ b/bin/systeminfo @@ -1,14 +1,14 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require_relative '../lib/config_handler' require_relative '../lib/first_run' require_relative '../lib/commands' # Check for config file and create if not exists -config_path = './config/systeminfo_config.yml' -ConfigHandler.ensure_config_exists(config_path) +config_path = '../config/systeminfo_config.yml' -# Load config +FirstRun.setup(config_path) unless ConfigHandler.config_valid?(config_path) config = ConfigHandler.load_config(config_path) # Handle command-line arguments diff --git a/config/systeminfo_config.yml b/config/systeminfo_config.yml new file mode 100644 index 0000000..f0d5e3b --- /dev/null +++ b/config/systeminfo_config.yml @@ -0,0 +1,26 @@ +--- +cpu: true +ram: true +gpu: true +nic_model: true +network_speed: true +os_name: true +kernel_name_version: true +system_uptime: true +disks: true +display_resolution: true +theme: true +desktop_environment: true +window_manager: true +terminal: true +shell: true +hostname: true +board_model: true +chipset: true +amount_of_monitors: true +sound_drivers: true +sound_card: true +display_technology: true +color_bit_depth: true +package_managers: true +file_systems: true diff --git a/lib/commands.rb b/lib/commands.rb old mode 100644 new mode 100755 index 594b60e..59bb76d --- a/lib/commands.rb +++ b/lib/commands.rb @@ -7,8 +7,8 @@ require_relative 'network_info' require_relative 'nic_info' require_relative 'os_info' require_relative 'uptime_info' -require_relative 'config_handler' # Add this line to require the ConfigHandler class -# ... other requires +require_relative 'display_handler' # Add this line to require the DisplayHandler class +require_relative 'config_handler' # Add this line to require the ConfigHandler class module Commands def self.handle(args, config) @@ -27,9 +27,25 @@ module Commands system_info = {} # Run the system info display - system_info[:cpu] = CpuInfo.new.gather_info if config['cpu'] - system_info[:ram] = RamInfo.new.gather_info if config['ram'] - # ... other info gathering + File.open('runtime_log.log', 'w') { |f| f.puts('Starting system info gathering... \n') } + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering CPU info \n') } + system_info[:cpu] = CpuInfo.gather_info if config['cpu'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering RAM info \n') } + system_info[:ram] = RamInfo.gather_info if config['ram'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Disk info \n') } + system_info[:disks] = DiskInfo.gather_info if config['disks'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering GPU info \n') } + system_info[:gpu] = GpuInfo.gather_info if config['gpu'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Kernel info \n') } + system_info[:kernel] = KernelInfo.gather_info if config['kernel'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Network info \n') } + system_info[:network] = NetworkInfo.gather_info if config['network'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering NIC info \n') } + system_info[:nic] = NicInfo.gather_info if config['nic'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering OS info \n') } + system_info[:os] = OsInfo.gather_info if config['os'] + File.open('runtime_log.log', 'a') { |f| f.puts('Gathering Uptime info \n') } + system_info[:uptime] = UptimeInfo.gather_info if config['uptime'] # Pass the collected data to a display handler DisplayHandler.display(system_info) diff --git a/lib/config_handler.rb b/lib/config_handler.rb old mode 100644 new mode 100755 diff --git a/lib/cpu_info.rb b/lib/cpu_info.rb old mode 100644 new mode 100755 index 2c2b1a7..8109c57 --- a/lib/cpu_info.rb +++ b/lib/cpu_info.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class CpuInfo - def gather_info + def self.gather_info cpu_info = {} cores = 0 threads = 0 diff --git a/lib/disk_info.rb b/lib/disk_info.rb old mode 100644 new mode 100755 index eb4bbcd..83e9e18 --- a/lib/disk_info.rb +++ b/lib/disk_info.rb @@ -1,4 +1,4 @@ -require 'json' +# frozen_string_literal: true class DiskInfo def self.gather_info @@ -7,13 +7,28 @@ class DiskInfo # Get additional disk details using `lsblk` command lsblk_output = `lsblk -J`.strip lsblk_json = JSON.parse(lsblk_output) + lsblk_json['blockdevices'].each do |device| - next unless device['type'] == 'disk' # We only want disk devices + next unless device['type'] == 'disk' # We only want disk devices + + # Skip swap partitions + next if device['mountpoints']&.include?('[SWAP]') + + # Determine if the disk is SSD or HDD + rotational_info = File.read("/sys/block/#{device['name']}/queue/rotational").strip + type = rotational_info == '1' ? 'HDD' : 'SSD' + + # Get transport type using udevadm + transport = `udevadm info --query=property --name=#{device['name']} | grep ID_BUS | cut -d= -f2`.strip + + # Get disk model from /sys filesystem + model_path = "/sys/block/#{device['name']}/device/model" + model = File.exist?(model_path) ? File.read(model_path).strip : 'Unknown' disk = { - model: device['model'], - type: device['rota'] == '1' ? 'HDD' : 'SSD', - transport: device['tran'] + model:, + type:, + transport: transport || 'Unknown' } disk_info << disk end diff --git a/lib/display_handler.rb b/lib/display_handler.rb new file mode 100755 index 0000000..bf317b3 --- /dev/null +++ b/lib/display_handler.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'tty-prompt' +require 'json' + +class DisplayHandler + def self.display(system_info) + # Log the entire system_info to a log file + File.open('system_info.log', 'w') do |f| + f.puts(JSON.pretty_generate(system_info)) + end + + prompt = TTY::Prompt.new + + choices = [ + { name: 'OS Info', value: :os }, + { name: 'Hardware Info', value: :hardware }, + { name: 'Network Info', value: :network }, + { name: 'Exit', value: :exit } + ] + + loop do + user_choice = prompt.select('Choose an option:', choices) + + case user_choice + when :os + display_os_info(system_info.slice(:kernel, :os, :uptime)) + when :hardware + display_hardware_info(system_info.slice(:cpu, :ram, :disk, :gpu)) + when :network + display_network_info(system_info.slice(:network, :nic)) + when :exit + break + end + end + end + + def self.display_os_info(os_info) + # Display OS information + puts "\nOS Information:" + puts '---------------' + os_info.each do |key, value| + puts "#{key.capitalize}: #{value}" + end + end + + def self.display_hardware_info(hardware_info) + # Display Hardware information (CPU, RAM, etc.) + puts "\nHardware Information:" + puts '---------------------' + hardware_info.each do |key, value| + puts "#{key.capitalize}: #{value}" + end + end + + def self.display_network_info(network_info) + # Display Network information + puts "\nNetwork Information:" + puts '--------------------' + network_info.each do |key, value| + puts "#{key.capitalize}: #{value}" + end + end +end diff --git a/lib/first_run.rb b/lib/first_run.rb old mode 100644 new mode 100755 index 7bd18a9..825697f --- a/lib/first_run.rb +++ b/lib/first_run.rb @@ -39,7 +39,7 @@ class FirstRun 'file_systems' => prompt.yes?('Do you want to display which file systems the drives are using?') } - File.write(config_path, config.to_yaml) + File.puts(config_path, config.to_yaml) puts 'Configuration saved!' end end diff --git a/lib/gpu_info.rb b/lib/gpu_info.rb old mode 100644 new mode 100755 diff --git a/lib/kernel_info.rb b/lib/kernel_info.rb old mode 100644 new mode 100755 index 620e29e..ac1006b --- a/lib/kernel_info.rb +++ b/lib/kernel_info.rb @@ -10,6 +10,7 @@ class KernelInfo kernel_info[:version] = uname_output if uname_output && !uname_output.empty? # Return the gathered kernel information + File.open('kernel_info.log', 'w') { |f| f.puts(kernel_info.to_json) } kernel_info end end diff --git a/lib/network_info.rb b/lib/network_info.rb old mode 100644 new mode 100755 index e76ba6e..3c5ad4a --- a/lib/network_info.rb +++ b/lib/network_info.rb @@ -5,9 +5,12 @@ require 'speedtest_net' class NetworkInfo def self.gather_info result = SpeedtestNet.run - { + network_info = { download_speed: result.pretty_download, upload_speed: result.pretty_upload } + + File.open('./runtime_log.log', 'w') { |f| f.puts(network_info.to_json) } + network_info end end diff --git a/lib/nic_info.rb b/lib/nic_info.rb old mode 100644 new mode 100755 index ef4e230..d6e9f11 --- a/lib/nic_info.rb +++ b/lib/nic_info.rb @@ -26,6 +26,7 @@ class NicInfo nic_info << info end + File.open('./runtime_log.log', 'w') { |f| f.puts(nic_info.to_json) } nic_info rescue JSON::ParserError [{ model: 'No permission', manufacturer: 'No permission', max_speed: 'No permission' }] diff --git a/lib/os_info.rb b/lib/os_info.rb old mode 100644 new mode 100755 index c034ba6..55a8459 --- a/lib/os_info.rb +++ b/lib/os_info.rb @@ -31,6 +31,7 @@ class OsInfo end os_info[:sound_driver] = sound_driver + File.open('./runtime_log.log', 'w') { |f| f.puts(os_info.to_json) } os_info end end diff --git a/lib/ram_info.rb b/lib/ram_info.rb old mode 100644 new mode 100755 index b622e65..a2081c0 --- a/lib/ram_info.rb +++ b/lib/ram_info.rb @@ -12,7 +12,7 @@ class RamInfo # Get RAM type and speed begin - dmi_data = `sudo dmidecode -t memory`.split("\n").select { |line| line =~ /Type:|Speed:/ } + dmi_data = `sudo dmidecode --type 17`.split("\n") ram_info[:ram_type] = dmi_data.select { |line| line =~ /Type:/ }.first.split(':').last.strip ram_info[:ram_speed] = dmi_data.select { |line| line =~ /Speed:/ }.first.split(':').last.strip rescue StandardError diff --git a/lib/uptime_info.rb b/lib/uptime_info.rb old mode 100644 new mode 100755 index 14d3eea..ab5bdfa --- a/lib/uptime_info.rb +++ b/lib/uptime_info.rb @@ -23,6 +23,7 @@ class UptimeInfo uptime_info[:seconds] = seconds if seconds.positive? # Format the uptime string + File.open('./runtime_log.log', 'w') { |f| f.puts(uptime_info.to_json) } formatted_uptime = uptime_info.map { |k, v| "#{v} #{k.to_s.capitalize}" }.join(' : ') { uptime: formatted_uptime }