A tool to list and diagnose Go processes currently running on your system

gops

GitHub Action Status Build status GoDoc

gops is a command to list and diagnose Go processes currently running on your system.

$ gops
983   980    uplink-soecks  go1.9   /usr/local/bin/uplink-soecks
52697 52695  gops           go1.10  /Users/jbd/bin/gops
4132  4130   foops        * go1.9   /Users/jbd/bin/foops
51130 51128  gocode         go1.9.2 /Users/jbd/bin/gocode

Installation

$ go get -u github.com/google/gops

Diagnostics

For processes that starts the diagnostics agent, gops can report additional information such as the current stack trace, Go version, memory stats, etc.

In order to start the diagnostics agent, see the hello example.

package main

import (
	"log"
	"time"

	"github.com/google/gops/agent"
)

func main() {
	if err := agent.Listen(agent.Options{}); err != nil {
		log.Fatal(err)
	}
	time.Sleep(time.Hour)
}

Otherwise, you could set GOPS_CONFIG_DIR environment variables to assign your config dir. Default, gops will use the current user's home directory(AppData on windows).

Manual

It is possible to use gops tool both in local and remote mode.

Local mode requires that you start the target binary as the same user that runs gops binary. To use gops in a remote mode you need to know target's agent address.

In Local mode use process's PID as a target; in Remote mode target is a host:port combination.

Listing all processes running locally

To print all go processes, run gops without arguments:

$ gops
983   980    uplink-soecks  go1.9   /usr/local/bin/uplink-soecks
52697 52695  gops           go1.10  /Users/jbd/bin/gops
4132  4130   foops        * go1.9   /Users/jbd/bin/foops
51130 51128  gocode         go1.9.2 /Users/jbd/bin/gocode

The output displays:

  • PID
  • PPID
  • Name of the program
  • Go version used to build the program
  • Location of the associated program

Note that processes running the agent are marked with * next to the PID (e.g. 4132*).

$ gops <pid>

To report more information about a process, run gops following by a PID:

$ gops <pid>
parent PID:	5985
threads:	27
memory usage:	0.199%
cpu usage:	0.139%
username:	jbd
cmd+args:	/Applications/Splice.app/Contents/Resources/Splice Helper.app/Contents/MacOS/Splice Helper -pid 5985
local/remote:	127.0.0.1:56765 <-> :0 (LISTEN)
local/remote:	127.0.0.1:56765 <-> 127.0.0.1:50955 (ESTABLISHED)
local/remote:	100.76.175.164:52353 <-> 54.241.191.232:443 (ESTABLISHED)

$ gops tree

To display a process tree with all the running Go processes, run the following command:

$ gops tree

...
├── 1
│   └── 13962 [gocode] {go1.9}
├── 557
│   └── 635 [com.docker.supervisor] {go1.9.2}
│       └── 638 [com.docker.driver.amd64-linux] {go1.9.2}
└── 13744
    └── 67243 [gops] {go1.10}

$ gops stack (<pid>|<addr>)

In order to print the current stack trace from a target program, run the following command:

$ gops stack (<pid>|<addr>)
gops stack 85709
goroutine 8 [running]:
runtime/pprof.writeGoroutineStacks(0x13c7bc0, 0xc42000e008, 0xc420ec8520, 0xc420ec8520)
	/Users/jbd/go/src/runtime/pprof/pprof.go:603 +0x79
runtime/pprof.writeGoroutine(0x13c7bc0, 0xc42000e008, 0x2, 0xc428f1c048, 0xc420ec8608)
	/Users/jbd/go/src/runtime/pprof/pprof.go:592 +0x44
runtime/pprof.(*Profile).WriteTo(0x13eeda0, 0x13c7bc0, 0xc42000e008, 0x2, 0xc42000e008, 0x0)
	/Users/jbd/go/src/runtime/pprof/pprof.go:302 +0x3b5
github.com/google/gops/agent.handle(0x13cd560, 0xc42000e008, 0xc420186000, 0x1, 0x1, 0x0, 0x0)
	/Users/jbd/src/github.com/google/gops/agent/agent.go:150 +0x1b3
github.com/google/gops/agent.listen()
	/Users/jbd/src/github.com/google/gops/agent/agent.go:113 +0x2b2
created by github.com/google/gops/agent.Listen
	/Users/jbd/src/github.com/google/gops/agent/agent.go:94 +0x480
# ...

$ gops memstats (<pid>|<addr>)

To print the current memory stats, run the following command:

$ gops memstats (<pid>|<addr>)

$ gops gc (<pid>|<addr>)

If you want to force run garbage collection on the target program, run gc. It will block until the GC is completed.

$gops setgc (<pid>|<addr>)

Sets the garbage collection target to a certain percentage. The following command sets it to 10%:

$ gops setgc (<pid>|<addr>) 10

$ gops version (<pid>|<addr>)

gops reports the Go version the target program is built with, if you run the following:

$ gops version (<pid>|<addr>)
devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000

$ gops stats (<pid>|<addr>)

To print the runtime statistics such as number of goroutines and GOMAXPROCS.

Profiling

Pprof

gops supports CPU and heap pprof profiles. After reading either heap or CPU profile, it shells out to the go tool pprof and let you interactively examine the profiles.

To enter the CPU profile, run:

$ gops pprof-cpu (<pid>|<addr>)

To enter the heap profile, run:

$ gops pprof-heap (<pid>|<addr>)
Execution trace

gops allows you to start the runtime tracer for 5 seconds and examine the results.

$ gops trace (<pid>|<addr>)
Owner
Google
Google ❤️ Open Source
Google
Comments
  • Gops hangs if there are too many Go processes to examine

    Gops hangs if there are too many Go processes to examine

    If you have more than ten (I believe) Go processes, gops will hang in goprocess/gp.go's FindAll() function. This happens because the 'for .. range pss { ...}' loop attempts to obtain a limitCh token before starting the goroutine, but the goroutines only release their token after they have sent their reply to the found channel. Since the found channel is unbuffered and is only read from by the main code after the 'for .. range pss {}' loop finishes, this deadlocks if the number of goroutines would ever be limited.

    I think either the entire 'for .. range pss { ... }' loop needs to be in a goroutine so that it doesn't block reading from the found channel, or the limitCh token must be released by the code before sending to found. The former change seems easier and I think it's correct.

  • Added remote mode support

    Added remote mode support

    This PR adds a possibility to use this tool for instrumented binaries running on remote hosts.

    PR adds new protocol command, which dumps running service's binary file. Two dependencies were added, namely github.com/pkg/errors for errors' contexts and github.com/kardianos/osext, which helps agent find the path to executable file.

    Interface changes are simple: it is now possible to pass host:port combo instead of PID to gops tool.

  • gops can not list process in Mac book with m1 chip

    gops can not list process in Mac book with m1 chip

    gops program can not list the process which is build with cgo in M1 MacBook

    example:

     ~ go env
    GO111MODULE=""
    GOARCH="arm64"
    GOBIN=""
    GOCACHE="/Users/rao/Library/Caches/go-build"
    GOENV="/Users/rao/Library/Application Support/go/env"
    GOEXE=""
    GOEXPERIMENT=""
    GOFLAGS=""
    GOHOSTARCH="arm64"
    GOHOSTOS="darwin"
    GOINSECURE=""
    GOMODCACHE="/Users/rao/go/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="darwin"
    GOPATH="/Users/rao/go"
    GOPRIVATE=""
    GOPROXY="https://goproxy.cn,direct"
    GOROOT="/usr/local/go"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
    GOVCS=""
    GOVERSION="go1.17.6"
    GCCGO="gccgo"
    AR="ar"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD="/dev/null"
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v5/jbb9crmn2gn5z__s2_pyybdh0000gn/T/go-build1597321378=/tmp/go-build -gno-record-gcc-switches -fno-common"
    ➜ ~ cat main.go
    package main
    
    import "C"
    
    import (
    	"fmt"
    	"os"
    	"os/signal"
    )
    
    func main() {
    	c := make(chan os.Signal, 1)
    	signal.Notify(c, os.Kill, os.Interrupt)
    	<-c
    	fmt.Println("exit")
    }
    ➜  ~ go build main.go
    ➜  ~ ./main &
    [1] 44211
    ➜  ~ gops
    ➜  ~
    
  • gops stopped listing my running go programs

    gops stopped listing my running go programs

    A few days ago, gops stopped listing my running go program (found this when I couldn't attach to my program for debugging in GoLand)

    Any ideas on how to debug this?

  • Fix configdir path and use correct path under windows

    Fix configdir path and use correct path under windows

    Two small fixes:

    • adds the gopsdirectory to the osUserConfigDir. So we use the correct directory.
    • uses filepath.Join in PIDFile() so that gops works under windows.
  • agent: allow to set SO_REUSEPORT on listening socket

    agent: allow to set SO_REUSEPORT on listening socket

    Introduce Option.SocketReuseAddrAndPort which, if set, will lead to the SO_REUSEPORT socket option being set on the listening socket on Unix-like OSes. This also sets SO_REUSEADDR which is already the default in net.Listen (see net.setDefaultSockopts).

    Setting these options increases the chance to re-bind() to the same address and port upon agent restart if Options.Addr is set.

  • agent: clean up socket and port file on SIGTERM and SIGQUIT

    agent: clean up socket and port file on SIGTERM and SIGQUIT

    In case the agent is exiting due to a SIGTERM or SIGQUIT it is leaking the port files in the gops config directory, as e.g. reported in cilium/cilium#11455

    Make sure the socket is cleaned up and port files in the gops config directory are removed upon these signals by also relaying these signals to the signal channel in gracefulShutdown. In case of SIGTERM, which is the "normal" termination signal, exit the process with exit status 0.

  • Allow starting the agent without installing a signal handler

    Allow starting the agent without installing a signal handler

    If the application the agent is being installed on also need to run some shutdown code during an Interrupt signal, it's important to have the ability to prevent gops agent from calling os.Exit(). This also adds the requirement of exposing a method to manually cleanup garbage left by the gops agent.

    To allow custom agent flags now and in the future an Agent type was created with a public boolean field HandleSignals. This allowed preserving the current interface by having the Start() method start an Agent with HandleSignals set to true. The Agent type also exposes a Stop() method to perform the necessary cleanup.

    This PR also adds some basic initial testing to Agent start and stopping.

  • #10 replace unix socket by tcp

    #10 replace unix socket by tcp

    Trying to build on the comment:

    I want to move off of the unix socket and want to listen on a TCP socket instead. I am planning to listen on a random port and keep the port process is listening under $HOME/.gops/.addr. This will also enable the windows support.

    Not sure about the perms, though.

  • agent: include newlines in warning log messages

    agent: include newlines in warning log messages

    The warnings that agent prints to os.Stderr did not previously include newlines causing program output to get jumbled up when an error occurs. We see this most often when calling Close(), which causes the listener to print gops: accept tcp 127.0.0.1:9999: use of closed network connection which breaks whatever is logged next.

  • Added support for displaying the elapsed time (etime) of a process

    Added support for displaying the elapsed time (etime) of a process

    The PR introduces the display of the elapsed time of a process, indicating how long the process has been running for.

    According to the ps man page:

    etime  ELAPSED  elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.
    

    Example:

    $ gops 849
    parent PID:     1
    threads:        16
    memory usage:   0.066%
    cpu usage:      0.114%
    username:       dastergon
    cmd+args:       /usr/local/opt/etcd/bin/etcd
    elapsed time:   02-23:48:13
    local/remote:   127.0.0.1:2380 <-> :0 (LISTEN)
    local/remote:   127.0.0.1:2379 <-> :0 (LISTEN)
    local/remote:   127.0.0.1:49189 <-> 127.0.0.1:2379 (ESTABLISHED)
    local/remote:   127.0.0.1:2379 <-> 127.0.0.1:49189 (ESTABLISHED)
    

    Note: I have already sent a PR to gopsutil for addition of this functionality, but I am not certain whether it will land on master or not. Consequently, I decided to use the code straight from the PR for this implementation. If the gopsutil PR gets merged in the future, I will send a follow-up PR to use gopsutil's function instead.

  • Couldn't resolve addr or pid <pid> to TCPAddress

    Couldn't resolve addr or pid to TCPAddress

    root@xxx-server# gops stack 19401 Couldn't resolve addr or pid 19401 to TCPAddress: couldn't get port for PID 19401: open /root/.config/gops/19401: no such file or directory

  • Extend `gops trace` to allow duration parameter

    Extend `gops trace` to allow duration parameter

    gops trace :port 10m will now run a trace for 10 minutes, as opposed to always doing 5 seconds.

    For backwards compatibility both server and the client default to 5s if nothing is specified.

  • go get failed in m1

    go get failed in m1

    ➜  struct-test git:(master) ✗ go version
    go version go1.16.5 darwin/arm64
    
    ➜  struct-test git:(master) ✗ go get -u github.com/google/gops
    go: downloading github.com/google/gops v0.3.22
    go: downloading github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7
    go: downloading github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
    go: downloading rsc.io/goversion v1.2.0
    go: downloading github.com/shirou/gopsutil/v3 v3.21.9
    go: downloading github.com/shirou/gopsutil v3.21.11+incompatible
    go: downloading github.com/shirou/gopsutil/v3 v3.21.11
    go: downloading github.com/tklauser/go-sysconf v0.3.9
    go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
    go: downloading github.com/tklauser/numcpus v0.3.0
    go: downloading github.com/go-ole/go-ole v1.2.6-0.20210915003542-8b1f7f90f6b1
    go: downloading github.com/yusufpapurcu/wmi v1.2.2
    go: downloading github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0
    go: downloading github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c
    # github.com/google/gops
    /usr/local/go/pkg/tool/darwin_arm64/link: /usr/local/go/pkg/tool/darwin_arm64/link: combining dwarf failed: unknown load command 0x80000034 (2147483700)
    
  • improve CI/CD release process with GitHub Actions and GoReleaser

    improve CI/CD release process with GitHub Actions and GoReleaser

    • [ ] Integrate with GoReleaser, sign/verify binaries&container images GitHub Actions OIDC Keyless with cosign
    • [ ] create GitHub Action workflows for releasing
    • [ ] Mage?
    • [ ] Multi-arch support?
    • [ ] provide the necessary information in version command (version, date, etc), use ldflags?

    we are volunteers, please free to assign this to us 🙋🏻‍♂️🤝

    cc: @rakyll @dentrax

  • gops crashes on macos without a CLI command on startup

    gops crashes on macos without a CLI command on startup

    $ (cd $(mktemp -d); GO111MODULE=on go get github.com/google/gops/@v0.3.21)
    
    $ ~/go/bin/gops
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x410df6e]
    
    goroutine 11 [running]:
    rsc.io/goversion/version.(*machoExe).Symbols(0xc000024210)
    	/Users/paul.johnston/go/pkg/mod/rsc.io/[email protected]/version/exe.go:290 +0x2e
    rsc.io/goversion/version.ReadExe({0xc000024210, 0x0})
    	/Users/paul.johnston/go/pkg/mod/rsc.io/[email protected]/version/read.go:41 +0x1d0
    github.com/google/gops/goprocess.isGo({0x4196550, 0xc00006a4c0})
    	/Users/paul.johnston/go/pkg/mod/github.com/google/[email protected]/goprocess/gp.go:123 +0x93
    github.com/google/gops/goprocess.findAll.func1()
    	/Users/paul.johnston/go/pkg/mod/github.com/google/[email protected]/goprocess/gp.go:60 +0xd1
    created by github.com/google/gops/goprocess.findAll
    	/Users/paul.johnston/go/pkg/mod/github.com/google/[email protected]/goprocess/gp.go:56 +0xd4
    
    $ go version
    go version go1.17.1 darwin/amd64
    
Cloudinsight Agent is a system tool that monitors system processes and services, and sends information back to your Cloudinsight account.

Cloudinsight Agent 中文版 README Cloudinsight Agent is written in Go for collecting metrics from the system it's running on, or from other services, and

Nov 3, 2022
Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.
Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Nov 10, 2022
A GNU/Linux monitoring and profiling tool focused on single processes.
A GNU/Linux monitoring and profiling tool focused on single processes.

Uroboros is a GNU/Linux monitoring tool focused on single processes. While utilities like top, ps and htop provide great overall details, they often l

Dec 26, 2022
EdgeLog is a lightweight log management system, and Agent is a part of EdgeLog system

EdgeLog is a lightweight log management system, and Agent is a part of EdgeLog system. It is installed on host machine and its main duty is to collect host program log statics.

Oct 10, 2022
List files and their creation, modification and access time on android

andfind List files and their access, modification and creation date on a Android

Jan 5, 2022
Cloudprober is a monitoring software that makes it super-easy to monitor availability and performance of various components of your system.

Cloudprober is a monitoring software that makes it super-easy to monitor availability and performance of various components of your system. Cloudprobe

Dec 30, 2022
The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.
The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.

Static Go Playground Features Full Go Compiler running on the browser. Supports using custom build tags. Incremental builds (build cache). Supports mu

Jun 16, 2022
A system and resource monitoring tool written in Golang!
A system and resource monitoring tool written in Golang!

Grofer A clean and modern system and resource monitor written purely in golang using termui and gopsutil! Currently compatible with Linux only. Curren

Jan 8, 2023
checkah is an agentless SSH system monitoring and alerting tool.

CHECKAH checkah is an agentless SSH system monitoring and alerting tool. Features: agentless check over SSH (password, keyfile, agent) config file bas

Oct 14, 2022
rtop is an interactive, remote system monitoring tool based on SSH

rtop rtop is a remote system monitor. It connects over SSH to a remote system and displays vital system metrics (CPU, disk, memory, network). No speci

Dec 30, 2022
BRUS - Parses your web server (e.g. nginx) log files and checks with GreyNoise how much noise your website is exposed to.

BRUS bbbbbb rrrrrr u u sssss b b r r u u s bbbbbb rrrrrr u u sssss b b r r u u s bbbbbb r r

May 29, 2022
With this package you can create your own syslog server with your own handlers for different kind of syslog messages

Using this library you can easy implement your own syslog server that: Can listen on multiple UDP ports and unix domain sockets. Can pass parsed syslo

Nov 9, 2022
Distributed simple and robust release management and monitoring system.
Distributed simple and robust release management and monitoring system.

Agente Distributed simple and robust release management and monitoring system. **This project on going work. Road map Core system First worker agent M

Nov 17, 2022
Hidra is a tool to monitor all of your services without making a mess.

hidra Don't lose your mind monitoring your services. Hidra lends you its head. ICMP If you want to use ICMP scenario, you should activate on your syst

Nov 8, 2022
The Prometheus monitoring system and time series database.

Prometheus Visit prometheus.io for the full documentation, examples and guides. Prometheus, a Cloud Native Computing Foundation project, is a systems

Dec 31, 2022
An open-source and enterprise-level monitoring system.
 An open-source and enterprise-level monitoring system.

Falcon+ Documentations Usage Open-Falcon API Prerequisite Git >= 1.7.5 Go >= 1.6 Getting Started Docker Please refer to ./docker/README.md. Build from

Jan 1, 2023
An example logging system using Prometheus, Loki, and Grafana.
An example logging system using Prometheus, Loki, and Grafana.

Logging Example Structure Collector Export numerical data for Prometheus and log data for Promtail. Exporter uses port 8080 Log files are saved to ./c

Nov 21, 2022
Nightingale - A Distributed and High-Performance Monitoring System. Prometheus enterprise edition
Nightingale - A Distributed and High-Performance Monitoring System. Prometheus enterprise edition

Introduction ?? A Distributed and High-Performance Monitoring System. Prometheus

Jan 7, 2022
A simple to use log system, minimalist but with features for debugging and differentiation of messages
A simple to use log system, minimalist but with features for debugging and differentiation of messages

A simple to use log system, minimalist but with features for debugging and differentiation of messages

Sep 26, 2022