github.com/google/cadvisor@v0.49.1/container/common/container_hints.go (about)

     1  // Copyright 2014 Google Inc. All Rights Reserved.
     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  // Unmarshal's a Containers description json file. The json file contains
    16  // an array of ContainerHint structs, each with a container's id and networkInterface
    17  // This allows collecting stats about network interfaces configured outside docker
    18  // and lxc
    19  package common
    20  
    21  import (
    22  	"encoding/json"
    23  	"flag"
    24  	"os"
    25  )
    26  
    27  var ArgContainerHints = flag.String("container_hints", "/etc/cadvisor/container_hints.json", "location of the container hints file")
    28  
    29  type ContainerHints struct {
    30  	AllHosts []containerHint `json:"all_hosts,omitempty"`
    31  }
    32  
    33  type containerHint struct {
    34  	FullName         string            `json:"full_path,omitempty"`
    35  	NetworkInterface *networkInterface `json:"network_interface,omitempty"`
    36  	Mounts           []Mount           `json:"mounts,omitempty"`
    37  }
    38  
    39  type Mount struct {
    40  	HostDir      string `json:"host_dir,omitempty"`
    41  	ContainerDir string `json:"container_dir,omitempty"`
    42  }
    43  
    44  type networkInterface struct {
    45  	VethHost  string `json:"veth_host,omitempty"`
    46  	VethChild string `json:"veth_child,omitempty"`
    47  }
    48  
    49  func GetContainerHintsFromFile(containerHintsFile string) (ContainerHints, error) {
    50  	dat, err := os.ReadFile(containerHintsFile)
    51  	if os.IsNotExist(err) {
    52  		return ContainerHints{}, nil
    53  	}
    54  	var cHints ContainerHints
    55  	if err == nil {
    56  		err = json.Unmarshal(dat, &cHints)
    57  	}
    58  
    59  	return cHints, err
    60  }