43

Occasionally, I need to check resources on several machines throughout our data-centers for consolidation recommendations and the like. I prefer htop, mostly because of the interactive feel and the display.

Is there a way to default some settings to my setup for htop? For example, one thing I'd like to always have shown is the average CPU load.

important note: Setting this on specific boxes isn't something feasible - I'm looking for maybe a way to set this dynamically every time I ssh into the box.

Is this possible at all?

  • 1
    Isn't that what the numbers for Load averages at the top show? This answer explains what they mean. – Anko Aug 1 '14 at 16:19
40

htop has a setup screen, accessed via F2, that allows you to customize the top part of the display, including adding or removing a "Load average" field and setting it's style (text, bar, etc.).

These seem to be auto saved in $HOME/.config/htop/htoprc, which warns:

# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.

I.e., edit that at your own risk. However, you should be able to transfer it from one system to another (version differences might occasionally cause a bit of an issue).

You could also set up a configuration, quit, and then copy the file, so that you could maintain a set of different configurations by swapping/symlinking whichever one with htoprc.

  • Thanks. I just blindly copied htop config from a good looking server to ugly looking server. It made the ugly looking server look great! – Thamme Gowda Oct 11 '17 at 15:42
  • 1
    Also, note that if you lose permission to your htoprc, such as by accidentally touching it as root/sudo, htop will be unable to update this file and silently fail to save your changes. – Cerin Dec 19 '17 at 0:50
  • @Cerin This is an important point - I think it would be great if the author would add it to their answer. – Amr Bekhit Dec 5 '18 at 6:54
27

The easiest way is to use the setup in the program and then save and exit the program with F10, not with CTRL+C. Next time you can close the program the way you like.

  • 7
    TL;DR: Exit with F10, not CTRL-C. – camomileCase Aug 15 '16 at 19:14
  • At least on linux, quitting with 'Q' also does NOT save your changes... ;( – ljwobker Dec 29 '17 at 0:06
  • 1
    To unbind F10 from opening the terminal window's File menu in Ubuntu, in a terminal window: Edit > Preferences > General: uncheck 'Enable the menu accelerator key (F10 by default)' – David Oliver Nov 29 '18 at 16:20
3

For any Mac users, the htop config file may be located in either of two places:

  1. under a config subdirectory in home: $HOME/.config/htop/htoprc
  2. right at the home directory: $HOME/.htoprc,

The first option (under .config/htop/ is preferred -- as mentioned in htop's manpage as well as my own experiments.

On a 2014 MacBook Pro, the second location was used, while on a 2017 MacBook Pro the first location is used, though in both cases Homebrew was used to install htop, and both laptops are (as of 10/29/17) running macOS 10.12.6. (thanks to @iconoclast for pointing out the discrepancy)

In either case, the same config file format can be used, and in both cases, it's recommended you change any settings via htop's own setup instead of directly editing the config file, as it's automatically generated.

  • on my Mac it's at $HOME/.config/htop/htoprc – iconoclast Jun 13 '16 at 0:52
  • Yeah, the same is true for my own newer MBP. Not sure why the difference exists, but I updated the answer to reflect it. Thanks for the note! – TCAllen07 Oct 30 '17 at 1:23
1

Just had the same problem, but quitting htop with F10 didn't help save the settings. It appeared that this user's ~/.config belonged to root.

To check this:

$user@host:~$ ls -hal ~ |grep config

drwx------  4 root root 4.0K Mar 25  2015 .config

If it lists any user other than you, you should chown the directory to make your htop able to write in it:

sudo chown user:mygroup ~/.config

(replace "user" and "mygroup" with your username and group)

There is a "softer" way when you just give yourself permission to write but do not change the owner. But I cannot imagine why one should not own their ~/.config. Please tell me if I'm wrong.

  • Also encountered this. I know I have run sudo htop at some point, which likely wound up saving the config file with root's user and group. – user86616 Feb 27 '17 at 16:53
1

Okay, though this post may be old, I had the same issue.

Use the setup htop provides, which the asker had already done, but the settings were not being saved upon SSH, which is likely because there is no htoprc. Upon creating one, htop will then use it to save and load settings, rather than defaulting to its stock setup.

After reading @goldilocks and @TCAllen07 response, I sought to check if I even had a htoprc to begin with. It was not present. So, even though I owned my config directory from install, if I changed the setup, the settings would be lost. To solve it, I simply created the htoprc file in it's directory using touch .config/htop/htoprc, then I edited the settings from within htop interface and used cat .config/htop/htoprc to see that the changes were saved.

OS: Fedora 25 LK: 4.9.9-200.fc25.x86_64

  • @Fox the answer is in fact provided. It's too use the setup htop provides, which the asked had already done, but the settings were not being saved upon SSH, which is likely because there is no htoprc. Upon creating one, htop will then use it to save and load settings, rather than defaulting to its stock setup. – Th'Ink-King Feb 15 '17 at 12:19
1

You could also use a folder, shared among all your machines. Let's say that /media/shared is mounted equally on all machines. You can set it as your $HOME for htop, then it will save and load its configuration there.

HOME=/media/shared htop

This will start htop with a clean configuragion. Setup and close htop with F10 (or q). You could also copy your current configuration:

cp ~/.config/htop/htoprc /media/shared/.config/htop/htoprc

Now launch htop on your other machine(s):

HOME=/media/shared htop

It should be configured as you did on your previous machine. :)

  • 1
    Don't be "smart" and set $HOME globally in your shell session by doing export HOME=/media/shared. This may cause headaches. :-) – hzpc-joostk Aug 1 '17 at 16:07
1

Reset the settings in the config file

This are the default settings for htop on a Ubuntu 18.04 system. Replace the content of the file $HOME/.config/htop/htoprc and you should be fine. Make a backup first.

# Beware! This file is rewritten by htop when settings are changed in the interface.
# # The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1 
sort_key=1
sort_direction=1
hide_threads=0
hide_kernel_threads=1
hide_userland_threads=0
shadow_other_users=0
show_thread_names=0
show_program_path=1
highlight_base_name=0
highlight_megabytes=1
highlight_threads=1
tree_view=0
header_margin=1
detailed_cpu_time=0
cpu_count_from_zero=0
update_process_names=0
account_guest_in_cpu_meter=0
color_scheme=0
delay=15
left_meters=LeftCPUs Memory Swap 
left_meter_modes=1 1 1 
right_meters=RightCPUs Tasks LoadAverage Uptime 
right_meter_modes=1 2 2 2 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.