Browse Source

mv grafana to datasources

main
Alexey Velikiy 3 years ago
parent
commit
8fc2f55ac4
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 2
      README.md
  4. 1
      src/datasources.rs
  5. 11
      src/datasources/grafana.rs
  6. 6
      src/datasources/grafana/prometheus.rs
  7. 2
      src/lib.rs
  8. 4
      src/main.rs

2
Cargo.lock generated

@ -690,7 +690,7 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "subbeat"
version = "0.0.2"
version = "0.0.3"
dependencies = [
"anyhow",
"async-trait",

2
Cargo.toml

@ -1,6 +1,6 @@
[package]
name = "subbeat"
version = "0.0.2"
version = "0.0.3"
edition = "2018"
license = "MIT OR Apache-2.0"

2
README.md

@ -4,7 +4,7 @@ subbeat
## Example
```
subbeat grafana http://localhost:3000 eyJrIjoiWnRRMTNmcGpvTHNPb3UzNzdUNUphRm53Rk9tMTNzOTQiLCJuIjoic3ViYmVhdC10ZXN0IiwiaWQiOjF9 "/api/datasources/proxy/1/api/v1/query_range" "rate(go_memstats_alloc_bytes_total[5m])" 1634672070 1634672970 15
subbeat grafana http://localhost:3000 eyJrIjoiWnRRMTNmcGpvTHNPb3UzNzdUNUphRm53Rk9tMTNzOTQiLCJuIjoic3ViYmVhdC10ZXN0IiwiaWQiOjF9 "/api/datasources/proxy/1/api/v1/query_range" "rate(go_memstats_alloc_bytes_total[5m])" 1634672070 1635110190 15
```

1
src/datasources.rs

@ -0,0 +1 @@
pub mod grafana;

11
src/grafana_service.rs → src/datasources/grafana.rs

@ -1,3 +1,4 @@
use crate::metric::Metric;
use crate::{metric::MetricResult, types};
use hyper::{Body, Client, Method, Request, StatusCode};
@ -8,16 +9,16 @@ mod prometheus;
use serde_json;
use crate::metric::Metric;
pub struct GrafanaService {
pub struct Grafana {
url: String,
api_key: String,
}
impl GrafanaService {
pub fn new(url: String, api_key: String) -> GrafanaService {
GrafanaService { api_key, url }
impl Grafana {
pub fn new(url: String, api_key: String) -> Grafana {
Grafana { api_key, url }
}
pub async fn test_connection(&self) -> types::Result<()> {

6
src/grafana_service/prometheus.rs → src/datasources/grafana/prometheus.rs

@ -11,12 +11,12 @@ use serde_derive::{Deserialize, Serialize};
use serde_qs as qs;
use super::GrafanaService;
use super::Grafana;
pub struct Prometheus<'a> {
url: String,
query: String,
grafana_service: &'a GrafanaService,
grafana_service: &'a Grafana,
}
#[derive(Deserialize, Serialize)]
@ -28,7 +28,7 @@ struct Query {
}
impl<'a> Prometheus<'a> {
pub fn new(grafana_service: &'a GrafanaService, url: &str, query: &str) -> Prometheus<'a> {
pub fn new(grafana_service: &'a Grafana, url: &str, query: &str) -> Prometheus<'a> {
Prometheus {
url: url.to_owned(),
grafana_service,

2
src/lib.rs

@ -1,3 +1,3 @@
pub mod grafana_service;
pub mod datasources;
pub mod metric;
pub mod types;

4
src/main.rs

@ -1,4 +1,4 @@
use subbeat::grafana_service;
use subbeat::datasources::grafana;
mod cli;
mod types;
@ -7,7 +7,7 @@ mod types;
async fn main() -> types::Result<()> {
let cli = cli::CLI::new();
let gs = grafana_service::GrafanaService::new(cli.url.to_string(), cli.key.to_string());
let gs = grafana::Grafana::new(cli.url.to_string(), cli.key.to_string());
// gs.test_connection().await?;
// gs.get_datasources().await?;

Loading…
Cancel
Save