summaryrefslogtreecommitdiff
path: root/rrdformat/format.go
blob: f9b8504eec5888588475c2652618c3fbc7d3b33c (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package rrdformat

import (
	"git.lukeshu.com/go/librrd/rrdformat/rrdbinary"
)

// File format versions:
//
// For the most part, the layout of the file format hasn't
// changed--the version number just indicates which enum members you
// need to support.  The only parser-breaking change is that the
// 0002->0003 transition added a few bytes to the timestamp, in order
// to go from second-precision to microsecond-precision.
//
//  - "0005" (added in rrdtool 1.5.0, 2015-04-16)
//    * added DST_DCOUNTER
//    * added DST_DDERIVE
//    * otherwise identical to "0004"
//
//  - "0004" (added in rrdtool 1.3.0, 2008-06-10)
//    * added MHWPREDICT function
//    * otherwise identical to "0003"
//
//  - "0003" (added in the unreleased rrdtool 1.1.x in 2003,
//            present in rrdtool 1.2.0, 2005-04-25)
//    * last-updated timestamp gained a `long` microsecond component
//    * otherwise identical to "0002"
//
//  - "0002" (never used by a stable release of rrdtool, but was used
//            by development versions of 1.1.x 2001-2003)
//    * added DST_CDEF
//    * added CF_HWPREDICT
//    * added CF_SEASONAL
//    * added CF_DEVPREDICT
//    * added CF_DEVSEASONAL
//    * added CF_FAILURES
//
//  - "0001" (the original in rrdtool 1.0.0, 1999-07-15)

const XMLNS = "https://oss.oetiker.ch/rrdtool/rrdtool-dump.xml"

type RRDValue = rrdbinary.Float

type Header struct {
	Cookie      rrdbinary.String     `rrdbinary:"size=4" xml:"-"`
	Version     rrdbinary.String     `rrdbinary:"size=5" xml:"version"`
	FloatCookie rrdbinary.Float      `xml:"-"`
	DSCnt       rrdbinary.Uint       `xml:"-"`
	RRACnt      rrdbinary.Uint       `xml:"-"`
	PDPStep     rrdbinary.Uint       `xml:"step"`
	Parameters  [10]rrdbinary.Unival `xml:"-"`
}

type DSDef struct {
	DSName     rrdbinary.String `rrdbinary:"size=20"`
	DSType     rrdbinary.String `rrdbinary:"size=20"`
	Parameters [10]rrdbinary.Unival
}

type RRADef struct {
	CFName rrdbinary.String `rrdbinary:"size=20"`
	RowCnt rrdbinary.Uint
	PDPCnt rrdbinary.Uint
}

type TimeWithUsec struct {
	Sec  rrdbinary.Time
	Usec rrdbinary.Int // signed, but always >= 0
}

type TimeWithoutUsec struct {
	Sec  rrdbinary.Time
	Usec rrdbinary.Int `rrdbinary:"-"`
}

type PDPPrep struct {
	LastDS  rrdbinary.String `rrdbinary:"size=30"`
	Scratch [10]rrdbinary.Unival
}

type CDPPrep struct {
	Scratch [10]rrdbinary.Unival
}

type RRAPtr struct {
	CurRow rrdbinary.Uint
}

type RRDv0005 = RRDv0004
type RRDv0004 = RRDv0003

type RRDv0003 struct {
	Header      Header
	DSDefs      []DSDef  // .Header.DSCnt
	RRADefs     []RRADef // .Header.RRACnt
	LastUpdated TimeWithUsec
	PDPPreps    []PDPPrep  // .Header.DSCnt
	CDPPreps    []CDPPrep  // .Header.DSCnt * .Header.RRACnt
	RRAPtrs     []RRAPtr   // .Header.RRACnt
	Values      []RRDValue // Σ .RRADefs[i].RowCnt*.Header.DSCnt
}

type RRDv0002 = RRDv0001

type RRDv0001 struct {
	Header      Header
	DSDefs      []DSDef  // .Header.DSCnt
	RRADefs     []RRADef // .Header.RRACnt
	LastUpdated TimeWithoutUsec
	PDPPreps    []PDPPrep  // .Header.DSCnt
	CDPPreps    []CDPPrep  // .Header.DSCnt * .Header.RRACnt
	RRAPtrs     []RRAPtr   // .Header.RRACnt
	Values      []RRDValue // Σ .RRADefs[i].RowCnt*.Header.DSCnt
}