Skip to content

Commit 7ec4b4e

Browse files
authored
Merge pull request #31 from caarlos0/more
feat: added more fields to the metrics
2 parents da1e8cd + a477c18 commit 7ec4b4e

3 files changed

Lines changed: 48 additions & 38 deletions

File tree

METRICS.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
# Metrics
22

3-
Below are an example of the metrics as exposed by this exporter.
3+
Below are an example of the metrics as exposed by this exporter.
44

55
```
6-
# HELP github_repo_open_issues open_issues
7-
# TYPE github_repo_open_issues gauge
8-
github_repo_open_issues{repo="docker-hub-exporter",user="infinityworksltd"} 1.0
9-
github_repo_open_issues{repo="prometheus-rancher-exporter",user="infinityworksltd"} 2.0
10-
# HELP github_repo_watchers watchers
11-
# TYPE github_repo_watchers gauge
12-
github_repo_watchers{repo="docker-hub-exporter",user="infinityworksltd"} 1.0
13-
github_repo_watchers{repo="prometheus-rancher-exporter",user="infinityworksltd"} 6.0
14-
# HELP github_repo_stars stars
15-
# TYPE github_repo_stars gauge
16-
github_repo_stars{repo="docker-hub-exporter",user="infinityworksltd"} 1.0
17-
github_repo_stars{repo="prometheus-rancher-exporter",user="infinityworksltd"} 6.0
18-
# HELP github_repo_forks forks
19-
# TYPE github_repo_forks gauge
20-
github_repo_forks{repo="docker-hub-exporter",user="infinityworksltd"} 0.0
21-
github_repo_forks{repo="prometheus-rancher-exporter",user="infinityworksltd"} 9.0
22-
# HELP github_repo_size_kb Size in KB for given repository
23-
# TYPE github_repo_size_kb gauge
24-
github_repo_size_kb{repo="docker-hub-exporter",user="infinityworksltd"} 44
25-
github_repo_size_kb{repo="prometheus-rancher-exporter",user="infinityworksltd"} 7242
266
# HELP github_rate_limit Number of API queries allowed in a 60 minute window
277
# TYPE github_rate_limit gauge
28-
github_rate_limit 60
8+
github_rate_limit 5000
299
# HELP github_rate_remaining Number of API queries remaining in the current window
3010
# TYPE github_rate_remaining gauge
31-
github_rate_remaining 38
11+
github_rate_remaining 2801
3212
# HELP github_rate_reset The time at which the current rate limit window resets in UTC epoch seconds
3313
# TYPE github_rate_reset gauge
34-
github_rate_reset 1.493139756e+09
35-
# HELP github_size_kb Size in KB for given repository
36-
# TYPE github_size_kb gauge
37-
github_size_kb{repo="CRUST",user="infinityworksltd"} 44
38-
```
14+
github_rate_reset 1.527709029e+09
15+
# HELP github_repo_forks Total number of forks for given repository
16+
# TYPE github_repo_forks gauge
17+
github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 19
18+
# HELP github_repo_open_issues Total number of open issues for given repository
19+
# TYPE github_repo_open_issues gauge
20+
github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 7
21+
# HELP github_repo_size_kb Size in KB for given repository
22+
# TYPE github_repo_size_kb gauge
23+
github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 41
24+
# HELP github_repo_stars Total number of Stars for given repository
25+
# TYPE github_repo_stars gauge
26+
github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 64
27+
# HELP github_repo_watchers Total number of watchers/subscribers for given repository
28+
# TYPE github_repo_watchers gauge
29+
github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 10
30+
```
31+
32+
<!--
33+
34+
The above output was generated by running:
35+
36+
```
37+
REPOS=infinityworks/github-exporter go run main.go
38+
```
39+
40+
And copying the output of http://localhost:9171/metrics
41+
42+
-->

exporter/metrics.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ func AddMetrics() map[string]*prometheus.Desc {
1111
APIMetrics["Stars"] = prometheus.NewDesc(
1212
prometheus.BuildFQName("github", "repo", "stars"),
1313
"Total number of Stars for given repository",
14-
[]string{"repo", "user", "private"}, nil,
14+
[]string{"repo", "user", "private", "fork", "archived", "license", "language"}, nil,
1515
)
1616
APIMetrics["OpenIssues"] = prometheus.NewDesc(
1717
prometheus.BuildFQName("github", "repo", "open_issues"),
1818
"Total number of open issues for given repository",
19-
[]string{"repo", "user", "private"}, nil,
19+
[]string{"repo", "user", "private", "fork", "archived", "license", "language"}, nil,
2020
)
2121
APIMetrics["Watchers"] = prometheus.NewDesc(
2222
prometheus.BuildFQName("github", "repo", "watchers"),
2323
"Total number of watchers/subscribers for given repository",
24-
[]string{"repo", "user", "private"}, nil,
24+
[]string{"repo", "user", "private", "fork", "archived", "license", "language"}, nil,
2525
)
2626
APIMetrics["Forks"] = prometheus.NewDesc(
2727
prometheus.BuildFQName("github", "repo", "forks"),
2828
"Total number of forks for given repository",
29-
[]string{"repo", "user", "private"}, nil,
29+
[]string{"repo", "user", "private", "fork", "archived", "license", "language"}, nil,
3030
)
3131
APIMetrics["Size"] = prometheus.NewDesc(
3232
prometheus.BuildFQName("github", "repo", "size_kb"),
3333
"Size in KB for given repository",
34-
[]string{"repo", "user", "private"}, nil,
34+
[]string{"repo", "user", "private", "fork", "archived", "license", "language"}, nil,
3535
)
3636
APIMetrics["Limit"] = prometheus.NewDesc(
3737
prometheus.BuildFQName("github", "rate", "limit"),
@@ -57,11 +57,11 @@ func (e *Exporter) processMetrics(data []*Datum, rates *RateLimits, ch chan<- pr
5757

5858
// APIMetrics - range through the data slice
5959
for _, x := range data {
60-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Stars"], prometheus.GaugeValue, x.Stars, x.Name, x.Owner.Login, strconv.FormatBool(x.Private))
61-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Forks"], prometheus.GaugeValue, x.Forks, x.Name, x.Owner.Login, strconv.FormatBool(x.Private))
62-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["OpenIssues"], prometheus.GaugeValue, x.OpenIssues, x.Name, x.Owner.Login, strconv.FormatBool(x.Private))
63-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Watchers"], prometheus.GaugeValue, x.Watchers, x.Name, x.Owner.Login, strconv.FormatBool(x.Private))
64-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Size"], prometheus.GaugeValue, x.Size, x.Name, x.Owner.Login, strconv.FormatBool(x.Private))
60+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Stars"], prometheus.GaugeValue, x.Stars, x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
61+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Forks"], prometheus.GaugeValue, x.Forks, x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
62+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["OpenIssues"], prometheus.GaugeValue, x.OpenIssues, x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
63+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Watchers"], prometheus.GaugeValue, x.Watchers, x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
64+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Size"], prometheus.GaugeValue, x.Size, x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
6565

6666
}
6767

exporter/structs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ type Datum struct {
2525
Owner struct {
2626
Login string `json:"login"`
2727
} `json:"owner"`
28+
License struct {
29+
Key string `json:"key"`
30+
} `json:"license"`
31+
Language string `json:"language"`
32+
Archived bool `json:"archived"`
2833
Private bool `json:"private"`
34+
Fork bool `json:"fork"`
2935
Forks float64 `json:"forks"`
3036
Stars float64 `json:"stargazers_count"`
3137
OpenIssues float64 `json:"open_issues"`

0 commit comments

Comments
 (0)