Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism

workflow Gitter chat Tweet

nhi is a revolutionary tool which automatically captures all potentially useful information about each executed command and everything around, and delivers powerful querying mechanism.

nhi keeps records of:

  • command
  • output of command
  • exit status of command
  • working directory at the end of command execution
  • start time of command
  • finish time of command
  • shell prompt at the time of command execution
  • (and much more in the future 😄 )

nhi also keeps record of infomations about shell session in general.

These features allow retrievement of commands executed in past and whole shell sessions, as well as every other useful information in a convenient way.

nhi daemon is based on eBPF - a technology built into linux kernel. Usage of eBPF guarantee a great performance and low overhead of the tool, because tracing is being safely done inside kernel.

nhi does not affect behaviour of any program/process (and OS in general).

Watch the introduction video to see how nhi works in practice.

Usage

For the full documentation, read the nhi(1) man page.

For quick reference, use nhi --help flags.

Requirements

bash or zsh, x86_64 architecture, systemd and linux kernel 5.5+. Some major distributions that ship with the linux kernel 5.5+:

  • Debian 11
  • Ubuntu 20.10+
  • Fedora 32+

xterm based terminals are highly recommended. (If you don't know whether your terminal emulator is xterm based or not, it most likely is xterm based. xterm is standard for terminal emulators.)

Installation

Step 1: Install objdump, awk, sqlite3, libsqlite3-dev and libbpf-dev (example for linux debian/ubuntu systems):

sudo apt-get install binutils gawk sqlite3 libsqlite3-dev libbpf-dev

Step 2: Download all seven files from the latest release, and put them in a new empty directory.

Step 3: Go to the new directory and run:

sudo -E bash ./install

Extra step only for Ubuntu users: Ubuntu has oddly compiled bash and zsh binaries which are missing some data required by nhi. To install shells that are compiled "normally", like on every other distro run:

sudo apt-get remove zsh-common
sudo add-apt-repository ppa:strang1ato/default-bash-and-zsh
sudo apt-get update && sudo apt-get install --reinstall bash

and if you were using zsh:

sudo apt-get install zsh

From now bash and zsh will be upgraded/installed only from the newly added repository.

Step 4: Restart your computer.

In order to check if you installed nhi succesfully open new terminal window and execute for example:

echo nhi test

and

nhi fetch {-1}

If you see "nhi test" once again, it means that nhi is properly installed.

Contributions

Contributions are welcome! Any tips and suggestions are appreciated. If you found any bug feel free to submit a new issue.

Owner
Karol Ołtarzewski
17, self-taught coder/hacker
Karol Ołtarzewski
Comments
  • `nhi` doesn't record commands

    `nhi` doesn't record commands

    Installed from release 0.2.1, nhi fetch shows only the creation of sessions, no commands have been logged, nor the finish of sessions. Same result from within and without tmux

    $ uname -a
    Linux Aostro-5468 5.14.16-arch1-1 #1 SMP PREEMPT Tue, 02 Nov 2021 22:22:59 +0000 x86_64 GNU/Linux
    
    $ zsh --version
    zsh 5.8 (x86_64-pc-linux-gnu)
    
  • nhi does not work on Archlinux

    nhi does not work on Archlinux

    Hi, This appears to be a fantastic utility.

    However, following the readme, I installed nhi on ArchLinux, but it does not seem to work correctly, as the echo nhi test failed (no output).

    Also, nih.bash seems to conflict with the merged_history.bash script published in http://ptspts.blogspot.com/2011/03/how-to-automatically-synchronize-shell.html to get a persistent command history, which does not work anymore if nhi.bash is sourced in .bashrc.

  • [BPF] Improve safety of potentially concurrent calls

    [BPF] Improve safety of potentially concurrent calls

    BPF spin locks don't support tracing programs, although according to manual this may change in the future.

    EDIT: BPF maps are RCU protected so calls are mostly safe

  • [lib] nhi doesn't save bash errors to db

    [lib] nhi doesn't save bash errors to db

    Bug is caused by https://github.com/strang1ato/nhi/commit/e73040d0bfad0cca0f25f78f896d3043277f8204 commit

    Tip: Bash outputs error via child processes that don't run execve()

  • Output of commands not saved when vim is ran

    Output of commands not saved when vim is ran

    Hello,

    Thank you, this project is really cool!

    However, my commands are not logged after running commands such as vim:

    vagrant@bullseye:~$ nhi fetch {-1}
    vagrant@bullseye:~$ echo test
    test
    vagrant@bullseye:~$ vim
    vagrant@bullseye:~$ echo test
    (nothing here)
    

    This issue seems to come from here: https://github.com/strang1ato/nhi/blob/a3c65ccf4a7600d5dea264eba924afd234191e06/daemon/src/nhi.bpf.c#L393-L404

    Looking in the database (at /var/nhi/db), I can see:

    echo test
    b'\xfftest\n'
    vim
    b'\xff\x1b[?1000h\xff\x1b[34h\x1b[?25h\x00\x00\x00\x00\x00\x00\x00\x00'
    echo test
    b''
    

    The last 8 bytes are set to \x00 which should mean that omit_write is set to zero, but I do not understand why it still refuses to log the next commands.

    On another note, it would be nice to remove the null bytes and the rest of what was logged (\x1b[?1000h\xff\x1b[34h\x1b[?25h), it messes up my terminal after executing nhi fetch (which makes me have to execute reset to clean my terminal).

  • `nhid` segfaults on 0.2.2 while using tmux

    `nhid` segfaults on 0.2.2 while using tmux

    Not really an issue (probably because I haven't used nhi that much), but I saw this in the kernel messages:

    [  +0.000004] nhid[3381461]: segfault at 0 ip 00007fed21d1f515 sp 00007ffd5ca83e38 error 4 in libc-2.33.so[7fed21be5000+14b000]
    [  +0.000010] Code: 00 00 0f 1f 00 31 c0 c5 f8 77 c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 89 f9 48 89 fa c5 f9 ef c0 83 e1 3f 83 f9 20 77 2b <c5> fd 74 0f c5 fd d7 c1 85 c0 0f 85 eb 00 00 00 48 83 c7 20 83 e1
    

    I don't know why there isn't a coredump generated, but it happens inside tmux and with my .zshrc (haven't tested other conditions yet). Again, not a urgent problem for me, just something for you to look into

simple web app that print its environment variable, useful for testing on k8s

Index Sample web app that pints environment variables. Start it: docker-compose up Use it: > curl localhost:8080 PATH=/usr/local/sbin:/usr/local/bin:/

Jan 10, 2022
Go package exposing a simple interface for executing commands, enabling easy mocking and wrapping of executed commands.

go-runner Go package exposing a simple interface for executing commands, enabling easy mocking and wrapping of executed commands. The Runner interface

Oct 18, 2022
A simple tool to extract Fronius solar data logger output and output Influx line protocol

telegraf-exec-fronius This is a simple tool to extract Fronius solar data logger output and output Influx line protocol; it is designed to be used wit

Jan 8, 2022
API to get docker information from server.

Docker Access API API to get docker information from server. This api is written using Go language and used Gin Framework for API building. How to run

Dec 13, 2021
Output all versions of a local git repo, which could be used as test data for your ML program.

gitwalker Output all versions of a local git repo, which could be used as test data for your ML program. Notice This program is under development. Cur

Dec 27, 2021
Capture the stream of Images for a Raspberry Pi Camera in GoLang

piCamera This package is a wrapper for the raspivid command on the Raspberry Pi. To make development easier on a PC, there is are different Start() me

Mar 5, 2022
A wrapper for leader election mechanism in Kubernetes

Kubernetes Leader Election Library for Go This library provides a thin wrapper for kubernetes leader election. It can be used to elect a leader betwee

Dec 24, 2022
A golang tool to list out all EKS clusters with active nodegroups in all regions in json format

eks-tool A quick and dirty tool to list out all EKS clusters with active nodegro

Dec 18, 2021
OCI transport plugin for apt-get (i.e., apt-get over ghcr.io)

apt-transport-oci: OCI transport plugin for apt-get (i.e., apt-get over ghcr.io) apt-transport-oci is an apt-get plugin to support distributing *.deb

Nov 1, 2022
vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds
vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds

Website • Quickstart • Documentation • Blog • Twitter • Slack vcluster - Virtual Clusters For Kubernetes Lightweight & Low-Overhead - Based on k3s, bu

Jan 4, 2023
PolarDB Stack is a DBaaS implementation for PolarDB-for-Postgres, as an operator creates and manages PolarDB/PostgreSQL clusters running in Kubernetes. It provides re-construct, failover swtich-over, scale up/out, high-available capabilities for each clusters.
PolarDB Stack is a DBaaS implementation for PolarDB-for-Postgres, as an operator creates and manages PolarDB/PostgreSQL clusters running in Kubernetes. It provides re-construct, failover swtich-over, scale up/out, high-available capabilities for each clusters.

PolarDB Stack开源版生命周期 1 系统概述 PolarDB是阿里云自研的云原生关系型数据库,采用了基于Shared-Storage的存储计算分离架构。数据库由传统的Share-Nothing,转变成了Shared-Storage架构。由原来的N份计算+N份存储,转变成了N份计算+1份存储

Nov 8, 2022
kitex running in kubernetes cluster and discover each other in kubernetes Service way

Using kitex in kubernetes Kitex [kaɪt'eks] is a high-performance and strong-extensibility Golang RPC framework. This go module helps you to build mult

Feb 21, 2022
I'd like to share random apps in the spare times. Thus, I'm going to try learning some concepts of Go and as much as I can I try to clarify each line.

go-samples I'd like to share random apps in the spare times. Thus, I'm going to try learning some concepts of Go and as much as I can I try to clarify

Mar 16, 2022
Connect, Subscribe and Publish over MQTT broker to check its status.

MQTT Blackbox Exporter Introduction In each probe it sends a message over MQTT broker and then wait for getting it over subscription. By measuring thi

Aug 27, 2022
The missing package manager for golang binaries (its homebrew for "go install")

Bingo: The missing package manager for golang binaries (its homebrew for "go install") Do you love the simplicity of being able to download & compile

Oct 31, 2022
A letsencrypt client that uses etcd as its storage.

letsencrypt-with-etcd This is a letsencrypt client that uses etcd as its storage. It stores your (automatically created) LetsEncrypt account in /letse

Jan 20, 2022
CetusGuard is a tool that allows to protect the Docker daemon socket by filtering the calls to its API endpoints.

CetusGuard CetusGuard is a tool that allows to protect the Docker daemon socket by filtering the calls to its API endpoints. Some highlights: It is wr

Dec 23, 2022
Monitoring changes in the source file and automatically compile and run (restart).
Monitoring changes in the source file and automatically compile and run (restart).

dogo Monitoring changes in the source file and automatically compile and run (restart). 中文 Install go get github.com/liudng/dogo Create config Here's

Dec 28, 2022
An image server which automatically optimize non webp and avif images to webp and avif images

go-imageserver go-imageserver is an image server which automatically optimize no

Apr 18, 2022