Hello again all. I have been in the midst of trying to get back into programming, specifically Go, and come to you for help once more. The objective is to create a custom collector for FreeNAS. This will work within the node exporter that gives metrics to Prometheus, a newer monitoring system. I have had a basic version working here, https://forums.freenas.org/index.php?threads/freenas-esxi-lab-build-log.61833/page-8#post-450251, but ran into a few problems. I just finished with the udemy course, https://www.udemy.com/learn-how-to-code/, and am trying to put that to use in better understanding the code within the Prometheus project (in go) and for professional/home lab use. My first priority is to get temperature monitoring fixed. I can then expand to export whatever metrics people are interested in. I am doing this as I don't feel like email alerts are adequate, and I want to learn
Problem #1 - The current CPU temperature reads as 400 M. While I know I am undervolting the fans...
https://github.com/prometheus/node_exporter/blob/master/collector/cpu_freebsd.go
This takes the temperature from...(next) and then does a conversion (no idea to or from what) before sending it off to a channel (spaced use for concurrent and parallel processing)
https://github.com/golang/sys/blob/master/unix/syscall_bsd.go (took out error detecting)
Which calls...not gonna keep going down the wormhole.
I propose writing a new program, creating a slice of structs for the CPUs and a slice of structs for the drives. This allows expansion as we can add in additional fields their respective calls. I need to translate the shell scripts used for the drive and CPU temperatures that I previously mushed together with the SMART report. The scripts are here: https://github.com/Spearfoot/FreeNAS-scripts. I then need to get those translated scripts to feed into the Prometheus node exporter like the other collectors. Any help or guidance is appreciated. I will post up what I have so far soon.
<I moved the code to a second post so it will be easier to update. Eventually I will just update it via github...>
I know there is a bit of work and understanding to get through, but I'm hitting a bit of a wall and thought it worthwhile to reach out for help here. I have tried the Golang and Prometheus IRC channels without much luck.
After going back and re-reading some of the posts related to creating a custom collector, it appears just running a script on CRON that appends the data to the exported text file is the best bet. I really want to get a custom one done in Go though...
I think I may actually have it, though now I need to test it. Now that I have it nearly ready, I realized that I am going to have to make two separate collectors, one for the CPU info (from IPMI) and one for the drive temps (from FreeNAS). It may almost be easier to use the IPMI exporter and try to modify one of the working disk collectors...
Problem #1 - The current CPU temperature reads as 400 M. While I know I am undervolting the fans...
https://github.com/prometheus/node_exporter/blob/master/collector/cpu_freebsd.go
Code:
temp, err := unix.SysctlUint32(fmt.Sprintf("dev.cpu.%d.temperature", cpu)) ...error handlng ch <- c.temp.mustNewConstMetric(float64(temp-2732)/10, lcpu)
This takes the temperature from...(next) and then does a conversion (no idea to or from what) before sending it off to a channel (spaced use for concurrent and parallel processing)
https://github.com/golang/sys/blob/master/unix/syscall_bsd.go (took out error detecting)
Code:
func SysctlUint32(name string) (uint32, error) { return SysctlUint32Args(name) } func SysctlUint32Args(name string, args ...int) (uint32, error) { mib, err := sysctlmib(name, args...) n := uintptr(4) buf := make([]byte, 4) if err := sysctl(mib, &buf[0], &n, nil, 0); err != nil { return 0, err } if n != 4 { return 0, EIO } return *(*uint32)(unsafe.Pointer(&buf[0])), nil }
Which calls...not gonna keep going down the wormhole.
I propose writing a new program, creating a slice of structs for the CPUs and a slice of structs for the drives. This allows expansion as we can add in additional fields their respective calls. I need to translate the shell scripts used for the drive and CPU temperatures that I previously mushed together with the SMART report. The scripts are here: https://github.com/Spearfoot/FreeNAS-scripts. I then need to get those translated scripts to feed into the Prometheus node exporter like the other collectors. Any help or guidance is appreciated. I will post up what I have so far soon.
<I moved the code to a second post so it will be easier to update. Eventually I will just update it via github...>
I know there is a bit of work and understanding to get through, but I'm hitting a bit of a wall and thought it worthwhile to reach out for help here. I have tried the Golang and Prometheus IRC channels without much luck.
After going back and re-reading some of the posts related to creating a custom collector, it appears just running a script on CRON that appends the data to the exported text file is the best bet. I really want to get a custom one done in Go though...
I think I may actually have it, though now I need to test it. Now that I have it nearly ready, I realized that I am going to have to make two separate collectors, one for the CPU info (from IPMI) and one for the drive temps (from FreeNAS). It may almost be easier to use the IPMI exporter and try to modify one of the working disk collectors...
Last edited: