The very basic metricator-client and package.

Package can be used in external things if needed.
This commit is contained in:
2020-12-24 23:06:13 +05:00
parent f1418a7a31
commit 614526b16d
10 changed files with 305 additions and 18 deletions

9
pkg/schema/apps_list.go Normal file
View File

@@ -0,0 +1,9 @@
package schema
// AppsList represents applications list structure from Metricator's API.
type AppsList []string
// IsEmpty returns true if returned applications list is empty.
func (a AppsList) IsEmpty() bool {
return len(a) == 0
}

41
pkg/schema/metric.go Normal file
View File

@@ -0,0 +1,41 @@
package schema
// Metric is a generic metric structure. Used in HTTP responses and data storage.
type Metric struct {
// BaseName is a metric's base name, used for constructing name.
BaseName string
// Name is a metric name.
Name string
// Description is a metric description from HELP line.
Description string
// Type is a metric type from TYPE line.
Type string
// Value is a metric value.
Value string
// Params is an additional params which are placed inside "{}".
Params []string
}
// NewMetric creates new structure for storing single metric data.
func NewMetric(name, mType, description string, params []string) Metric {
m := Metric{
BaseName: name,
Name: name,
Description: description,
Type: mType,
Params: params,
Value: "",
}
return m
}
// GetValue returns metric's value.
func (m *Metric) GetValue() string {
return m.Value
}
// SetValue sets value for metric.
func (m *Metric) SetValue(value string) {
m.Value = value
}

9
pkg/schema/metrics.go Normal file
View File

@@ -0,0 +1,9 @@
package schema
// Metrics is a metrics collection response.
type Metrics []*Metric
// IsEmpty returns true if returned applications list is empty.
func (m Metrics) IsEmpty() bool {
return len(m) == 0
}