1 // Copyright 2018 The Prometheus Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
22 // FS represents the pseudo-filesystem proc, which provides an interface to
23 // kernel data structures.
26 // DefaultMountPoint is the common mount point of the proc filesystem.
27 const DefaultMountPoint = "/proc"
29 // NewFS returns a new FS mounted under the given mountPoint. It will error
30 // if the mount point can't be read.
31 func NewFS(mountPoint string) (FS, error) {
32 info, err := os.Stat(mountPoint)
34 return "", fmt.Errorf("could not read %s: %s", mountPoint, err)
37 return "", fmt.Errorf("mount point %s is not a directory", mountPoint)
40 return FS(mountPoint), nil
43 // Path returns the path of the given subsystem relative to the procfs root.
44 func (fs FS) Path(p ...string) string {
45 return path.Join(append([]string{string(fs)}, p...)...)