Compare commits

..

8 Commits

Author SHA1 Message Date
deployer3000 d5f0f470d6 Merge pull request 'rc' (#7) from rc into master 2025-03-04 16:22:53 +03:00
YurijO 1bf6595bbc Merge branch 'master' into rc
test-org/prometheus-exporter/pipeline/pr-master Build started... Details
test-org/prometheus-exporter/pipeline/pr-rc This commit looks good Details
2025-03-04 16:20:42 +03:00
YurijO e22cb121eb Merge pull request 'feature/#1108' (#6) from feature/#1108 into rc
test-org/prometheus-exporter/pipeline/pr-master Build queued... Details
Reviewed-on: http://git.enode/deployer3000/prometheus-exporter/pulls/6
2025-03-03 17:45:05 +03:00
prplV deace7b776 version changed
test-org/prometheus-exporter/pipeline/pr-rc This commit looks good Details
2025-03-03 16:49:55 +03:00
prplV e5b8bfff99 registration metric with desc 2025-03-03 13:53:22 +03:00
prplV 12c98c199c fix String -> &str with clonning 2025-03-03 13:52:57 +03:00
prplV e7aeb78192 refactor + Cow usage 2025-03-03 13:50:08 +03:00
prplV 83f5dd472c borrowed strings without ownership (almost everywhere) 2025-03-03 13:49:48 +03:00
4 changed files with 14 additions and 15 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "exporter"
version = "0.1.0"
version = "0.2.3"
edition = "2021"
[dependencies]

View File

@ -7,23 +7,18 @@ use crate::structs::v3::PrometheusMetrics;
use prometheus::{ Encoder, Gauge, Registry, TextEncoder};
use std::sync::{ Arc, MutexGuard };
use crate::AppState;
use tracing::{ error, debug, info, warn };
use tracing::{ error, info, warn };
use crate::metrics::{MetricsProcesser, MetricsValueType};
pub async fn update_metrics(
State(state): State<Arc<AppState>>,
Json(request) : Json<PrometheusMetrics>
Json(request) : Json<PrometheusMetrics<'_>>
) -> impl IntoResponse {
info!("post on /update");
// let resp = Response::new("body");
// debug!("{:?}", request);
// debug!("{:?}", MetricsProcesser::get_type_of_value(&request));
let service = &request.service_name;
let endpoint = &request.endpoint_name;
for i in request.metrics {
// debug!("{:?}", &i);
// debug!("{:?}", MetricsProcesser::get_type_of_value(&i));
let metric_name = format!("{}_{}_{}", service, endpoint, &i.id);
match MetricsProcesser::get_type_of_value(&i) {
MetricsValueType::Array |
@ -33,7 +28,8 @@ pub async fn update_metrics(
MetricsValueType::Number => {
let gauge = MetricsProcesser::gauge_from_number(
&i,
&metric_name
&metric_name,
&i.desc.clone().unwrap_or_else(|| std::borrow::Cow::Borrowed(&i.id))
);
if let Some(gauge) = gauge {
match state.registry.lock() {
@ -50,7 +46,6 @@ pub async fn update_metrics(
},
}
}
// dbg!(gauge);
},
MetricsValueType::ArrayOfStrings => {
warn!("String arrays are unsupported, ignoring ...");

View File

@ -39,10 +39,11 @@ impl MetricsProcesser {
pub fn gauge_from_number(
metric: &MetricOutput,
metric_name: &str,
metric_desc: &str
) -> Option<Gauge> {
let gauge = Gauge::new(
metric_name,
&metric.id
metric_desc
);
match gauge {

View File

@ -1,25 +1,28 @@
// use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use serde_json::Value;
use std::borrow::Cow;
// use anyhow::Result;
// use std::sync::Arc;
pub mod v3 {
pub use super::*;
// to prometheus and nmns
#[derive(Serialize, Deserialize, Debug)]
pub struct MetricOutput {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MetricOutput<'a> {
pub id : String,
#[serde(rename = "type")]
json_type : String,
addr : String,
pub value : Value,
#[serde(rename = "description")]
pub desc : Option<Cow<'a, String>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct PrometheusMetrics {
pub struct PrometheusMetrics<'a> {
pub service_name: String,
pub endpoint_name: String,
pub metrics: Vec<MetricOutput>,
pub metrics: Vec<MetricOutput<'a>>,
}
}