From 4334f94fb995762a53b342411a29bbc626df572c Mon Sep 17 00:00:00 2001 From: Nelson J Morais Date: Mon, 21 Dec 2020 17:27:19 +0000 Subject: [PATCH 1/8] added github actions runner collector --- src/collectors/github_runners.rs | 180 +++++++++++++++++++++++++++++++ src/collectors/mod.rs | 9 ++ src/config.rs | 11 ++ src/http.rs | 37 +++++++ src/lib.rs | 4 +- 5 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/collectors/github_runners.rs create mode 100644 src/http.rs diff --git a/src/collectors/github_runners.rs b/src/collectors/github_runners.rs new file mode 100644 index 0000000..a2cf842 --- /dev/null +++ b/src/collectors/github_runners.rs @@ -0,0 +1,180 @@ +use crate::{http, http::is_token_flagged, Config}; +use anyhow::Error; +use log::{debug, error, warn}; +use prometheus::core::Desc; +use prometheus::proto::MetricFamily; +use prometheus::{core::Collector, IntGauge, Opts}; +use std::collections::HashMap; +use std::sync::{Arc, RwLock}; +use tokio::time::Duration; + +const GH_RUNNERS_ENDPOINT: &str = "https://api.github.com/repos/{owner_repo}/actions/runners"; + +#[derive(Debug, serde::Deserialize)] +struct ApiResponse { + total_count: usize, + runners: Vec, +} + +#[derive(Debug, serde::Deserialize)] +struct Runner { + id: usize, + name: String, + os: String, + status: String, + busy: bool, + labels: Vec