forked from pachyderm/pachyderm
/
metrics.go
64 lines (59 loc) · 1.83 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package metrics
import (
"time"
"github.com/pachyderm/pachyderm/src/client/pkg/uuid"
"github.com/pachyderm/pachyderm/src/client/version"
db "github.com/pachyderm/pachyderm/src/server/pfs/db"
"github.com/dancannon/gorethink"
"go.pedge.io/lion/proto"
kube "k8s.io/kubernetes/pkg/client/unversioned"
)
func dbMetrics(dbClient *gorethink.Session, pfsDbName string, ppsDbName string, metrics *Metrics) {
cursor, err := gorethink.Object(
"Repos",
gorethink.DB(pfsDbName).Table("Repos").Count(),
"Commits",
gorethink.DB(pfsDbName).Table("Commits").Count(),
"ArchivedCommits",
gorethink.DB(pfsDbName).Table("Commits").Filter(
map[string]interface{}{
"Archived": true,
},
).Count(),
"CancelledCommits",
gorethink.DB(pfsDbName).Table("Commits").Filter(
map[string]interface{}{
"Cancelled": true,
},
).Count(),
"Files",
gorethink.DB(pfsDbName).Table("Diffs").Group("Path").Ungroup().Count(),
"Jobs",
gorethink.DB(ppsDbName).Table("JobInfos").Count(),
"Pipelines",
gorethink.DB(ppsDbName).Table("PipelineInfos").Count(),
).Run(dbClient)
if err != nil {
protolion.Errorf("Error Fetching Metrics:%+v", err)
}
cursor.One(&metrics)
}
// ReportMetrics blocks and reports metrics, if modified, to the
// given kubernetes client every 15 seconds.
func ReportMetrics(clusterID string, kubeClient *kube.Client, address string, pfsDbName string, ppsDbName string) {
dbClient, err := db.DbConnect(address)
if err != nil {
protolion.Errorf("Error connected to DB when reporting metrics: %v\n", err)
return
}
for {
metrics := &Metrics{}
dbMetrics(dbClient, pfsDbName, ppsDbName, metrics)
externalMetrics(kubeClient, metrics)
metrics.ID = clusterID
metrics.PodID = uuid.NewWithoutDashes()
metrics.Version = version.PrettyPrintVersion(version.Version)
reportSegment(metrics)
<-time.After(15 * time.Second)
}
}