GithubHelp home page GithubHelp logo

dshb's Introduction

dshb

A macOS system monitor in Swift, inspired by top & htop. Displays live readings of system CPU & memory usage, machine temperature sensors, fan speeds, battery information and other miscellaneous system statistics. The ncurses based TUI (text-based user interface) uses color coating to imply status and is fully resizable. Stats are updated at one second intervals while still maintaining low overhead (the observer effect is inescapable in this case sadly).

alt text

Why?

  • Exploration of Swift. In particular, systems programming and interfacing with low-level C APIs

Homebrew 🍺

$ brew install dshb

Requirements

Clone

Make sure to use the recursive option on clone to auto init all submodules.

git clone --recursive https://github.com/beltex/dshb

Incase you have already cloned the repository, run the following inside the project directory.

git submodule update --init

Install

This will build dshb from source and place the binary and manual page in your path.

make install

Stack

  • ncurses
    • For drawing to the terminal (tested with version 5.4 - default on macOS)
  • SystemKit
    • For almost all statistics
  • SMCKit
    • For temperature & fan statistics
  • CommandLine
    • For the CLI
  • ronn
    • For generating the manual page

All Git submodules are built part of the project as simply source files, not frameworks (which are essentially dynamic libraries). This is because currently, the Swift runtime dynamic libraries must be packaged with the application in question. In the case of dshb, a single binary is generated which has the runtime statically linked. Thus, frameworks, which expect to find the libraries inside the application bundle (.app), cannot "see" them.

For more see:

References

License

This project is under the MIT License.

P.S.

Working on this always brought a smile to my face. I hope it brings a smile to yours too. Enjoy :)

dshb's People

Contributors

alexpovh avatar beltex avatar

Stargazers

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

Watchers

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

dshb's Issues

Test on OS X 10.11 El Capitan

  • Early, but opening this up as a placeholder nonetheless
  • Hope to get a machine setup with 10.11 sometime soon
  • Any feedback from those already on 10.11 would be greatly appreciated! :)
  • Don't expect much to have changed, but if there's any issues it'll be with SMCKit & SystemKit
  • Main concern is actually with the new System Integrity Protection ("rootless") functionality, which will affect #8/#13. Will open separate issue for that

Update to Xcode 7 GM seed 1

Apple Swift version 2.0 (swiftlang-700.0.57.3 clang-700.0.72)
Apple Swift version 2.0 (swiftlang-700.0.59 clang-700.0.72)

This update will require breaking changes.

  • For dshb itself, just a one line change with the replacement of String.extends() with String.appendContentsOf(). However, there is the new try? functionality that should be useful, will explore
  • PR for CommandLine submitted: jatoben/CommandLine#29
  • SMCKit & SystemKit should be fine as is at first glance

Performance benchmarking

Means to measure the following:

  • Boot time
  • Window resize CPU spike
  • User input responsiveness
  • CPU & memory usage

Would allow us to benchmark against top & htop. Also, to catch regressions in performance. Related (possibly add performance tests via XCTest):

Add support for the Swift Package Manager

A continuation of #19.

It's still early, but it would be great to add it. Implies support for the open-source version of Swift. Dependencies will each need a Package.swift file added to them. CommandLine has already done so.

Build from command line

  • Will help with #1
  • Handy to have in general
  • Simple shell script using xcodebuild tools and the like?

Investigate System Integrity Protection on 10.11

  • As a part of #26
  • OS X 10.11 has a new System Integrity Protection ("rootless") feature enabled by default
  • "A new security policy that applies to every running process, including privileged code and code that runs out of the sandbox. The policy extends additional protections to components on disk and at run-time, only allowing system binaries to be modified by the system installer and software updates. Code injection and runtime attachments are no longer permitted." - via What's New in OS X Apple doc
  • The most detail I've seen on this so far is via the 706 session, Security and Your Apps talk (WWDC 2015)
  • Will need to play around with it in 10.11 still to get a better understanding
  • You can disable it, however, requires booting to recovery partition to do so
  • The main concern here is of course with SystemKit and process lists (beltex/SystemKit#10, #8, #13). While it won't block the feature entirely, as we can get basic process info without root, we won't be able to match top(1) or Activity Monitor without it either

Makefile manual page path shouldn't assume Homebrew is installed

when i do the "make install" everything goes as plans and the build succeeded but there's something at then end that i don't understand;

> Check dependencies
> 
> ** BUILD SUCCEEDED **
> 
> mkdir -p bin
> cp build/Release/dshb bin
> strip bin/dshb
> cp bin/dshb /usr/local/bin
> cp doc/dshb.1 /usr/local/share/man/man1
> cp: /usr/local/share/man/man1: No such file or directory
> make: *** [install] Error 1

Source code archives are missing Git submodules

This is not a dshb issue per se, but it does affect it, and so opening this up as a means to track things. Quoting 273c6a1 commit message.

git-archive(1) unfortunately does not currently support including submodules in the archive it creates. This seems to be why both the "Download Zip" option on GitHub and the "Source code" tar and zip that comes with a release are missing submodules, as there using git-archive(1) underneath it seems [1]. There was a discussion a few months back on the Git mailing list about adding this functionality [2]. In the mean time we need a work around. Not only to have a real archive (the current ones won't work at all as there not real Git repos, so you can't even init the submodules), but also for folks who don't have Git or don't want to use it, they can just curl/Wget the archive and be able to build. There are various scripts out there to address this. However, they do a lot more than what we need and add yet another dependency. Thus, came up with a small shell script to do this. Added two methods of doing this to the Makefile for now.

The key problem in doing this is ignoring files in the .gitignore (which git-archive(1) does automatically). The first approach does everything locally, archiving the main repo and all the submodules individually and then putting all that together. The second approach which is simpler, but relies on remote, does a fresh clone, init's the submodules and zip's all that. This works because the repo being new is free of any files in the .gitignore (except for .git/ but thats easy to exclude via zip).

There is another option, even simpler, in which we just zip the current directory and feed in .gitignore into zip's exclude option. However, zip's exclude is a bit strange, had trouble with this approach.

[1] https://blogs.law.harvard.edu/acts/2012/10/18/github-zip-doesnt-include-submodules/#comment-975
[2] http://www.mail-archive.com/git%40vger.kernel.org/msg68665.html

Sort proc list

  • Can be sorted by any proc metric - pid, cpu, mem, etc.
  • top does this via red–black tree (could use AVL tree?)
  • Solution might be added to SystemKit actually
  • Pre-req: beltex/SystemKit#10

Update to Swift 1.2

  • Sadly, Xcode 6.3 Beta 1 has dropped support for Mavericks, so I’ve yet to have a chance to do this (still on 10.9 :))
  • Will require changes to libs as well. In the case of CommandLine, may need to temporarily fork

fatal error: subscript: subRange extends past String end

fatal error: subscript: subRange extends past String end
Illegal instruction: 4

This has happened a couple times while I've had a terminal open in the background with dshb running.

In both cases the cursor has been located at the point where fan speeds are displayed, if that helps narrow it down. Screenshot:

screen shot 2016-03-13 at 11 26 11 am

Add support for disk usage statistics

Hi there!

So, is very strange for me coming from Windows environment deal with no info about transferring time or speeds. At Windows We have the indicator like "90MB/s" but in Mac Os is totaly blindness. oO

I tryout use some "free apps" but none of then really do what Windows does. And one called "Speed" (blue icon) do some trick with bash commands but with large files stay "quiet". He does Zipping before transfering. And Makes me nervous.

I wanted something like the "Task manager". Who says the use of the HDD/SDD, says about IO use, speeds and so on. But there's nothing close to this on AppStore.

So, there is. Best Regards.

Xcode 7 Beta 1: Darwin.ncurses module no longer links ncurses automatically

import Darwin.ncurses in Xcode 7 Beta 1 no longer automatically links ncurses for you, has to be done manually. This does not seem to be intended behaviour. Apple has changed some stuff related to frameworks in Xcode 7 that has caused a known issue, which seems to be the culprit [1]. They have introduced .tbd files, "'text-based stub libraries', that provide a much more compact version of the stub libraries for use in the SDK, and help to significantly reduce its download size." This is the format that libncurses is listed as now, not as a .dylib.

One workaround is to manually add libncurses.dylib to the build phases setting in Xcode (see 5baea59).

[1] https://forums.developer.apple.com/message/8609#8609

Integrity checks

  • Since we need root, would be nice to have integrity checks of the app binary
  • Checksum? shasum -a384 dshb
  • Code signed with Apple cert (though carries a yearly cost)
    • Self signed cert?

Update to Swift 2.0

  • There's a lot to still go through after todays release
  • Likely will keep changes in a separate branch for a while
  • Not sure how Homebrew handles beta releases of Xcode
  • As mentioned, would be nice to get #20 going as well for this

Update to Swift 2.3 or 3

Hi, Homebrew maintainer here.

El Capitan and Sierra folks are on Xcode 8 (with Swift 3 or 2.3) already so dshb no longer builds:

==> make release
xcodebuild -configuration Release build
=== BUILD TARGET dshb OF PROJECT dshb WITH CONFIGURATION Release ===

Check dependencies
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)
make: *** [build] Error 65

Could you please update to Swift 2.3 or 3 and cut a new release? Otherwise we'll have to move the formula to boneyard. Thanks.

Custom colour schemes

  • Use colour scheme template from an editor (Vim, Atom, TextWrangler, etc.)
  • Set via dot file? - .dshb
  • Factor in terminal colour scheme
  • Have base set of themes. For more, add via custom config. Do not want to have indefinite number of them added to repo (see oh-my-zsh)

ncurses graphs

  • Like Activity Monitor or iStat Pro
  • Can use this for CPU, network, etc.

Git submodules use SSH URLs requiring GitHub account

cam$ git clone --recursive https://github.com/beltex/dshb

Cloning into 'dshb'...
remote: Counting objects: 810, done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 810 (delta 106), reused 82 (delta 82), pack-reused 679
Receiving objects: 100% (810/810), 259.62 KiB | 0 bytes/s, done.
Resolving deltas: 100% (545/545), done.
Checking connectivity... done.
Submodule 'libs/CommandLine' ([email protected]:jatoben/CommandLine.git) registered for path 'libs/CommandLine'
Submodule 'libs/SMCKit' ([email protected]:beltex/SMCKit.git) registered for path 'libs/SMCKit'
Submodule 'libs/SystemKit' ([email protected]:beltex/SystemKit.git) registered for path 'libs/SystemKit'
Cloning into 'libs/CommandLine'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Clone of '[email protected]:jatoben/CommandLine.git' into submodule path 'libs/CommandLine' failed

Handle terminal window resize

  • Need signal handler for SIGWINCH
  • Use Darwin signal handler instead of signal.h?
    • GCD seems to be the best way to go about it, see here

Create Homebrew formula

Update

  • Formula is ready to go. See Gist
  • Whoever would like to submit to Homebrew, feel free to do so!
  • As the project author, I can't :)
  • Keep in mind though, there is no guarantee that it will be accepted, as it may not be popular enough, etc., which is totally cool.

Use Git submodules for adding SMCKit & SystemKit

  • Manually adding them is prone to mistakes and adds noise to commits
  • Git submodules at a bit of complexity, but make things cleaner ultimately and we won't be performing any changes in those submodules
  • This should all be temporary until CocoaPods has full Swift support

Failed build

latest commit: ee48c78

** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
make: *** [build] Error 65

homebrew notes this formulae as deprecated or disabled.

I like dshb - works fine but is there any concern re the warning?

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
dshb

➜  ~ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  dshb

Warning: You are using macOS 10.13.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
old version.

➜  ~ 

Stat dependent update frequency

  • Something that could be handy
  • Be able to update stats at a frequency that makes sense for the stat in question. So for example, uptime would really only be useful every minute, rather than every second. As would say battery life. No need to poll frequently in those cases
  • The point being, that by having stat dependent timers, you could reduce CPU usage (less work on every update)
  • Stat config seen in #4 & #14, will help as well for this

Add debug logging

  • Can't print to stdout since were using ncurses
  • Log to a file?
  • top has a special print function, have to look into it further
  • Keep in mind the debug logging in SystemKit & SMCKit won't work either

Slightly cleaner way to do getUsername()

I had a look at getUsername and saw that it could be a little cleaner - in fact I suspect the current version has a small memory leak. My version below for what its worth.
`
func getUsername(_ uid: uid_t) -> String
{
let username: String
var passwdInfo = passwd()
var result: UnsafeMutablePointer? = nil

let bufferSize = sysconf(_SC_GETPW_R_SIZE_MAX)
var buffer = [Int8](repeating: 0, count: bufferSize)

if getpwuid_r(uid, &passwdInfo, &buffer, bufferSize, &result) == 0,
   result != nil {
	username = String(cString: passwdInfo.pw_name)
} else {
	username = String(Int(uid))
}

return username

}`

Explore possibility of Linux & *BSD support

With Swift now being open-source, this is possible, especially with the inclusion of GCD and Foundation as part of the core libs (though they are still in development). It would certainly be an interesting exercise, but would likely depend on how much interest their would be. Collecting stats for each of these platforms can be quite varied and thus a fair amount of work. Probably would want OS X support to get to a "stable" level before diving into this.

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.