Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12 from runabove/parser
Browse files Browse the repository at this point in the history
Parser
  • Loading branch information
d33d33 committed Jan 5, 2017
2 parents d981ff7 + fdfd1af commit 1b11622
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "beamium"
version = "1.0.2"
version = "1.0.3"
authors = [ "d33d33 <kevin.georges@corp.ovh.com>" ]

build = "build.rs"
Expand Down
6 changes: 5 additions & 1 deletion src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ fn send(sink: &config::Sink, parameters: &config::Parameters) -> Result<(), Box<

debug!("post metrics");
let request = client.post(&sink.url).headers(headers).body(&metrics);
let res = try!(request.send());
let mut res = try!(request.send());
if !res.status.is_success() {
let mut body = String::new();
try!(res.read_to_string(&mut body));
debug!("data {}", &body);

return Err(From::from("non 200 received"));
}

Expand Down
12 changes: 9 additions & 3 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,22 @@ fn fetch(source: &config::Source,
Ok(())
}

/// Format Wqrp10 metrics from Prometheus one.
/// Format Warp10 metrics from Prometheus one.
fn format(line: &str, labels: &String, now: i64) -> Result<String, Box<Error>> {
// Skip comments
if line.starts_with("#") {
return Ok(String::new());
}

// Extract Prometheus metric
let mut tokens = line.split_whitespace();
let class = try!(tokens.next().ok_or("no class"));
let index = if line.contains("{") {
try!(line.rfind('}').ok_or("bad class"))
} else {
try!(line.find(' ').ok_or("bad class"))
};
let (class, v) = line.split_at(index + 1);
let mut tokens = v.split_whitespace();

let value = try!(tokens.next().ok_or("no value"));
let timestamp = tokens.next()
.map(|v| {
Expand Down

0 comments on commit 1b11622

Please sign in to comment.