fn run(&mut self, parameters: ArgMatches) {
        let dispatch_duration: u64 = parameters
            .value_of("dispatch_duration")
            .unwrap()
            .parse()
            .expect("Wrong dispatch_duration value, should be a number of seconds");

        let hostname = get_hostname();

        let mut rclient = RiemannClient::new(&parameters);

        info!(
            "{}: Starting Riemann exporter",
            Utc::now().format("%Y-%m-%dT%H:%M:%S")
        );
        println!("Press CTRL-C to stop scaphandre");
        println!("Measurement step is: {}s", dispatch_duration);

        let topology = self.sensor.get_topology().unwrap();
        let mut metric_generator = MetricGenerator::new(
            topology,
            hostname,
            parameters.is_present("qemu"),
            parameters.is_present("containers"),
        );

        loop {
            info!(
                "{}: Beginning of measure loop",
                Utc::now().format("%Y-%m-%dT%H:%M:%S")
            );

            metric_generator
                .topology
                .proc_tracker
                .clean_terminated_process_records_vectors();

            info!(
                "{}: Refresh topology",
                Utc::now().format("%Y-%m-%dT%H:%M:%S")
            );
            metric_generator.topology.refresh();

            info!("{}: Refresh data", Utc::now().format("%Y-%m-%dT%H:%M:%S"));
            // Here we need a specific behavior for process metrics, so we call each gen function
            // and then implement that specific behavior (we don't use gen_all_metrics).
            metric_generator.gen_self_metrics();
            metric_generator.gen_host_metrics();
            metric_generator.gen_socket_metrics();

            let mut data = vec![];
            let processes_tracker = &metric_generator.topology.proc_tracker;

            for pid in processes_tracker.get_alive_pids() {
                let exe = processes_tracker.get_process_name(pid);
                let cmdline = processes_tracker.get_process_cmdline(pid);

                let mut attributes = HashMap::new();
                attributes.insert("pid".to_string(), pid.to_string());

                attributes.insert("exe".to_string(), exe.clone());

                if let Some(cmdline_str) = cmdline {
                    attributes.insert("cmdline".to_string(), cmdline_str.replace("\"", "\\\""));

                    if parameters.is_present("qemu") {
                        if let Some(vmname) = utils::filter_qemu_cmdline(&cmdline_str) {
                            attributes.insert("vmname".to_string(), vmname);
                        }
                    }
                }

                // Here we define a metric name with pid + exe string suffix as riemann needs
                // to differentiate services/metrics
                let metric_name = format!(
                    "{}_{}_{}",
                    "scaph_process_power_consumption_microwatts",
                    pid.to_string(),
                    exe
                );
                if let Some(power) = metric_generator
                    .topology
                    .get_process_power_consumption_microwatts(pid)
                {
                    data.push(Metric {
                        name: metric_name,
                        metric_type: String::from("gauge"),
                        ttl: 60.0,
                        hostname: get_hostname(),
                        timestamp: power.timestamp,
                        state: String::from("ok"),
                        tags: vec!["scaphandre".to_string()],
                        attributes,
                        description: String::from("Power consumption due to the process, measured on at the topology level, in microwatts"),
                        metric_value: MetricValueType::Text(power.value),
                    });
                }
            }
            // Send all data
            info!("{}: Send data", Utc::now().format("%Y-%m-%dT%H:%M:%S"));
            for metric in metric_generator.pop_metrics() {
                rclient.send_metric(&metric);
            }
            for metric in data {
                rclient.send_metric(&metric);
            }

            thread::sleep(Duration::new(dispatch_duration, 0));
        }
    }
/// Entry point of the RiemannExporter.
Entry point of the RiemannExporter.
Entry point of the RiemannExporter .
fn run(&mut self, parameters: ArgMatches) {
        let dispatch_duration: u64 = parameters
            .value_of("dispatch_duration")
            .unwrap()
            .parse()
            .expect("Wrong dispatch_duration value, should be a number of seconds");
        let hostname = get_hostname();
        let mut rclient = RiemannClient::new(&parameters);
        info!(
            "{}: Starting Riemann exporter",
            Utc::now().format("%Y-%m-%dT%H:%M:%S")
        );
        println!("Press CTRL-C to stop scaphandre");
        println!("Measurement step is: {}s", dispatch_duration);
        let topology = self.sensor.get_topology().unwrap();
        let mut metric_generator = MetricGenerator::new(
            topology,
            hostname,
            parameters.is_present("qemu"),
            parameters.is_present("containers"),
        );
        loop {
            info!(
                "{}: Beginning of measure loop",
                Utc::now().format("%Y-%m-%dT%H:%M:%S")
            );
            metric_generator
                .topology
                .proc_tracker
                .clean_terminated_process_records_vectors();
            info!(
                "{}: Refresh topology",
                Utc::now().format("%Y-%m-%dT%H:%M:%S")
            );
            metric_generator.topology.refresh();
            info!("{}: Refresh data", Utc::now().format("%Y-%m-%dT%H:%M:%S"));
            // Here we need a specific behavior for process metrics, so we call each gen function
            // and then implement that specific behavior (we don't use gen_all_metrics).
            metric_generator.gen_self_metrics();
            metric_generator.gen_host_metrics();
            metric_generator.gen_socket_metrics();
            let mut data = vec![];
            let processes_tracker = &metric_generator.topology.proc_tracker;
            for pid in processes_tracker.get_alive_pids() {
                let exe = processes_tracker.get_process_name(pid);
                let cmdline = processes_tracker.get_process_cmdline(pid);
                let mut attributes = HashMap::new();
                attributes.insert("pid".to_string(), pid.to_string());
                attributes.insert("exe".to_string(), exe.clone());
                if let Some(cmdline_str) = cmdline {
                    attributes.insert("cmdline".to_string(), cmdline_str.replace("\"", "\\\""));
                    if parameters.is_present("qemu") {
                        if let Some(vmname) = utils::filter_qemu_cmdline(&cmdline_str) {
                            attributes.insert("vmname".to_string(), vmname);
                        }
                    }
                }
                // Here we define a metric name with pid + exe string suffix as riemann needs
                // to differentiate services/metrics
                let metric_name = format!(
                    "{}_{}_{}",
                    "scaph_process_power_consumption_microwatts",
                    pid.to_string(),
                    exe
                );
                if let Some(power) = metric_generator
                    .topology
                    .get_process_power_consumption_microwatts(pid)
                {
                    data.push(Metric {
                        name: metric_name,
                        metric_type: String::from("gauge"),
                        ttl: 60.0,
                        hostname: get_hostname(),
                        timestamp: power.timestamp,
                        state: String::from("ok"),
                        tags: vec!["scaphandre".to_string()],
                        attributes,
                        description: String::from("Power consumption due to the process, measured on at the topology level, in microwatts"),
                        metric_value: MetricValueType::Text(power.value),
                    });
                }
            }
            // Send all data
            info!("{}: Send data", Utc::now().format("%Y-%m-%dT%H:%M:%S"));
            for metric in metric_generator.pop_metrics() {
                rclient.send_metric(&metric);
            }
            for metric in data {
                rclient.send_metric(&metric);
            }
            thread::sleep(Duration::new(dispatch_duration, 0));
        }
    }
fn run ( & mut self , parameters : ArgMatches ) { let dispatch_duration : u64 = parameters . value_of ( " " ) . unwrap ( ) . parse ( ) . expect ( " " ) ; let hostname = get_hostname ( ) ; let mut rclient = RiemannClient :: new ( & parameters ) ; info ! ( " " Utc now ( ) format ( " " ) ) ; println ! ( " " ) ; println ! ( " " dispatch_duration ) ; let topology = self . sensor . get_topology ( ) . unwrap ( ) ; let mut metric_generator = MetricGenerator :: new ( topology , hostname , parameters . is_present ( " " ) , parameters . is_present ( " " ) , ) ; loop { info ! ( " " Utc now ( ) format ( " " ) ) ; metric_generator . topology . proc_tracker . clean_terminated_process_records_vectors ( ) ; info ! ( " " Utc now ( ) format ( " " ) ) ; metric_generator . topology . refresh ( ) ; info ! ( " " Utc now ( ) format ( " " ) ) ; // Here we need a specific behavior for process metrics, so we call each gen function // and then implement that specific behavior (we don't use gen_all_metrics). metric_generator . gen_self_metrics ( ) ; metric_generator . gen_host_metrics ( ) ; metric_generator . gen_socket_metrics ( ) ; let mut data = vec ! [ ] ; let processes_tracker = & metric_generator . topology . proc_tracker ; for pid in processes_tracker . get_alive_pids ( ) { let exe = processes_tracker . get_process_name ( pid ) ; let cmdline = processes_tracker . get_process_cmdline ( pid ) ; let mut attributes = HashMap :: new ( ) ; attributes . insert ( " " . to_string ( ) , pid . to_string ( ) ) ; attributes . insert ( " " . to_string ( ) , exe . clone ( ) ) ; if let Some ( cmdline_str ) = cmdline { attributes . insert ( " " . to_string ( ) , cmdline_str . replace ( " \" " , " \\ \" " ) ) ; if parameters . is_present ( " " ) { if let Some ( vmname ) = utils :: filter_qemu_cmdline ( & cmdline_str ) { attributes . insert ( " " . to_string ( ) , vmname ) ; } } } // Here we define a metric name with pid + exe string suffix as riemann needs // to differentiate services/metrics let metric_name = format ! ( " " " " pid to_string ( ) exe ) ; if let Some ( power ) = metric_generator . topology . get_process_power_consumption_microwatts ( pid ) { data . push ( Metric { name : metric_name , metric_type : String :: from ( " " ) , ttl : 60.0 , hostname : get_hostname ( ) , timestamp : power . timestamp , state : String :: from ( " " ) , tags : vec ! [ " " to_string ( ) ] , attributes , description : String :: from ( " " ) , metric_value : MetricValueType :: Text ( power . value ) , } ) ; } } // Send all data info ! ( " " Utc now ( ) format ( " " ) ) ; for metric in metric_generator . pop_metrics ( ) { rclient . send_metric ( & metric ) ; } for metric in data { rclient . send_metric ( & metric ) ; } thread :: sleep ( Duration :: new ( dispatch_duration , 0 ) ) ; } }
Entry point of the RiemannExporter.
Entry point of the RiemannExporter .
&mut self
parameters
ArgMatches
&mut self
parameters
ArgMatches