public PodMetricsReader(KubernetesClient kubernetes, String pod, String integration, String integrationId, String version, RawMetricsHandler handler) { this.pod = pod; this.integration = integration; this.integrationId = integrationId; this.version = version; this.handler = handler; this.jolokia = forPod(kubernetes, pod); }
/** * Tests whether the value is <tt>null</tt> or an empty string. * * @param value the value, if its a String it will be tested for text length as well * @return true if empty */ public static boolean isEmpty(Object value) { return !isNotEmpty(value); }
try { LOGGER.debug("Collecting stats from integrationId: {}", integrationId); List<Map<String, String>> routeStats = getRoutes(integration, "[a-zA-z0-9_-]+"); long messages = toLong(m.getOrDefault(EXCHANGES_TOTAL, "0")); long errors = toLong(m.getOrDefault(EXCHANGES_FAILED, "0")); Date lastCompleted = toDate(m.get(LAST_COMPLETED_TIMESTAMP)); Date lastFailed = toDate(m.get(LAST_FAILED_TIMESTAMP)); Date lastMessage = (lastCompleted == null && lastFailed != null) || : lastCompleted; Date resetDate = toDate(m.get(RESET_TIMESTAMP)); Date startDate = toDate(m.get(START_TIMESTAMP));
@Test @Ignore public void readTest() { String podName = "dbtest1-2-3nvf3"; String integration = "DBTest1"; String integrationId = "-L5ApZneYNfmLWG-PKQt"; String version = "1"; PodMetricsReader reader = new PodMetricsReader( new DefaultKubernetesClient(), podName, integration, integrationId, version, new LogRawMetrics()); reader.run(); } }
.filter(p -> Readiness.isReady(p)) .forEach(p -> executor.execute(new PodMetricsReader( kubernetes, p.getMetadata().getName(),
/** * Removes all leading and ending quotes (single and double) from the string * * @param s the string * @return the string without leading and ending quotes (single and double) */ public static String removeLeadingAndEndingQuotes(String s) { if (isEmpty(s)) { return s; } String copy = s.trim(); if (copy.startsWith("'") && copy.endsWith("'")) { return copy.substring(1, copy.length() - 1); } if (copy.startsWith("\"") && copy.endsWith("\"")) { return copy.substring(1, copy.length() - 1); } // no quotes, so return as-is return s; }
/** * Code borrowed from the DefaultCamelController: https://github.com/apache/camel/blob/master/platforms/commands/commands-jolokia/src/main/java/org/apache/camel/commands/jolokia/DefaultJolokiaCamelController.java * Slight modifications have been applied. * Credits to: Claus & Tomo */ private ObjectName lookupCamelContext(String camelContextName) throws Exception { ObjectName on = cache.get(camelContextName); if (on == null) { ObjectName found = null; J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest("org.apache.camel:type=context,*")); if (sr != null) { for (ObjectName name : sr.getObjectNames()) { String id = name.getKeyProperty("name"); id = removeLeadingAndEndingQuotes(id); if (camelContextName.equals(id)) { found = name; break; } } } if (found != null) { on = found; cache.put(camelContextName, on); } } return on; }
ObjectName found = camelContextName != null ? lookupCamelContext(camelContextName) : null; if (found != null) {