fn send_metric(&mut self, metric: &Metric) {
        let mut event = Event::new();

        let mut attributes: Vec<Attribute> = vec![];
        for (key, value) in &metric.attributes {
            let mut attribute = Attribute::new();
            attribute.set_key(key.clone());
            attribute.set_value(value.clone());
            attributes.push(attribute);
        }

        event.set_time(
            SystemTime::now()
                .duration_since(UNIX_EPOCH)
                .unwrap()
                .as_secs() as i64,
        );
        event.set_ttl(metric.ttl);
        event.set_host(metric.hostname.to_string());
        event.set_service(metric.name.to_string());
        event.set_state(metric.state.to_string());
        event.set_tags(protobuf::RepeatedField::from_vec(metric.tags.clone()));
        if !attributes.is_empty() {
            event.set_attributes(protobuf::RepeatedField::from_vec(attributes));
        }
        event.set_description(metric.description.to_string());

        match metric.metric_value {
            // MetricValueType::IntSigned(value) => event.set_metric_sint64(value),
            // MetricValueType::Float(value) => event.set_metric_f(value),
            MetricValueType::FloatDouble(value) => event.set_metric_d(value),
            MetricValueType::IntUnsigned(value) => event.set_metric_sint64(
                i64::try_from(value).expect("Metric cannot be converted to signed integer."),
            ),
            MetricValueType::Text(ref value) => {
                let value = value.replace(",", ".").replace("\n", "");
                if value.contains('.') {
                    event.set_metric_d(value.parse::<f64>().expect("Cannot parse metric value."));
                } else {
                    event.set_metric_sint64(
                        value.parse::<i64>().expect("Cannot parse metric value."),
                    );
                }
            }
        }

        self.client
            .event(event)
            .expect("Fail to send metric to Riemann");
    }
/// Send metrics to the server.
Send metrics to the server.
Send metrics to the server .
fn send_metric(&mut self, metric: &Metric) {
        let mut event = Event::new();
        let mut attributes: Vec<Attribute> = vec![];
        for (key, value) in &metric.attributes {
            let mut attribute = Attribute::new();
            attribute.set_key(key.clone());
            attribute.set_value(value.clone());
            attributes.push(attribute);
        }
        event.set_time(
            SystemTime::now()
                .duration_since(UNIX_EPOCH)
                .unwrap()
                .as_secs() as i64,
        );
        event.set_ttl(metric.ttl);
        event.set_host(metric.hostname.to_string());
        event.set_service(metric.name.to_string());
        event.set_state(metric.state.to_string());
        event.set_tags(protobuf::RepeatedField::from_vec(metric.tags.clone()));
        if !attributes.is_empty() {
            event.set_attributes(protobuf::RepeatedField::from_vec(attributes));
        }
        event.set_description(metric.description.to_string());
        match metric.metric_value {
            // MetricValueType::IntSigned(value) => event.set_metric_sint64(value),
            // MetricValueType::Float(value) => event.set_metric_f(value),
            MetricValueType::FloatDouble(value) => event.set_metric_d(value),
            MetricValueType::IntUnsigned(value) => event.set_metric_sint64(
                i64::try_from(value).expect("Metric cannot be converted to signed integer."),
            ),
            MetricValueType::Text(ref value) => {
                let value = value.replace(",", ".").replace("\n", "");
                if value.contains('.') {
                    event.set_metric_d(value.parse::<f64>().expect("Cannot parse metric value."));
                } else {
                    event.set_metric_sint64(
                        value.parse::<i64>().expect("Cannot parse metric value."),
                    );
                }
            }
        }
        self.client
            .event(event)
            .expect("Fail to send metric to Riemann");
    }
fn send_metric ( & mut self , metric : & Metric ) { let mut event = Event :: new ( ) ; let mut attributes : Vec < Attribute > = vec ! [ ] ; for ( key , value ) in & metric . attributes { let mut attribute = Attribute :: new ( ) ; attribute . set_key ( key . clone ( ) ) ; attribute . set_value ( value . clone ( ) ) ; attributes . push ( attribute ) ; } event . set_time ( SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) as i64 , ) ; event . set_ttl ( metric . ttl ) ; event . set_host ( metric . hostname . to_string ( ) ) ; event . set_service ( metric . name . to_string ( ) ) ; event . set_state ( metric . state . to_string ( ) ) ; event . set_tags ( protobuf :: RepeatedField :: from_vec ( metric . tags . clone ( ) ) ) ; if ! attributes . is_empty ( ) { event . set_attributes ( protobuf :: RepeatedField :: from_vec ( attributes ) ) ; } event . set_description ( metric . description . to_string ( ) ) ; match metric . metric_value { // MetricValueType::IntSigned(value) => event.set_metric_sint64(value), // MetricValueType::Float(value) => event.set_metric_f(value), MetricValueType :: FloatDouble ( value ) => event . set_metric_d ( value ) , MetricValueType :: IntUnsigned ( value ) => event . set_metric_sint64 ( i64 :: try_from ( value ) . expect ( " " ) , ) , MetricValueType :: Text ( ref value ) => { let value = value . replace ( " " , " " ) . replace ( " \n " , " " ) ; if value . contains ( '.' ) { event . set_metric_d ( value . parse :: < f64 > ( ) . expect ( " " ) ) ; } else { event . set_metric_sint64 ( value . parse :: < i64 > ( ) . expect ( " " ) , ) ; } } } self . client . event ( event ) . expect ( " " ) ; }
Send metrics to the server.
Send metrics to the server .
&mut self
metric
&Metric
&mut self
metric
&Metric