-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
1,533 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: On push | ||
run-name: On push 🚀 | ||
on: [push] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version-file: 'go.mod' | ||
check-latest: true | ||
- run: go version | ||
|
||
- name: Test | ||
run: go test ./... | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
args: --timeout=3m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
run: | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
- interfacer | ||
- ineffassign | ||
- structcheck | ||
- deadcode | ||
- depguard | ||
- nosnakecase | ||
- ifshort | ||
- forbidigo | ||
- funlen | ||
- gocritic | ||
- golint | ||
- goerr113 | ||
- gosec | ||
- gomnd | ||
- gocognit | ||
- cyclop | ||
- scopelint | ||
- exhaustivestruct | ||
- maligned | ||
- varcheck | ||
- rowserrcheck | ||
- wastedassign | ||
- gci | ||
- wsl | ||
- exhaustruct | ||
- paralleltest | ||
- testpackage | ||
- varnamelen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,87 @@ | ||
# kload | ||
kload show cpu and memory load on nodes and pods in your kubernetes cluster | ||
# Kload | ||
|
||
Kload shows cpu and memory load on nodes and pods in your kubernetes cluster. Kload uses your kubectl setup | ||
to show information about your cluster. | ||
|
||
[<img src="./doc/kload-demo.gif" alt="kloaddemo" type="image/gif">](demo/drawdemo.go) | ||
|
||
## Installation | ||
|
||
You must have [kubectl](https://kubernetes.io/docs/reference/kubectl/) installed on your machine and [metrics](https://github.com/kubernetes-sigs/metrics-server) enabled for your kubernetes cluster. | ||
Most likely you have them both installed. | ||
|
||
### Source | ||
``` | ||
$go install github.com/raffepaffe/kload@latest | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
Kload shows a line graph with CPU percentage used in yellow and memory percentage in red. Each pod and container name is seen | ||
on the top of each graph together with cpu and memory limits. | ||
|
||
### Show cpu and memory for the nodes in your cluster | ||
|
||
Show all nodes in your cluster | ||
``` | ||
$kload -node | ||
``` | ||
[<img src="./doc/node-example-demo.png" alt="kloaddemo" type="image/png">]() | ||
|
||
The default value for the number of columns is set to three. If you have three nodes your output will look like this. | ||
[<img src="./doc/node-example-default-view.png" alt="kloaddemo" type="image/png">]() | ||
|
||
You can adjust the numer of columns with the column parameter. | ||
``` | ||
$kload -node -columns 2 | ||
``` | ||
[<img src="./doc/node-example-2-columns.png" alt="kloaddemo" type="image/png">]() | ||
|
||
You can show only the nodes you are interested in by listing the node names. This will show node-000 node-001. | ||
``` | ||
$kload -node node-000 node-001 | ||
``` | ||
|
||
### Show cpu and memory for the pods and containers in your cluster | ||
|
||
Show the pods in the prod namespace | ||
``` | ||
$kload -pod -ns prod | ||
``` | ||
|
||
Show the pods in the prod namespace, two columns wide and with the namne http-server and app-server | ||
``` | ||
$kload -pod -ns prod -columns 2 http-server app-server | ||
``` | ||
|
||
Show the pods in the prod namespace, two columns wide, the name can't contain app or http, with the name server. | ||
You can use regexp with the -v flag. | ||
``` | ||
$kload -pod -ns prod -columns 2 -v 'app|http' server | ||
``` | ||
|
||
## Issues | ||
|
||
- Graph lines will bleed over if they come to close to each other. | ||
- Pods and nodes that exist when kload is started are shown. If you deploy new ones or redeploy them, they will not show up. | ||
- During development, I didn't use TDD as I usually do. No tests -> probably has bugs. | ||
- Draw function is too long and needs to be refactored. | ||
|
||
## Credits | ||
|
||
The idea for this came during a time when I was trying to find a memory leak. I needed to continuously monitor some of my pods | ||
and I was trying to understand how memory management worked in kubernetes. | ||
|
||
Credit goes to (in alphabetic order) Anders, Björn and Hampus for | ||
helping me become a better Go developer. | ||
|
||
## Contributing | ||
|
||
As with most tools, this will likely miss some cases. If you come across a case which you | ||
think should be covered and isn't, please file an issue including a minimum reproducible example of the case. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT license. See the [LICENSE](./LICENSE) file for more | ||
details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"strconv" | ||
|
||
"github.com/raffepaffe/kload/internal/k8s" | ||
"github.com/raffepaffe/kload/internal/ui/terminal" | ||
) | ||
|
||
type datasource struct { | ||
elements []*k8s.Element | ||
} | ||
|
||
func (d *datasource) Fetch() ([]*k8s.Element, error) { | ||
for _, e := range d.elements { | ||
value := randValue() | ||
e.CPU = e.CPU + float64(value) | ||
value = randValue() | ||
e.Memory = e.Memory + float64(value) | ||
} | ||
|
||
return d.elements, nil | ||
} | ||
|
||
func randValue() int32 { | ||
value := rand.Int31n(6) | ||
if value%2 == 0 { | ||
value = -value * 2 | ||
} | ||
|
||
return value | ||
} | ||
|
||
func (d *datasource) MaxColumns() int { | ||
return 2 | ||
} | ||
|
||
func newDatasource() *datasource { | ||
cpuLimit := float64(100) | ||
memLimit := float64(300) | ||
|
||
elements := make([]*k8s.Element, 0) | ||
|
||
for i := 0; i < 3; i++ { | ||
e := &k8s.Element{ | ||
Name: "http-server" + "/" + "agdf-1df" + strconv.Itoa(i), | ||
CPU: rand.Float64() * 100, | ||
CPULimit: cpuLimit, | ||
Memory: rand.Float64() * 200, | ||
MemoryLimit: memLimit, | ||
} | ||
|
||
elements = append(elements, e) | ||
} | ||
|
||
ds := &datasource{elements: elements} | ||
|
||
return ds | ||
} | ||
|
||
func main() { | ||
fmt.Println("kload demo") | ||
ds := newDatasource() | ||
err := terminal.Draw(ds) | ||
if err != nil { | ||
fmt.Println("error is %w", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Kload shows cpu and memory load on nodes and pods in your kubernetes cluster. Kload uses your kubectl setup | ||
// to show information about your cluster. | ||
// | ||
// Basic usage: | ||
// | ||
// Show load in a namespace: | ||
// kload -pod -ns [your-namespace] | ||
// | ||
// Show load in a namespace for a pod: | ||
// kload -pod -ns [your-namespace] [your-pod] | ||
// | ||
// Show load for nodes: | ||
// kload -node [node-name] | ||
// | ||
// Find more information at https://github.com/raffepaffe/kload/blob/master/README.md | ||
package main |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module github.com/raffepaffe/kload | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/mum4k/termdash v0.18.0 | ||
k8s.io/apimachinery v0.25.4 | ||
k8s.io/client-go v0.25.4 | ||
k8s.io/metrics v0.25.4 | ||
) | ||
|
||
require ( | ||
github.com/PuerkitoBio/purell v1.1.1 // indirect | ||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/go-restful/v3 v3.8.0 // indirect | ||
github.com/gdamore/encoding v1.0.0 // indirect | ||
github.com/gdamore/tcell/v2 v2.5.4 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.19.5 // indirect | ||
github.com/go-openapi/swag v0.19.14 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/gofuzz v1.1.0 // indirect | ||
github.com/imdario/mergo v0.3.6 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mattn/go-runewidth v0.0.14 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect | ||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect | ||
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect | ||
golang.org/x/text v0.5.0 // indirect | ||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/api v0.25.4 // indirect | ||
k8s.io/klog/v2 v2.70.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect | ||
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect | ||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
sigs.k8s.io/yaml v1.2.0 // indirect | ||
) |
Oops, something went wrong.