Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 3.18 KB | None | 0 0
  1. // API response example
  2. // ["7.3"                                 #0 miner_version                       tag
  3. // "0"                                    #1 uptime                              measurement
  4. // "145834;5;0"                           #2 ethereum_hashrate;shares;rejected   measurements
  5. // "24244;24383;24360;24264;24185;24396"  #3 ethereum_hashrates_per_gpu          measurements
  6. // "0;0;0"                                #4 secondary_hashrate;shares;rejected  measurements
  7. // "off;off;off;off;off;off"              #5 secondary_hashrates_per_gpu         measurements
  8. // "54;38;54;35;54;37;71;40;69;36;64;27"  #6 tempfan_per_gpu                     measurements
  9. // "eu.alpereum.ch:3002"                  #7 pools                               tag
  10. // "0;0;0;0"]                             #8 invalids_and_pool_switches          measurements
  11.  
  12. func parse(response []string) (metrics []formats.Metric, err error) {
  13.     rig_id, _ := os.Hostname()
  14.  
  15.     // uptime
  16.     tags := map[string]string{
  17.         "rig":           rig_id,
  18.         "miner_version": response[0],
  19.     }
  20.     value, _ := strconv.Atoi(response[1])
  21.  
  22.     metrics = append(metrics,
  23.         formats.Metric{
  24.             Name:  "uptime",
  25.             Value: value,
  26.             Tags:  tags,
  27.         })
  28.  
  29.     // totals
  30.     tags = map[string]string{
  31.         "rig":           rig_id,
  32.         "miner_version": response[0],
  33.         "pools":         response[7],
  34.     }
  35.     coin_index := map[string]int{
  36.         "ethereum":  2,
  37.         "secondary": 4,
  38.     }
  39.     metric_index := map[string]int{
  40.         "hashrate": 0,
  41.         "shares":   1,
  42.         "rejected": 2,
  43.     }
  44.  
  45.     for coin, index := range coin_index {
  46.         tags["coin"] = coin
  47.         s := strings.Split(response[index], ";")
  48.         for name, i := range metric_index {
  49.             if s[i] == "off" {
  50.                 s[i] = "0"
  51.             }
  52.             value, _ := strconv.Atoi(s[i])
  53.             fmt.Println(tags)
  54.             metrics = append(metrics,
  55.                 formats.Metric{
  56.                     Name:  name,
  57.                     Value: value,
  58.                     Tags:  tags,
  59.                 })
  60.         }
  61.     }
  62.  
  63.     // // per-gpu performance
  64.     // tags = map[string]string{
  65.     //  "rig":           rig_id,
  66.     //  "miner_version": response[0],
  67.     //  "pools":          response[7],
  68.     // }
  69.     // coin_index = map[string]int{
  70.     //  "ethereum":  3,
  71.     //  "secondary": 5,
  72.     // }
  73.     //
  74.     // for coin, index := range coin_index {
  75.     //  tags["coin"] = coin
  76.     //  s := strings.Split(response[index], ";")
  77.     //  for i := range s {
  78.     //      if s[i] == "off" {
  79.     //          s[i] = "0"
  80.     //      }
  81.     //      tags["gpu"] = strconv.Itoa(i)
  82.     //      value, _ := strconv.Atoi(s[i])
  83.     //      metrics = append(metrics,
  84.     //          formats.Metric{
  85.     //              Name:  "hashrate",
  86.     //              Value: value,
  87.     //              Tags:  tags,
  88.     //          })
  89.     //  }
  90.     // }
  91.     //
  92.     // // gpu_health measurement
  93.     // tags = map[string]string{
  94.     //  "rig":           rig_id,
  95.     //  "miner_version": response[0],
  96.     // }
  97.     //
  98.     // tempfan := strings.Split(response[6], ";")
  99.     // for i := 0; i < len(tempfan)/2; i++ {
  100.     //  tags["gpu"] = strconv.Itoa(i)
  101.     //  value, _ := strconv.Atoi(tempfan[2*i])
  102.     //  metrics = append(metrics,
  103.     //      formats.Metric{
  104.     //          Name:  "temperature",
  105.     //          Value: value,
  106.     //          Tags:  tags,
  107.     //      })
  108.     //  value, _ = strconv.Atoi(tempfan[2*i+1])
  109.     //  metrics = append(metrics,
  110.     //      formats.Metric{
  111.     //          Name:  "fan_speed",
  112.     //          Value: value,
  113.     //          Tags:  tags,
  114.     //      })
  115.     // }
  116.  
  117.     return
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement