metrics: add METRIC_FAMILY_TYPE_OBJECT type
We will need a way to send journal entries as metrics. Those are already json objects. So Lennart suggested to introduce a new type METRIC_FAMILY_TYPE_OBJECT that does this. This commit implements his suggestion.
This commit is contained in:
@@ -58,6 +58,7 @@ static const char * const metric_family_type_table[_METRIC_FAMILY_TYPE_MAX] = {
|
||||
[METRIC_FAMILY_TYPE_COUNTER] = "counter",
|
||||
[METRIC_FAMILY_TYPE_GAUGE] = "gauge",
|
||||
[METRIC_FAMILY_TYPE_STRING] = "string",
|
||||
[METRIC_FAMILY_TYPE_OBJECT] = "object",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_TO_STRING(metric_family_type, MetricFamilyType);
|
||||
@@ -229,3 +230,18 @@ int metric_build_send_double(
|
||||
|
||||
return metric_build_send(mf, link, object, v, fields);
|
||||
}
|
||||
|
||||
int metric_build_send_object(
|
||||
const MetricFamily *mf,
|
||||
sd_varlink *link,
|
||||
const char *object,
|
||||
sd_json_variant *value,
|
||||
sd_json_variant *fields) {
|
||||
|
||||
assert(mf);
|
||||
assert(link);
|
||||
assert(value);
|
||||
assert(sd_json_variant_is_object(value));
|
||||
|
||||
return metric_build_send(mf, link, object, value, fields);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ typedef enum MetricFamilyType {
|
||||
METRIC_FAMILY_TYPE_COUNTER,
|
||||
METRIC_FAMILY_TYPE_GAUGE,
|
||||
METRIC_FAMILY_TYPE_STRING,
|
||||
METRIC_FAMILY_TYPE_OBJECT,
|
||||
_METRIC_FAMILY_TYPE_MAX,
|
||||
_METRIC_FAMILY_TYPE_INVALID = -EINVAL,
|
||||
} MetricFamilyType;
|
||||
@@ -39,3 +40,4 @@ int metrics_method_list(const MetricFamily mfs[], sd_varlink *link, sd_json_vari
|
||||
int metric_build_send_string(const MetricFamily* mf, sd_varlink *link, const char *object, const char *value, sd_json_variant *fields);
|
||||
int metric_build_send_unsigned(const MetricFamily* mf, sd_varlink *link, const char *object, uint64_t value, sd_json_variant *fields);
|
||||
int metric_build_send_double(const MetricFamily* mf, sd_varlink *link, const char *object, double value, sd_json_variant *fields);
|
||||
int metric_build_send_object(const MetricFamily* mf, sd_varlink *link, const char *object, sd_json_variant *value, sd_json_variant *fields);
|
||||
|
||||
@@ -9,7 +9,9 @@ static SD_VARLINK_DEFINE_ENUM_TYPE(
|
||||
SD_VARLINK_FIELD_COMMENT("A gauge metric family type which is a value that can go up and down"),
|
||||
SD_VARLINK_DEFINE_ENUM_VALUE(gauge),
|
||||
SD_VARLINK_FIELD_COMMENT("A string metric family type"),
|
||||
SD_VARLINK_DEFINE_ENUM_VALUE(string));
|
||||
SD_VARLINK_DEFINE_ENUM_VALUE(string),
|
||||
SD_VARLINK_FIELD_COMMENT("An object metric family type whose value is an arbitrary JSON object"),
|
||||
SD_VARLINK_DEFINE_ENUM_VALUE(object));
|
||||
|
||||
static SD_VARLINK_DEFINE_ERROR(NoSuchMetric);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user