-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a6bd9a
commit 41f9ec3
Showing
5 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package egym | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
var ( | ||
exerciseMuscleMap = map[string]string{ | ||
"994": "QUADRICEPS", | ||
"997": "HAMSTRING", | ||
"996": "LOWER_BACK", | ||
"995": "ABS", | ||
"1000": "LATS", | ||
"1011": "SHOULDER", | ||
"999": "UPPER_BACK", | ||
"998": "CHEST", | ||
"1003": "OUTER_HIPS", | ||
"1004": "INNER_HIPS", | ||
"1001": "GLUTEUS", | ||
} | ||
) | ||
|
||
func (c *EgymClient) GetStrengthMetrics() (*[]StrengthMetric, error) { | ||
url := fmt.Sprintf("%s/measurements/api/v1.0/exercisers/%s/strength/latest", c.apiUrl, c.userId) | ||
body, err := c.fetch(url, 1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var response GetStrengthMetricsResponse | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &response.StrengthMeasurements, nil | ||
} | ||
|
||
func (c *EgymClient) GetMuscleFromStrengthExercise(exerciseCode string) string { | ||
return exerciseMuscleMap[exerciseCode] | ||
} | ||
|
||
type GetStrengthMetricsResponse struct { | ||
StrengthMeasurements []StrengthMetric `json:"strengthMeasurements"` | ||
} | ||
|
||
type StrengthMetric struct { | ||
CreatedAt string `json:"createdAt"` | ||
Timezone string `json:"timezone"` | ||
Source string `json:"source"` | ||
SourceLabel string `json:"sourceLabel"` | ||
BodyRegion string `json:"bodyRegion"` | ||
Exercise struct { | ||
Code string `json:"code"` | ||
Label string `json:"label"` | ||
} `json:"exercise"` | ||
Strength struct { | ||
Value float64 `json:"value"` | ||
Progress string `json:"progress"` | ||
PercentageDiff float64 `json:"percentageDiff"` | ||
AmountDiff float64 `json:"amountDiff"` | ||
CreatedAt string `json:"createdAt"` | ||
Timezone string `json:"timezone"` | ||
} `json:"strength"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package exporter | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
const strengthNamespace = "strength" | ||
|
||
var ( | ||
strengthLabels = []string{"source", "source_label", "body_region", "muscle", "exercise", "exercise_code", "progress"} | ||
|
||
strengthMetrics = prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, strengthNamespace, "metrics"), | ||
"Strength metrics", | ||
append(labels, strengthLabels...), | ||
nil, | ||
) | ||
) | ||
|
||
func (e *EgymExporter) describeStrengthMetrics(ch chan<- *prometheus.Desc) { | ||
ch <- strengthMetrics | ||
} | ||
|
||
func (e *EgymExporter) collectStrengthMetrics(ch chan<- prometheus.Metric) { | ||
strengths, err := e.client.GetStrengthMetrics() | ||
if err != nil { | ||
log.Error("could not retrieve strength metrics", err) | ||
return | ||
} | ||
|
||
for _, s := range *strengths { | ||
ch <- prometheus.MustNewConstMetric( | ||
strengthMetrics, | ||
prometheus.GaugeValue, | ||
s.Strength.Value, | ||
e.client.Username, | ||
s.Source, | ||
s.SourceLabel, | ||
s.BodyRegion, | ||
e.client.GetMuscleFromStrengthExercise(s.Exercise.Code), | ||
s.Exercise.Code, | ||
s.Exercise.Label, | ||
s.Strength.Progress, | ||
) | ||
} | ||
} |