Show server info (version and uptime) on API. (#201)

This commit is contained in:
Tim Bruijnzeels
2020-02-11 12:12:01 +01:00
parent 3f0668584a
commit e6252333e8
4 changed files with 43 additions and 1 deletions
+26
View File
@@ -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)]
+5
View File
@@ -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 {
+1
View File
@@ -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
+11 -1
View File
@@ -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