2019-07-19 14:46:16 -04:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use rocket_prometheus::prometheus;
|
|
|
|
|
2019-09-02 16:49:02 -04:00
|
|
|
use crate::anonymize_utils;
|
2019-07-19 14:46:16 -04:00
|
|
|
|
2019-09-02 16:49:02 -04:00
|
|
|
use crate::database::types::Email;
|
2019-07-19 14:46:16 -04:00
|
|
|
|
|
|
|
lazy_static! {
|
2019-07-20 11:00:02 -04:00
|
|
|
static ref KEY_UPLOAD: LabelCounter =
|
2019-07-20 13:44:18 -04:00
|
|
|
LabelCounter::new("hagrid_key_upload", "Uploaded keys", &["result"]);
|
2019-07-20 11:00:02 -04:00
|
|
|
|
|
|
|
static ref MAIL_SENT: LabelCounter =
|
2019-07-20 13:44:18 -04:00
|
|
|
LabelCounter::new("hagrid_mail_sent", "Sent verification mails", &["type", "domain"]);
|
2019-07-20 11:00:02 -04:00
|
|
|
|
|
|
|
static ref KEY_ADDRESS_PUBLISHED: LabelCounter =
|
2019-07-20 13:44:18 -04:00
|
|
|
LabelCounter::new("hagrid_key_address_published", "Verified email addresses", &["domain"]);
|
2019-07-20 11:00:02 -04:00
|
|
|
static ref KEY_ADDRESS_UNPUBLISHED: LabelCounter =
|
2019-07-20 13:44:18 -04:00
|
|
|
LabelCounter::new("hagrid_key_address_unpublished", "Unpublished email addresses", &["domain"]);
|
2019-07-19 14:46:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn register_counters(registry: &prometheus::Registry) {
|
2019-07-20 11:00:02 -04:00
|
|
|
KEY_UPLOAD.register(registry);
|
|
|
|
|
|
|
|
MAIL_SENT.register(registry);
|
|
|
|
|
2019-07-19 14:46:16 -04:00
|
|
|
KEY_ADDRESS_PUBLISHED.register(registry);
|
|
|
|
KEY_ADDRESS_UNPUBLISHED.register(registry);
|
|
|
|
}
|
|
|
|
|
2019-07-20 11:00:02 -04:00
|
|
|
pub fn inc_key_upload(upload_result: &str) {
|
|
|
|
KEY_UPLOAD.inc(&[upload_result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inc_mail_sent(mail_type: &str, email: &Email) {
|
|
|
|
let anonymized_adddress = anonymize_utils::anonymize_address_fallback(email);
|
|
|
|
MAIL_SENT.inc(&[mail_type, &anonymized_adddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inc_address_published(email: &Email) {
|
|
|
|
let anonymized_adddress = anonymize_utils::anonymize_address_fallback(email);
|
|
|
|
KEY_ADDRESS_PUBLISHED.inc(&[&anonymized_adddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inc_address_unpublished(email: &Email) {
|
|
|
|
let anonymized_adddress = anonymize_utils::anonymize_address_fallback(email);
|
|
|
|
KEY_ADDRESS_UNPUBLISHED.inc(&[&anonymized_adddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LabelCounter {
|
2019-07-19 14:46:16 -04:00
|
|
|
prometheus_counter: prometheus::IntCounterVec,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LabelCounter {
|
|
|
|
fn new(name: &str, help: &str, labels: &[&str]) -> Self {
|
|
|
|
let opts = prometheus::Opts::new(name, help);
|
|
|
|
let prometheus_counter = prometheus::IntCounterVec::new(opts, labels).unwrap();
|
|
|
|
Self { prometheus_counter }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn register(&self, registry: &prometheus::Registry) {
|
|
|
|
registry.register(Box::new(self.prometheus_counter.clone())).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn inc(&self, values: &[&str]) {
|
|
|
|
self.prometheus_counter.with_label_values(values).inc();
|
|
|
|
}
|
|
|
|
}
|