-
Notifications
You must be signed in to change notification settings - Fork 22
/
snapshots.go
74 lines (64 loc) · 1.6 KB
/
snapshots.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
package metrix
import (
"github.com/megamsys/vertice/carton"
"time"
)
const (
SNAPSHOTS = "snapshots"
SNAPSHOT_SENSOR = "instance.snapshots.exists"
)
type Snapshots struct {
DefaultUnits map[string]string
RawStatus []byte
}
func (r *Snapshots) Prefix() string {
return SNAPSHOTS
}
func (r *Snapshots) DeductBill(c *MetricsCollection) (e error) {
for _, mc := range c.Sensors {
mkBalance(mc, r.DefaultUnits)
}
return
}
func (s *Snapshots) Collect(c *MetricsCollection) (e error) {
snp := carton.Snaps{}
snps, e := snp.GetBox()
if e != nil {
return
}
s.CollectMetricsFromStats(c, snps)
e = s.DeductBill(c)
return
}
func (c *Snapshots) ReadUsers() ([]*carton.Account, error) {
act := new(carton.Account)
res, e := act.GetUsers()
if e != nil {
return nil, e
}
return res, nil
}
//actually the NewSensor can create trypes based on the event type.
func (c *Snapshots) CollectMetricsFromStats(mc *MetricsCollection, snps []carton.Snaps) {
for _, a := range snps {
if !a.IsQuota() && a.IsAlive() {
sc := NewSensor(SNAPSHOT_SENSOR)
sc.AccountId = a.AccountId
sc.AssemblyId = a.AssemblyId
sc.System = c.Prefix()
sc.Node = ""
sc.AssemblyName = a.Name
sc.AssembliesId = a.Id
sc.Source = c.Prefix()
sc.Message = "snapshot billing"
sc.Status = "health-ok"
sc.AuditPeriodBeginning = time.Now().Add(-MetricsInterval).Format(time.RFC3339)
sc.AuditPeriodEnding = time.Now().Format(time.RFC3339)
sc.AuditPeriodDelta = ""
sc.addMetric(STORAGE_COST, c.DefaultUnits[STORAGE_COST_PER_HOUR], a.Sizeof(), "delta")
sc.CreatedAt = time.Now()
mc.Add(sc)
}
}
return
}