|
19 | 19 | xmrigProcess *exec.Cmd
|
20 | 20 | )
|
21 | 21 |
|
| 22 | +type Hashrate struct { |
| 23 | + Total []float64 `json:"total"` |
| 24 | + Highest float64 `json:"highest"` |
| 25 | +} |
| 26 | + |
| 27 | +type SummaryResponse struct { |
| 28 | + Hashrate Hashrate `json:"hashrate"` |
| 29 | +} |
| 30 | + |
22 | 31 | type User struct {
|
23 | 32 | Name string `json:"name"`
|
24 | 33 | GitHub string `json:"github"`
|
@@ -80,7 +89,13 @@ func startP2Pool(host, address, path string) error {
|
80 | 89 | }
|
81 | 90 |
|
82 | 91 | func startXmrig(path string) error {
|
83 |
| - xmrigProcess = exec.Command(path, "-o", "127.0.0.1:3333") |
| 92 | + xmrigProcess = exec.Command(path, |
| 93 | + "-o", "127.0.0.1:3333", |
| 94 | + "--http-host=127.0.0.1", |
| 95 | + "--http-port=9999", |
| 96 | + "--http-access-token=dmvp2p", |
| 97 | + "--api-worker-id=1", |
| 98 | + "--api-id=1") |
84 | 99 |
|
85 | 100 | if err := xmrigProcess.Start(); err != nil {
|
86 | 101 | return fmt.Errorf("failed to start xmrig: %w", err)
|
@@ -133,3 +148,56 @@ func SelectFileWithDialog(label *widget.Label, settingsPath *string) {
|
133 | 148 | *settingsPath = selectedPath
|
134 | 149 | label.SetText("Selected file: " + *settingsPath)
|
135 | 150 | }
|
| 151 | + |
| 152 | +func GetXmrigStats() Hashrate { |
| 153 | + url := "http://127.0.0.1:9999/1/summary" |
| 154 | + token := "dmvp2p" |
| 155 | + |
| 156 | + client := &http.Client{} |
| 157 | + |
| 158 | + req, err := http.NewRequest("GET", url, nil) |
| 159 | + if err != nil { |
| 160 | + fmt.Printf("Error creating request: %v\n", err) |
| 161 | + return Hashrate{} |
| 162 | + } |
| 163 | + |
| 164 | + req.Header.Add("Authorization", "Bearer "+token) |
| 165 | + |
| 166 | + resp, err := client.Do(req) |
| 167 | + if err != nil { |
| 168 | + fmt.Printf("Error making request: %v\n", err) |
| 169 | + return Hashrate{} |
| 170 | + } |
| 171 | + defer resp.Body.Close() |
| 172 | + |
| 173 | + if resp.StatusCode != http.StatusOK { |
| 174 | + fmt.Printf("Received non-OK HTTP status: %s\n", resp.Status) |
| 175 | + return Hashrate{} |
| 176 | + } |
| 177 | + |
| 178 | + body, err := ioutil.ReadAll(resp.Body) |
| 179 | + if err != nil { |
| 180 | + fmt.Printf("Error reading response body: %v\n", err) |
| 181 | + return Hashrate{} |
| 182 | + } |
| 183 | + |
| 184 | + var summary SummaryResponse |
| 185 | + err = json.Unmarshal(body, &summary) |
| 186 | + if err != nil { |
| 187 | + fmt.Printf("Error parsing JSON response: %v\n", err) |
| 188 | + return Hashrate{} |
| 189 | + } |
| 190 | + |
| 191 | + totalHashrate := 0.0 |
| 192 | + if len(summary.Hashrate.Total) > 0 { |
| 193 | + totalHashrate = summary.Hashrate.Total[0] |
| 194 | + } |
| 195 | + |
| 196 | + fmt.Printf("Total Hashrate: %.2f H/s\n", totalHashrate) |
| 197 | + fmt.Printf("Highest Hashrate: %.2f H/s\n", summary.Hashrate.Highest) |
| 198 | + |
| 199 | + return Hashrate{ |
| 200 | + Total: []float64{totalHashrate}, |
| 201 | + Highest: summary.Hashrate.Highest, |
| 202 | + } |
| 203 | +} |
0 commit comments