public static void main(String[] args) { log.info("Application Version: {}, revision: {}, Build time: {}", AppInfo.getApplicationVersion(), AppInfo.getBuildRevision(), AppInfo.getBuildTime()); SpringApplication.run(Application.class, args); }
/** * extract '$artifactId' from manifest (Implementation-Title) or other places. * * @return */ public static String getApplicationName() { return getValue("dm-cluman-info-name"); }
private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Haven API") .description("Haven is an open source Docker container management system. " + "It integrates container, application, cluster, image, and registry management in one single place.") .contact(new Contact("Code Above Lab LLC", "https://github.com/codeabovelab/haven-platform", "info@codeabovelab.com")) .license("Apache License") .licenseUrl("https://www.apache.org/licenses/LICENSE-2.0") .version("1.0, server version: " + AppInfo.getApplicationVersion() + ", revision: " + AppInfo.getBuildRevision()) .build(); }
/** * create default ApplicationInfo * @return */ public static ApplicationInfoImpl createDefault() { return ApplicationInfoImpl.builder() .host(OSUtils.getHostName()) .application(AppInfo.getApplicationName()) .applicationVersion(AppInfo.getApplicationVersion()) .build(); } }
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { RabbitTemplate rabbitTemplate = this.templateFuture.get(); MetricReport report = new MetricReport(); Map<String, Object> data = new HashMap<>(); report.setMetrics(data); // we note that in MetricRegistry all data persisted into single map, and therefore it's keys unique per registry data.putAll(gauges); data.putAll(counters); data.putAll(histograms); data.putAll(meters); data.putAll(timers); try { MessageProperties messageProperties = new MessageProperties(); processMessageProperties(messageProperties); // it's not good, but it simply report.setApplication(messageProperties.getAppId()); report.setApplicationVersion(AppInfo.getApplicationVersion()); report.setHost((String)messageProperties.getHeaders().get(MessageHeaders.HOST)); byte[] body = objectMapper.writeValueAsBytes(report); Message message = new Message(body, messageProperties); rabbitTemplate.send(exchangeName, routingKey, message); } catch (JsonProcessingException e) { log.error("on serialize metrics report", e); } }
private void processMessageProperties(MessageProperties messageProperties) { messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON); messageProperties.setContentEncoding("UTF-8"); messageProperties.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT); messageProperties.setHeader(MessageHeaders.HOST, OSUtils.getHostName()); messageProperties.setAppId(AppInfo.getApplicationName()); if(this.messagePropertiesCallback != null) { this.messagePropertiesCallback.call(messageProperties); } } }
final String applicationId = AppInfo.getApplicationName(); AmqpUtils.ExchangeFactory exchangeFactory = new AmqpUtils.ExchangeFactory(); exchangeFactory.setExchangeName(exchange);
@RequestMapping(path = {"version", "info"}, method = RequestMethod.GET) public UiApplicationInfo getAppInfo() { return UiApplicationInfo.builder() .version(AppInfo.getApplicationVersion()) .buildTime(AppInfo.getBuildTime()) .buildRevision(AppInfo.getBuildRevision()) .address(UiUtils.getAppAddress(environment)) .build(); } }
/** * extract '$version' from manifest (Implementation-Version) or other places. * * @return */ public static String getApplicationVersion() { return getValue("dm-cluman-info-version"); }
public static String getBuildRevision() { return getValue("dm-cluman-info-buildRevision"); }
public static OffsetDateTime getBuildTime() { try { return OffsetDateTime.parse(getValue("dm-cluman-info-date"), DateTimeFormatter.ISO_OFFSET_DATE_TIME); } catch (DateTimeParseException e) { return OffsetDateTime.now(); } }