gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/runsc/cmd/metricserver/metricservercmd/metricservercmd.go (about)

     1  // Copyright 2023 The gVisor 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 metricservercmd partially implements the 'metric-server' subcommand.
    16  package metricservercmd
    17  
    18  import (
    19  	"gvisor.dev/gvisor/runsc/flag"
    20  )
    21  
    22  // Cmd partially implements subcommands.Command for the metric-server command.
    23  type Cmd struct {
    24  	ExporterPrefix         string
    25  	PIDFile                string
    26  	ExposeProfileEndpoints bool
    27  	AllowUnknownRoot       bool
    28  }
    29  
    30  // Name implements subcommands.Command.Name.
    31  func (*Cmd) Name() string {
    32  	return "metric-server"
    33  }
    34  
    35  // Synopsis implements subcommands.Command.Synopsis.
    36  func (*Cmd) Synopsis() string {
    37  	return "implements Prometheus metrics HTTP endpoint"
    38  }
    39  
    40  // Usage implements subcommands.Command.Usage.
    41  func (*Cmd) Usage() string {
    42  	return `-root=<root dir> -metric-server=<addr> metric-server [-exporter-prefix=<runsc_>]
    43  `
    44  }
    45  
    46  // SetFlags implements subcommands.Command.SetFlags.
    47  func (c *Cmd) SetFlags(f *flag.FlagSet) {
    48  	f.StringVar(&c.ExporterPrefix, "exporter-prefix", "runsc_", "Prefix for all metric names, following Prometheus exporter convention")
    49  	f.StringVar(&c.PIDFile, "pid-file", "", "If set, write the metric server's own PID to this file after binding to the --metric-server address. The parent directory of this file must already exist.")
    50  	f.BoolVar(&c.ExposeProfileEndpoints, "allow-profiling", false, "If true, expose /runsc-metrics/profile-cpu and /runsc-metrics/profile-heap to get profiling data about the metric server")
    51  	f.BoolVar(&c.AllowUnknownRoot, "allow-unknown-root", false, "if set, the metric server will keep running regardless of the existence of --root or the metric server's ability to access it.")
    52  }