github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/gadgets/trace/fsslower/tracer/gadget.go (about)

     1  // Copyright 2022-2023 The Inspektor Gadget authors
     2  //
     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
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     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.
    14  
    15  package tracer
    16  
    17  import (
    18  	"fmt"
    19  
    20  	gadgetregistry "github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-registry"
    21  	"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets"
    22  	"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/trace/fsslower/types"
    23  	"github.com/inspektor-gadget/inspektor-gadget/pkg/params"
    24  	"github.com/inspektor-gadget/inspektor-gadget/pkg/parser"
    25  )
    26  
    27  const (
    28  	ParamFilesystem = "filesystem"
    29  	ParamMinLatency = "min"
    30  )
    31  
    32  type GadgetDesc struct{}
    33  
    34  func (g *GadgetDesc) Name() string {
    35  	return "fsslower"
    36  }
    37  
    38  func (g *GadgetDesc) Category() string {
    39  	return gadgets.CategoryTrace
    40  }
    41  
    42  func (g *GadgetDesc) Type() gadgets.GadgetType {
    43  	return gadgets.TypeTrace
    44  }
    45  
    46  func (g *GadgetDesc) Description() string {
    47  	return "Trace open, read, write and fsync operations slower than a threshold"
    48  }
    49  
    50  func (g *GadgetDesc) ParamDescs() params.ParamDescs {
    51  	return params.ParamDescs{
    52  		{
    53  			Key:          ParamMinLatency,
    54  			Alias:        "m",
    55  			Title:        "Minimum Latency",
    56  			DefaultValue: fmt.Sprintf("%d", types.MinLatencyDefault),
    57  			Description:  "Min latency to trace, in ms",
    58  			TypeHint:     params.TypeUint64,
    59  		},
    60  		{
    61  			Key:            ParamFilesystem,
    62  			Alias:          "f",
    63  			Title:          "Filesystem",
    64  			DefaultValue:   "ext4",
    65  			Description:    "Filesystem to trace",
    66  			PossibleValues: []string{"btrfs", "ext4", "fuse", "nfs", "ntfs3", "xfs"},
    67  		},
    68  	}
    69  }
    70  
    71  func (g *GadgetDesc) Parser() parser.Parser {
    72  	return parser.NewParser[types.Event](types.GetColumns())
    73  }
    74  
    75  func (g *GadgetDesc) EventPrototype() any {
    76  	return &types.Event{}
    77  }
    78  
    79  func init() {
    80  	gadgetregistry.Register(&GadgetDesc{})
    81  }