/
monitoring.go
80 lines (69 loc) · 2.27 KB
/
monitoring.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2016 Canonical Ltd.
package monitoring // import "gopkg.in/juju/charmstore.v5/internal/monitoring"
import (
"github.com/cloud-green/monitoring"
"github.com/prometheus/client_golang/prometheus"
)
var (
requestDuration = prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: "charmstore",
Subsystem: "handler",
Name: "request_duration",
Help: "The duration of a web request in seconds.",
}, []string{"method", "root", "kind"})
uploadProcessingDuration = prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: "charmstore",
Subsystem: "archive",
Name: "processing_duration",
Help: "The processing duration of a charm upload in seconds.",
})
blobstoreGCDuration = prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: "charmstore",
Subsystem: "archive",
Name: "blobstore_gc_duration",
Help: "The processing duration a garbage collection in seconds",
})
blobCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "charmstore",
Subsystem: "archive",
Name: "blob_count",
Help: "The total number of stored blobs.",
})
maxBlobSize = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "charmstore",
Subsystem: "archive",
Name: "max_blob_size",
Help: "The maximum stored blob size",
})
meanBlobSize = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "charmstore",
Subsystem: "archive",
Name: "mean_blob_size",
Help: "The mean stored blob size",
})
)
// BlobStats holds statistics about blobs in the blob store.
type BlobStats struct {
// Count holds the total number of blobs stored.
Count int
// MaxSize holds the size of the largest blob.
MaxSize int64
// MeanSize holds the average blob size.
MeanSize int64
// TODO add counts/sizes for different
// kinds of blob?
}
func SetBlobStoreStats(s BlobStats) {
blobCount.Set(float64(s.Count))
maxBlobSize.Set(float64(s.MaxSize))
meanBlobSize.Set(float64(s.MeanSize))
}
func init() {
prometheus.MustRegister(requestDuration)
prometheus.MustRegister(uploadProcessingDuration)
prometheus.MustRegister(blobstoreGCDuration)
prometheus.MustRegister(blobCount)
prometheus.MustRegister(maxBlobSize)
prometheus.MustRegister(meanBlobSize)
prometheus.MustRegister(monitoring.NewMgoStatsCollector("charmstore"))
}