Code Monkey home page Code Monkey logo

cmon's People

Contributors

cwalsh003 avatar marshyski avatar peterfraedrich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cmon's Issues

Implement Process Info

Implement library github.com/shirou/gopsutil/process under the system package. The library will handle OS compatibility.

  1. Get a list of all system processes
  2. Parse each process for Name, CPU Percent, Memory Percent, PID, PPID, and Username into a string
  3. Append the string to an array

Mostly working example:

package main

import (
	"fmt"

	"github.com/shirou/gopsutil/process"
)

func main() {
	processes, err := process.Processes()
	if err != nil {
		return
	}

	for _, proc := range processes {
		pid := proc.Pid

		ppid, _ := proc.Ppid()

		name, err := proc.Name()
		if err != nil {
			name = "UNKNOWN"
		}

		username, err := proc.Username()
		if err != nil {
			username = "UNKNOWN"
		}

		var cpuPct int
		cpuFloat, err := proc.CPUPercent()
		if err == nil {
			cpuPct = int(cpuFloat)
		}

		var memPct int
		memFloat, err := proc.MemoryPercent()
		if err == nil {
			memPct = int(memFloat)
		}

		fmt.Printf("pid=%d ppid=%d name=%s user=%s cpu_pct=%d mem_pct=%d\n", pid, ppid, name, username, cpuPct, memPct)
	}
}

JSON output:

"processes": ["pid=191321 ppid=191281 name=code user=timski cpu_pct=5 mem_pct=0","pid=173684 ppid=2 name=kworker/u24:7-kcryptd/254:0 user=root cpu_pct=0 mem_pct=0","pid=158019 ppid=59419 name=/usr/bin/python3 user=timski cpu_pct=0 mem_pct=0","pid=66657 ppid=66570 name=slack user=timski cpu_pct=2 mem_pct=0"]

Implement lsmod for Linux systems

Implement command lsmod | grep -v Module under the system package.

  1. Check if the system is Linux.
  2. Parse the output of lsmod | grep -v Module
  3. Remove extra tabs/spaces between columns
  4. Store List of Key Values as a string array

Raw output:

pinctrl_intel          28672  2 pinctrl_cannonlake
wmi                    32768  4 intel_wmi_thunderbolt,wmi_bmof,msi_wmi,mxm_wmi
video                  49152  2 msi_wmi,i915

JSON output:

"loaded_kernel_modules": ["pinctrl_intel 28672 2 pinctrl_cannonlake", "wmi 32768 4 intel_wmi_thunderbolt,wmi_bmof,msi_wmi,mxm_wmi", "video 49152 2 msi_wmi,i915"]

Implement sysctl for NIX hosts

Implement command sysclt -a under system package.

  1. Check if the system is not Windows (Run on *NIX only)
  2. Parse the output of sysctl -a
  3. Store List of Key Values as a string array

Raw output:

vm.swappiness = 1
vm.unprivileged_userfaultfd = 1
vm.user_reserve_kbytes = 131072

JSON output:

"sysctl": ["vm.swappiness = 1", "vm.unprivileged_userfaultfd = 1", "vm.user_reserve_kbytes = 131072"]

Implement machine/chassis type

Implement command dmidecode --string chassis-type under the system package. The command should only run on Linux.

  1. Run command
  2. Lower case the output, you should see something like Other, Laptop, Notebook, Portable, etc.

JSON output:

"chassis_type": "other"

CircleCI to GitHub Actions

Convert this current CircleCI CI project into a GitHub Actions project.

Implement some of the CI technologies we implemented in our reference projects.

Systemd Timers

Implement command systemctl list-timers --all --no-pager | grep -v 'NEXT\|listed' under system package.

Check if the system is not Windows (Run on Linux only)
Parse the table output of systemctl
Store List of table entries
Raw output:

Thu 2020-11-19 14:31:46 EST 9min left     Thu 2020-11-19 13:33:12 EST 49min ago    anacron.timer                anacron.service               
Thu 2020-11-19 19:50:39 EST 5h 28min left Thu 2020-11-19 11:29:13 EST 2h 53min ago fwupd-refresh.timer          fwupd-refresh.service         
Fri 2020-11-20 00:00:00 EST 9h left       Thu 2020-11-19 11:29:13 EST 2h 53min ago logrotate.timer              logrotate.service             
Fri 2020-11-20 00:00:00 EST 9h left       Thu 2020-11-19 11:29:13 EST 2h 53min ago man-db.timer                 man-db.service 

JSON output:

"systemd_timers": ["Thu 2020-11-19 14:31:46 EST 6min left     Thu 2020-11-19 13:33:12 EST 51min ago    anacron.timer                anacron.service", "Thu 2020-11-19 19:50:39 EST 5h 25min left Thu 2020-11-19 11:29:13 EST 2h 55min ago fwupd-refresh.timer          fwupd-refresh.service"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.