mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-13 13:07:40 +02:00
Show server info (version and uptime) on API. (#201)
This commit is contained in:
@@ -11,6 +11,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use rpki::cert::Cert;
|
||||
use rpki::crypto::Signer;
|
||||
use rpki::uri;
|
||||
use rpki::x509::Time;
|
||||
|
||||
use crate::commons::api::ca::{ResourceSet, TrustAnchorLocator};
|
||||
use crate::commons::api::rrdp::PublishElement;
|
||||
@@ -578,6 +579,31 @@ impl fmt::Display for UpdateChildRequest {
|
||||
}
|
||||
}
|
||||
|
||||
//------------ ServerInfo ----------------------------------------------------
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ServerInfo {
|
||||
version: String,
|
||||
started: i64,
|
||||
}
|
||||
|
||||
impl ServerInfo {
|
||||
pub fn new(version: &str, started: Time) -> Self {
|
||||
ServerInfo {
|
||||
version: version.to_string(),
|
||||
started: started.timestamp(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &str {
|
||||
&self.version
|
||||
}
|
||||
|
||||
pub fn started(&self) -> i64 {
|
||||
self.started
|
||||
}
|
||||
}
|
||||
|
||||
//------------ Tests ---------------------------------------------------------
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -193,6 +193,11 @@ pub fn metrics(server: web::Data<AppServer>) -> HttpResponse {
|
||||
HttpResponse::Ok().body(res)
|
||||
}
|
||||
|
||||
// Return general server info
|
||||
pub fn server_info(server: web::Data<AppServer>) -> HttpResponse {
|
||||
render_json(server.read().server_info())
|
||||
}
|
||||
|
||||
//------------ Admin: Publishers ---------------------------------------------
|
||||
|
||||
pub fn repo_stats(server: web::Data<AppServer>) -> HttpResponse {
|
||||
|
||||
@@ -52,6 +52,7 @@ pub fn start(config: &Config) -> Result<(), Error> {
|
||||
.wrap(middleware::Logger::default())
|
||||
.route("/health", get().to(endpoints::health))
|
||||
.route("/metrics", get().to(metrics))
|
||||
.route("/stats/info", get().to(server_info))
|
||||
.route("/stats/repo", get().to(repo_stats))
|
||||
.route("/stats/cas", get().to(cas_stats))
|
||||
// API end-points
|
||||
|
||||
@@ -6,15 +6,17 @@ use std::thread;
|
||||
|
||||
use bytes::Bytes;
|
||||
use chrono::Duration;
|
||||
|
||||
use rpki::cert::Cert;
|
||||
use rpki::uri;
|
||||
use rpki::x509::Time;
|
||||
|
||||
use crate::commons::api::{
|
||||
AddChildRequest, AllCertAuthIssues, CaRepoDetails, CertAuthHistory, CertAuthInfo, CertAuthInit,
|
||||
CertAuthIssues, CertAuthList, CertAuthStats, ChildCaInfo, ChildHandle, CurrentRepoState,
|
||||
Handle, ListReply, ParentCaContact, ParentCaReq, ParentHandle, PublishDelta, PublisherDetails,
|
||||
PublisherHandle, RepoInfo, RepositoryContact, RepositoryUpdate, RoaDefinition,
|
||||
RoaDefinitionUpdates, TaCertDetails, UpdateChildRequest,
|
||||
RoaDefinitionUpdates, ServerInfo, TaCertDetails, UpdateChildRequest,
|
||||
};
|
||||
use crate::commons::error::Error;
|
||||
use crate::commons::remote::rfc8183;
|
||||
@@ -62,6 +64,9 @@ pub struct KrillServer {
|
||||
// Responsible for background tasks, e.g. re-publishing
|
||||
#[allow(dead_code)] // just need to keep this in scope
|
||||
scheduler: Scheduler,
|
||||
|
||||
// Time this server was started
|
||||
started: Time,
|
||||
}
|
||||
|
||||
/// # Set up and initialisation
|
||||
@@ -154,12 +159,17 @@ impl KrillServer {
|
||||
pubserver,
|
||||
caserver,
|
||||
scheduler,
|
||||
started: Time::now(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn service_base_uri(&self) -> &uri::Https {
|
||||
&self.service_uri
|
||||
}
|
||||
|
||||
pub fn server_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(KRILL_VERSION, self.started)
|
||||
}
|
||||
}
|
||||
|
||||
/// # Authentication
|
||||
|
||||
Reference in New Issue
Block a user