func cgUnifiedCached() (cgUnifiedMountMode, error) {
	if cgroupUnified != unifModeUnknown {
		return cgroupUnified, nil
	}
	var fs unix.Statfs_t
	err := unix.Statfs("/sys/fs/cgroup/", &fs)
	if err != nil {
		return unifModeUnknown, errors.Wrapf(err, "failed statfs(/sys/fs/cgroup)")
	}
	switch fs.Type {
	case cgroup2SuperMagic:
		log.Debugf("Found cgroup2 on /sys/fs/cgroup, full unified hierarchy")
		cgroupUnified = unifModeAll
	case tmpFsMagic:
		err := unix.Statfs("/sys/fs/cgroup/unified", &fs)
		if err == nil && fs.Type == cgroup2SuperMagic {
			log.Debugf("Found cgroup2 on /sys/fs/cgroup/systemd, unified hierarchy for systemd controller")
			cgroupUnified = unifModeSystemd
		} else {
			err := unix.Statfs("/sys/fs/cgroup/systemd", &fs)
			if err != nil {
				return unifModeUnknown, errors.Wrapf(err, "failed statfs(/sys/fs/cgroup/systemd)")
			}
			switch fs.Type {
			case cgroup2SuperMagic:
				log.Debugf("Found cgroup2 on /sys/fs/cgroup/systemd, unified hierarchy for systemd controller (v232 variant)")
				cgroupUnified = unifModeSystemd
			case cgroupSuperMagic:
				log.Debugf("Found cgroup on /sys/fs/cgroup/systemd, legacy hierarchy")
				cgroupUnified = unifModeNone
			default:
				return unifModeUnknown, errors.Errorf("unknown magic number %x for fstype returned by statfs(/sys/fs/cgroup/systemd)", fs.Type)
			}
		}
	default:
		return unifModeUnknown, errors.Errorf("unknown magic number %x for fstype returned by statfs(/sys/fs/cgroup)", fs.Type)
	}
	return cgroupUnified, nil
}
cgUnifiedCached checks the filesystem types mounted under /sys/fs/cgroup to determine
which systemd layout (legacy/hybrid/unified) is in use.
We do not bother to track unified_systemd_v232 as our usage does not
depend on reading the systemd hierarchy directly, we only focus on reading
the controllers. If you care if /sys/fs/cgroup/systemd is v1 or v2 you need
to track this
WARNING: We cache this data once at process start. Systemd updates
may require restarting systemd-exporter
package systemd
import (
	"bufio"
	"bytes"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"github.com/pkg/errors"
	"github.com/prometheus/common/log"
	"golang.org/x/sys/unix"
)
type cgUnifiedMountMode int8
const (
	unifModeUnknown cgUnifiedMountMode = iota
	unifModeNone cgUnifiedMountMode = iota
	unifModeSystemd cgUnifiedMountMode = iota
	unifModeAll cgUnifiedMountMode = iota
)
var cgroupUnified cgUnifiedMountMode = unifModeUnknown
const (
	tmpFsMagic        = 0x01021994
	cgroupSuperMagic  = 0x27e0eb
	cgroup2SuperMagic = 0x63677270
)