Ejemplo n.º 1
0
func main() {
	gosensors.Init()
	defer gosensors.Cleanup()

	chips := gosensors.GetDetectedChips()

	for i := 0; i < len(chips); i++ {
		chip := chips[i]

		fmt.Printf("%v\n", chip)
		fmt.Printf("Adapter: %v\n", chip.AdapterName())

		features := chip.GetFeatures()

		for j := 0; j < len(features); j++ {
			feature := features[j]

			fmt.Printf("%v ('%v'): %.1f\n", feature.Name, feature.GetLabel(), feature.GetValue())

			subfeatures := feature.GetSubFeatures()

			for k := 0; k < len(subfeatures); k++ {
				subfeature := subfeatures[k]

				fmt.Printf("  %v: %.1f\n", subfeature.Name, subfeature.GetValue())
			}
		}

		fmt.Printf("\n")
	}
}
Ejemplo n.º 2
0
func (s *Sensors) Gather(acc inputs.Accumulator) error {
	gosensors.Init()
	defer gosensors.Cleanup()

	for _, chip := range gosensors.GetDetectedChips() {
		for _, feature := range chip.GetFeatures() {
			chipName := chip.String()
			featureLabel := feature.GetLabel()

			if len(s.Sensors) != 0 {
				var found bool

				for _, sensor := range s.Sensors {
					parts := strings.SplitN(":", sensor, 2)

					if parts[0] == chipName {
						if parts[1] == "*" || parts[1] == featureLabel {
							found = true
							break
						}
					}
				}

				if !found {
					continue
				}
			}

			tags := map[string]string{
				"chip":          chipName,
				"adapter":       chip.AdapterName(),
				"feature-name":  feature.Name,
				"feature-label": featureLabel,
			}

			fieldName := chipName + ":" + featureLabel

			fields := map[string]interface{}{
				fieldName: feature.GetValue(),
			}

			acc.AddFields("sensors", fields, tags)
		}
	}

	return nil
}