summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/rrd.php
blob: 2da227d0e235ed42e108f04aba57df3a0b9fd6a1 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php

namespace Safe;

use Safe\Exceptions\RrdException;

/**
 * Creates the rdd database file.
 *
 * @param string $filename Filename for newly created rrd file.
 * @param array $options Options for rrd create - list of strings. See man page of rrd create
 * for whole list of options.
 * @throws RrdException
 *
 */
function rrd_create(string $filename, array $options): void
{
    error_clear_last();
    $result = \rrd_create($filename, $options);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
}


/**
 * Returns the first data sample from the specified RRA of the RRD file.
 *
 * @param string $file RRD database file name.
 * @param int $raaindex The index number of the RRA that is to be examined. Default value is 0.
 * @return int Integer number of unix timestamp.
 * @throws RrdException
 *
 */
function rrd_first(string $file, int $raaindex = 0): int
{
    error_clear_last();
    $result = \rrd_first($file, $raaindex);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
    return $result;
}


/**
 * Creates image for a particular data from RRD file.
 *
 * @param string $filename The filename to output the graph to. This will generally end in either
 * .png, .svg or
 * .eps, depending on the format you want to output.
 * @param array $options Options for generating image. See man page of rrd graph for all
 * possible options. All options (data definitions, variable definitions, etc.)
 * are allowed.
 * @return array Array with information about generated image is returned.
 * @throws RrdException
 *
 */
function rrd_graph(string $filename, array $options): array
{
    error_clear_last();
    $result = \rrd_graph($filename, $options);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
    return $result;
}


/**
 * Returns information about particular RRD database file.
 *
 * @param string $filename RRD database file name.
 * @return array Array with information about requested RRD file.
 * @throws RrdException
 *
 */
function rrd_info(string $filename): array
{
    error_clear_last();
    $result = \rrd_info($filename);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
    return $result;
}


/**
 * Gets array of the UNIX timestamp and the values stored for each date in the
 * most recent update of the RRD database file.
 *
 * @param string $filename RRD database file name.
 * @return array Array of information about last update.
 * @throws RrdException
 *
 */
function rrd_lastupdate(string $filename): array
{
    error_clear_last();
    $result = \rrd_lastupdate($filename);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
    return $result;
}


/**
 * Restores the RRD file from the XML dump.
 *
 * @param string $xml_file XML filename with the dump of the original RRD database file.
 * @param string $rrd_file Restored RRD database file name.
 * @param array $options Array of options for restoring. See man page for rrd restore.
 * @throws RrdException
 *
 */
function rrd_restore(string $xml_file, string $rrd_file, array $options = null): void
{
    error_clear_last();
    if ($options !== null) {
        $result = \rrd_restore($xml_file, $rrd_file, $options);
    } else {
        $result = \rrd_restore($xml_file, $rrd_file);
    }
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
}


/**
 * Change some options in the RRD dabase header file. E.g. renames the source for
 * the data etc.
 *
 * @param string $filename RRD database file name.
 * @param array $options Options with RRD database file properties which will be changed. See
 * rrd tune man page for details.
 * @throws RrdException
 *
 */
function rrd_tune(string $filename, array $options): void
{
    error_clear_last();
    $result = \rrd_tune($filename, $options);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
}


/**
 * Updates the RRD database file. The input data is time interpolated according to the
 * properties of the RRD database file.
 *
 * @param string $filename RRD database file name. This database will be updated.
 * @param array $options Options for updating the RRD database. This is list of strings. See man page of rrd update
 * for whole list of options.
 * @throws RrdException
 *
 */
function rrd_update(string $filename, array $options): void
{
    error_clear_last();
    $result = \rrd_update($filename, $options);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
}


/**
 * Exports the information about RRD database file. This data can be converted
 * to XML file via user space PHP script and then restored back as RRD database
 * file.
 *
 * @param array $options Array of options for the export, see rrd xport man page.
 * @return array Array with information about RRD database file.
 * @throws RrdException
 *
 */
function rrd_xport(array $options): array
{
    error_clear_last();
    $result = \rrd_xport($options);
    if ($result === false) {
        throw RrdException::createFromPhpError();
    }
    return $result;
}