add option to supplu api url
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
592fbea0e6
commit
42e2a23e26
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -607,12 +608,14 @@ func (e *Exporter) collectHotspotRewardsMetrics(wg *sync.WaitGroup, ch chan<- pr
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
fApiUrl := flag.String("apiUrl", "https://api.helium.io", "The helium api url")
|
||||||
fHeliumAccounts := flag.String("accounts", "", "A comma-delimited list of helium accounts to scrape (optional)")
|
fHeliumAccounts := flag.String("accounts", "", "A comma-delimited list of helium accounts to scrape (optional)")
|
||||||
fMetricsPath := flag.String("metricpath", "/metrics", "The metrics path")
|
fMetricsPath := flag.String("metricpath", "/metrics", "The metrics path")
|
||||||
fListenAddress := flag.String("listenAddress", "0.0.0.0", "The http server listen address")
|
fListenAddress := flag.String("listenAddress", "0.0.0.0", "The http server listen address")
|
||||||
fListenPort := flag.String("listenPort", "9865", "The http server listen port")
|
fListenPort := flag.String("listenPort", "9865", "The http server listen port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
heliumapi.ApiUrl = *fApiUrl
|
||||||
heliumAccounts := strings.Split(*fHeliumAccounts, ",")
|
heliumAccounts := strings.Split(*fHeliumAccounts, ",")
|
||||||
serverAddr := *fListenAddress + ":" + *fListenPort
|
serverAddr := *fListenAddress + ":" + *fListenPort
|
||||||
|
|
||||||
|
@ -637,5 +640,8 @@ func main() {
|
||||||
|
|
||||||
http.Handle(*fMetricsPath, promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
|
http.Handle(*fMetricsPath, promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
|
||||||
fmt.Printf("listening on %v\n", serverAddr)
|
fmt.Printf("listening on %v\n", serverAddr)
|
||||||
http.ListenAndServe(serverAddr, nil)
|
if err = http.ListenAndServe(serverAddr, nil); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func GetAccountForAddress(account string) (*Account, error) {
|
||||||
respobject := AccountResp{}
|
respobject := AccountResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
@ -49,7 +49,7 @@ func GetActivityForAccount(account string, filterTypes []string, minTime *time.T
|
||||||
activityResp := activity.ActivityResp{}
|
activityResp := activity.ActivityResp{}
|
||||||
err = json.Unmarshal(respBody, &activityResp)
|
err = json.Unmarshal(respBody, &activityResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
combinedResp.Data = append(combinedResp.Data, activityResp.Data...)
|
combinedResp.Data = append(combinedResp.Data, activityResp.Data...)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func GetActivityCountsForAccount(account string) (*ActivityCounts, error) {
|
||||||
respobject := ActivityCountsResp{}
|
respobject := ActivityCountsResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
@ -96,7 +96,7 @@ func GetRewardTotalsForAccount(account string, minTime *time.Time, maxTime *time
|
||||||
respobject := RewardTotalResp{}
|
respobject := RewardTotalResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
@ -115,7 +115,7 @@ func GetHotspotsForAccount(account string) (*[]AccountHotspot, error) {
|
||||||
respobject := AccountHotspotsResp{}
|
respobject := AccountHotspotsResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
|
|
@ -19,7 +19,7 @@ func GetHotspotActivityCount(hotspot string) (*ActivityCounts, error) {
|
||||||
respobject := ActivityCountsResp{}
|
respobject := ActivityCountsResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
@ -45,7 +45,7 @@ func GetRewardsTotalForHotspot(hotspot string, minTime *time.Time, maxTime *time
|
||||||
respobject := RewardTotalResp{}
|
respobject := RewardTotalResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetCurrentOraclePrice() (*CurrentOraclePrice, error) {
|
func GetCurrentOraclePrice() (*CurrentOraclePrice, error) {
|
||||||
const path = "/v1/oracle/prices/current"
|
path := "/v1/oracle/prices/current"
|
||||||
|
|
||||||
// query the api
|
// query the api
|
||||||
respBody, err := getHeliumApi(path, nil)
|
respBody, err := getHeliumApi(path, nil)
|
||||||
|
@ -18,7 +18,7 @@ func GetCurrentOraclePrice() (*CurrentOraclePrice, error) {
|
||||||
respobject := CurrentOraclePriceResp{}
|
respobject := CurrentOraclePriceResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
|
|
@ -7,16 +7,13 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
apiUrl = "https://api.helium.io"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
ApiUrl = "https://api.helium.io"
|
||||||
client = &http.Client{}
|
client = &http.Client{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func createGetRequest(path string, params map[string]string) (*http.Request, error) {
|
func createGetRequest(path string, params map[string]string) (*http.Request, error) {
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", apiUrl, path), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", ApiUrl, path), nil)
|
||||||
|
|
||||||
// setup headers
|
// setup headers
|
||||||
req.Header.Add("Accept", "application/json")
|
req.Header.Add("Accept", "application/json")
|
||||||
|
@ -50,14 +47,14 @@ func getHeliumApi(path string, params *map[string]string) ([]byte, error) {
|
||||||
// query the api
|
// query the api
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to query path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to query %v: %v", path, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// read the response body
|
// read the response body
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read response body of path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to read response body of %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return body, nil
|
return body, nil
|
||||||
|
@ -84,14 +81,14 @@ func getHeliumApiWithCursor(path string, params *map[string]string) ([][]byte, e
|
||||||
// query the api
|
// query the api
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to query path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to query %v: %v", path, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// read the response body and add it to the result array
|
// read the response body and add it to the result array
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read response body of path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to read response body of %v: %v", path, err)
|
||||||
}
|
}
|
||||||
res = append(res, body)
|
res = append(res, body)
|
||||||
|
|
||||||
|
@ -99,7 +96,7 @@ func getHeliumApiWithCursor(path string, params *map[string]string) ([][]byte, e
|
||||||
respCursor.Cursor = ""
|
respCursor.Cursor = ""
|
||||||
err = json.Unmarshal(body, &respCursor)
|
err = json.Unmarshal(body, &respCursor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// continue querying until there is no longer a cursor
|
// continue querying until there is no longer a cursor
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetBlockchainStats() (*BlockchainStats, error) {
|
func GetBlockchainStats() (*BlockchainStats, error) {
|
||||||
const path = "/v1/stats"
|
path := "/v1/stats"
|
||||||
|
|
||||||
// query the api
|
// query the api
|
||||||
respBody, err := getHeliumApi(path, nil)
|
respBody, err := getHeliumApi(path, nil)
|
||||||
|
@ -18,7 +18,7 @@ func GetBlockchainStats() (*BlockchainStats, error) {
|
||||||
respobject := BlockchainStatsResp{}
|
respobject := BlockchainStatsResp{}
|
||||||
err = json.Unmarshal(respBody, &respobject)
|
err = json.Unmarshal(respBody, &respobject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &respobject.Data, nil
|
return &respobject.Data, nil
|
||||||
|
|
Reference in New Issue