master
go 90 lines 1.69 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package dockerhub
4
5 import (
6 "strings"
7
8 "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi"
9 )
10
11 type (
12 // Charts is an alias for collectorapi.Charts
13 Charts = collectorapi.Charts
14 // Dims is an alias for collectorapi.Dims
15 Dims = collectorapi.Dims
16 // Dim is an alias for collectorapi.Dim
17 Dim = collectorapi.Dim
18 )
19
20 var charts = Charts{
21 {
22 ID: "pulls_sum",
23 Title: "Pulls Summary",
24 Units: "pulls",
25 Fam: "pulls",
26 Dims: Dims{
27 {ID: "pull_sum", Name: "sum"},
28 },
29 },
30 {
31 ID: "pulls",
32 Title: "Pulls",
33 Units: "pulls",
34 Fam: "pulls",
35 Type: collectorapi.Stacked,
36 },
37 {
38 ID: "pulls_rate",
39 Title: "Pulls Rate",
40 Units: "pulls/s",
41 Fam: "pulls",
42 Type: collectorapi.Stacked,
43 },
44 {
45 ID: "stars",
46 Title: "Stars",
47 Units: "stars",
48 Fam: "stars",
49 Type: collectorapi.Stacked,
50 },
51 {
52 ID: "status",
53 Title: "Current Status",
54 Units: "status",
55 Fam: "status",
56 },
57 {
58 ID: "last_updated",
59 Title: "Time Since Last Updated",
60 Units: "seconds",
61 Fam: "last updated",
62 },
63 }
64
65 func addReposToCharts(repositories []string, cs *Charts) {
66 for _, name := range repositories {
67 dimName := strings.ReplaceAll(name, "/", "_")
68 _ = cs.Get("pulls").AddDim(&Dim{
69 ID: "pull_count_" + name,
70 Name: dimName,
71 })
72 _ = cs.Get("pulls_rate").AddDim(&Dim{
73 ID: "pull_count_" + name,
74 Name: dimName,
75 Algo: collectorapi.Incremental,
76 })
77 _ = cs.Get("stars").AddDim(&Dim{
78 ID: "star_count_" + name,
79 Name: dimName,
80 })
81 _ = cs.Get("status").AddDim(&Dim{
82 ID: "status_" + name,
83 Name: dimName,
84 })
85 _ = cs.Get("last_updated").AddDim(&Dim{
86 ID: "last_updated_" + name,
87 Name: dimName,
88 })
89 }
90 }