Skip to main content

nominal_api/conjure/objects/storage/writer/api/
telegraf_metric.rs

1#[derive(
2    Debug,
3    Clone,
4    conjure_object::serde::Serialize,
5    conjure_object::serde::Deserialize,
6    PartialEq,
7    Eq,
8    PartialOrd,
9    Ord,
10    Hash
11)]
12#[serde(crate = "conjure_object::serde")]
13#[conjure_object::private::staged_builder::staged_builder]
14#[builder(crate = conjure_object::private::staged_builder, update, inline)]
15pub struct TelegrafMetric {
16    #[builder(
17        default,
18        map(
19            key(type = super::Field),
20            value(
21                custom(
22                    type = impl
23                    conjure_object::serde::Serialize,
24                    convert = |v|conjure_object::Any::new(
25                        v
26                    ).expect("value failed to serialize")
27                )
28            )
29        )
30    )]
31    #[serde(
32        rename = "fields",
33        skip_serializing_if = "std::collections::BTreeMap::is_empty",
34        default
35    )]
36    fields: std::collections::BTreeMap<super::Field, conjure_object::Any>,
37    #[serde(rename = "name")]
38    name: super::MeasurementName,
39    #[builder(default, map(key(type = String, into), value(type = String, into)))]
40    #[serde(
41        rename = "tags",
42        skip_serializing_if = "std::collections::BTreeMap::is_empty",
43        default
44    )]
45    tags: std::collections::BTreeMap<String, String>,
46    #[builder(
47        custom(
48            type = impl
49            conjure_object::serde::Serialize,
50            convert = |v|conjure_object::Any::new(v).expect("value failed to serialize")
51        )
52    )]
53    #[serde(rename = "timestamp")]
54    timestamp: conjure_object::Any,
55}
56impl TelegrafMetric {
57    /// Constructs a new instance of the type.
58    #[inline]
59    pub fn new(
60        name: super::MeasurementName,
61        timestamp: impl conjure_object::serde::Serialize,
62    ) -> Self {
63        Self::builder().name(name).timestamp(timestamp).build()
64    }
65    /// The values are expected to be either numeric or string values
66    #[inline]
67    pub fn fields(
68        &self,
69    ) -> &std::collections::BTreeMap<super::Field, conjure_object::Any> {
70        &self.fields
71    }
72    /// The measurement name. Measurement name and field are concatenated when creating the Nominal channel name.
73    #[inline]
74    pub fn name(&self) -> &super::MeasurementName {
75        &self.name
76    }
77    #[inline]
78    pub fn tags(&self) -> &std::collections::BTreeMap<String, String> {
79        &self.tags
80    }
81    #[inline]
82    pub fn timestamp(&self) -> &conjure_object::Any {
83        &self.timestamp
84    }
85}