forked from timescale/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 6
/
disk.go
83 lines (68 loc) · 2.08 KB
/
disk.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
81
82
83
package devops
import (
"fmt"
"math/rand"
"time"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/common"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/serialize"
)
const (
OneTerabyte = 1 << 40
inodeSize = 4096
)
var (
labelDisk = []byte("disk") // heap optimization
TotalByteString = []byte("total")
FreeByteString = []byte("free")
UsedByteString = []byte("used")
UsedPercentByteString = []byte("used_percent")
INodesTotalByteString = []byte("inodes_total")
INodesFreeByteString = []byte("inodes_free")
INodesUsedByteString = []byte("inodes_used")
DiskTags = [][]byte{
[]byte("path"),
[]byte("fstype"),
}
DiskFSTypeChoices = [][]byte{
[]byte("ext3"),
[]byte("ext4"),
[]byte("btrfs"),
}
)
type DiskMeasurement struct {
*subsystemMeasurement
path, fsType []byte
uptime time.Duration
}
func NewDiskMeasurement(start time.Time) *DiskMeasurement {
path := []byte(fmt.Sprintf("/dev/sda%d", rand.Intn(10)))
fsType := DiskFSTypeChoices[rand.Intn(len(DiskFSTypeChoices))]
sub := newSubsystemMeasurement(start, 1)
sub.distributions[0] = common.CWD(common.ND(50, 1), 0, OneTerabyte, OneTerabyte/2)
return &DiskMeasurement{
subsystemMeasurement: sub,
path: path,
fsType: fsType,
}
}
func (m *DiskMeasurement) ToPoint(p *serialize.Point) {
p.SetMeasurementName(labelDisk)
p.SetTimestamp(&m.timestamp)
p.AppendTag(DiskTags[0], m.path)
p.AppendTag(DiskTags[1], m.fsType)
// the only thing that actually changes is the free byte count:
free := int64(m.distributions[0].Get())
total := int64(OneTerabyte)
used := total - free
usedPercent := int64(100.0 * (float64(used) / float64(total)))
inodesTotal := total / inodeSize
inodesFree := free / inodeSize
inodesUsed := used / inodeSize
p.AppendField(TotalByteString, total)
p.AppendField(FreeByteString, free)
p.AppendField(UsedByteString, used)
p.AppendField(UsedPercentByteString, usedPercent)
p.AppendField(INodesTotalByteString, inodesTotal)
p.AppendField(INodesFreeByteString, inodesFree)
p.AppendField(INodesUsedByteString, inodesUsed)
}