mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 02:35:07 +01:00 
			
		
		
		
	Add option to LustreCollector to call lctl with sudo
This commit is contained in:
		@@ -22,6 +22,7 @@ type LustreCollectorConfig struct {
 | 
			
		||||
	LCtlCommand    string   `json:"lctl_command"`
 | 
			
		||||
	ExcludeMetrics []string `json:"exclude_metrics"`
 | 
			
		||||
	SendAllMetrics bool     `json:"send_all_metrics"`
 | 
			
		||||
	Sudo           bool     `json:"use_sudo"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type LustreCollector struct {
 | 
			
		||||
@@ -31,11 +32,17 @@ type LustreCollector struct {
 | 
			
		||||
	stats   map[string]map[string]int64
 | 
			
		||||
	config  LustreCollectorConfig
 | 
			
		||||
	lctl    string
 | 
			
		||||
	sudoCmd string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *LustreCollector) getDeviceDataCommand(device string) []string {
 | 
			
		||||
	var command *exec.Cmd
 | 
			
		||||
	statsfile := fmt.Sprintf("llite.%s.stats", device)
 | 
			
		||||
	command := exec.Command(m.lctl, LCTL_OPTION, statsfile)
 | 
			
		||||
	if m.config.Sudo {
 | 
			
		||||
		command = exec.Command(m.sudoCmd, m.lctl, LCTL_OPTION, statsfile)
 | 
			
		||||
	} else {
 | 
			
		||||
		command = exec.Command(m.lctl, LCTL_OPTION, statsfile)
 | 
			
		||||
	}
 | 
			
		||||
	command.Wait()
 | 
			
		||||
	stdout, _ := command.Output()
 | 
			
		||||
	return strings.Split(string(stdout), "\n")
 | 
			
		||||
@@ -136,6 +143,12 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	m.lctl = p
 | 
			
		||||
	if m.config.Sudo {
 | 
			
		||||
		p, err := exec.LookPath("sudo")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			m.sudoCmd = p
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	devices := m.getDevices()
 | 
			
		||||
	if len(devices) == 0 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user