1
// Copyright 2022-2023 The Inspektor Gadget authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
21
gadgetregistry "github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-registry"
22
"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets"
23
"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/snapshot/process/types"
24
"github.com/inspektor-gadget/inspektor-gadget/pkg/params"
25
"github.com/inspektor-gadget/inspektor-gadget/pkg/parser"
29
ParamThreads = "threads"
32
type GadgetDesc struct{}
34
func (g *GadgetDesc) Name() string {
38
func (g *GadgetDesc) Category() string {
39
return gadgets.CategorySnapshot
42
func (g *GadgetDesc) Type() gadgets.GadgetType {
43
return gadgets.TypeOneShot
46
func (g *GadgetDesc) Description() string {
47
return "Gather information about running processes"
50
func (g *GadgetDesc) ParamDescs() params.ParamDescs {
51
return params.ParamDescs{
55
Description: "Show all threads (by default, only processes are shown)",
56
Alias: "", // TODO: was t, clashes with timeout
57
DefaultValue: "false",
58
TypeHint: params.TypeBool,
63
func (g *GadgetDesc) Parser() parser.Parser {
64
return parser.NewParser[types.Event](types.GetColumns())
67
func (g *GadgetDesc) EventPrototype() any {
71
func (g *GadgetDesc) OutputFormats() (gadgets.OutputFormats, string) {
72
return gadgets.OutputFormats{
73
"tree": gadgets.OutputFormat{
75
Description: "A pstree like output",
76
Transform: func(data any) ([]byte, error) {
77
processes, ok := data.([]*types.Event)
79
return nil, fmt.Errorf("type must be []*types.Event and is: %T", data)
82
var builder strings.Builder
83
err := types.WriteTree(&builder, processes)
88
return []byte(builder.String()), nil
94
func (g *GadgetDesc) SortByDefault() []string {
95
return []string{"k8s.node", "k8s.namespace", "k8s.pod", "k8s.container", "comm", "pid", "tid", "ppid"}
99
gadgetregistry.Register(&GadgetDesc{})