Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // API response example
- // ["7.3" #0 miner_version tag
- // "0" #1 uptime measurement
- // "145834;5;0" #2 ethereum_hashrate;shares;rejected measurements
- // "24244;24383;24360;24264;24185;24396" #3 ethereum_hashrates_per_gpu measurements
- // "0;0;0" #4 secondary_hashrate;shares;rejected measurements
- // "off;off;off;off;off;off" #5 secondary_hashrates_per_gpu measurements
- // "54;38;54;35;54;37;71;40;69;36;64;27" #6 tempfan_per_gpu measurements
- // "eu.alpereum.ch:3002" #7 pools tag
- // "0;0;0;0"] #8 invalids_and_pool_switches measurements
- func parse(response []string) (metrics []formats.Metric, err error) {
- rig_id, _ := os.Hostname()
- // uptime
- tags := map[string]string{
- "rig": rig_id,
- "miner_version": response[0],
- }
- value, _ := strconv.Atoi(response[1])
- metrics = append(metrics,
- formats.Metric{
- Name: "uptime",
- Value: value,
- Tags: tags,
- })
- // totals
- tags = map[string]string{
- "rig": rig_id,
- "miner_version": response[0],
- "pools": response[7],
- }
- coin_index := map[string]int{
- "ethereum": 2,
- "secondary": 4,
- }
- metric_index := map[string]int{
- "hashrate": 0,
- "shares": 1,
- "rejected": 2,
- }
- for coin, index := range coin_index {
- tags["coin"] = coin
- s := strings.Split(response[index], ";")
- for name, i := range metric_index {
- if s[i] == "off" {
- s[i] = "0"
- }
- value, _ := strconv.Atoi(s[i])
- fmt.Println(tags)
- metrics = append(metrics,
- formats.Metric{
- Name: name,
- Value: value,
- Tags: tags,
- })
- }
- }
- // // per-gpu performance
- // tags = map[string]string{
- // "rig": rig_id,
- // "miner_version": response[0],
- // "pools": response[7],
- // }
- // coin_index = map[string]int{
- // "ethereum": 3,
- // "secondary": 5,
- // }
- //
- // for coin, index := range coin_index {
- // tags["coin"] = coin
- // s := strings.Split(response[index], ";")
- // for i := range s {
- // if s[i] == "off" {
- // s[i] = "0"
- // }
- // tags["gpu"] = strconv.Itoa(i)
- // value, _ := strconv.Atoi(s[i])
- // metrics = append(metrics,
- // formats.Metric{
- // Name: "hashrate",
- // Value: value,
- // Tags: tags,
- // })
- // }
- // }
- //
- // // gpu_health measurement
- // tags = map[string]string{
- // "rig": rig_id,
- // "miner_version": response[0],
- // }
- //
- // tempfan := strings.Split(response[6], ";")
- // for i := 0; i < len(tempfan)/2; i++ {
- // tags["gpu"] = strconv.Itoa(i)
- // value, _ := strconv.Atoi(tempfan[2*i])
- // metrics = append(metrics,
- // formats.Metric{
- // Name: "temperature",
- // Value: value,
- // Tags: tags,
- // })
- // value, _ = strconv.Atoi(tempfan[2*i+1])
- // metrics = append(metrics,
- // formats.Metric{
- // Name: "fan_speed",
- // Value: value,
- // Tags: tags,
- // })
- // }
- return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement