-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Erik Godding Boye <[email protected]>
- Loading branch information
Showing
4 changed files
with
62 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/no/statnett/k3alagexporter/MainLagExporterLoop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package no.statnett.k3alagexporter; | ||
|
||
import no.statnett.k3alagexporter.model.ClusterData; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
final class MainLagExporterLoop { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MainLagExporterLoop.class); | ||
|
||
public void runLoop() { | ||
try { | ||
final long msBetweenCollections = Conf.getPollIntervalMs(); | ||
LOG.info("Starting polling every " + msBetweenCollections + " ms"); | ||
final PrometheusReporter prometheusReporter = new PrometheusReporter(); | ||
prometheusReporter.start(); | ||
final ClusterLagCollector collector = new ClusterLagCollector(Conf.getClusterName(), | ||
Conf.getTopicAllowList(), Conf.getTopicDenyList(), | ||
Conf.getConsumerGroupAllowList(), Conf.getConsumerGroupDenyList(), | ||
Conf.getConsumerConfig(), Conf.getAdminConfig()); | ||
for (;;) { | ||
long t = System.currentTimeMillis(); | ||
final ClusterData clusterData = collector.collect(); | ||
prometheusReporter.publish(clusterData); | ||
t = System.currentTimeMillis() - t; | ||
try { | ||
Thread.sleep(Math.max(0, msBetweenCollections - t)); | ||
} catch (final InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} catch (final Exception e) { | ||
LOG.error("Fatal error. Terminating.", e); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/no/statnett/k3alagexporter/utils/LogUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package no.statnett.k3alagexporter.utils; | ||
|
||
public final class LogUtils { | ||
|
||
public static final String LOG_FORMAT_PROPERTY = "java.util.logging.SimpleFormatter.format"; | ||
|
||
private LogUtils() { | ||
} | ||
|
||
/** | ||
* Sets up logging to a single line when using Java Logging. | ||
* Must be called before any log-related class is instantiated. | ||
*/ | ||
public static void initLogging() { | ||
if (System.getProperty(LOG_FORMAT_PROPERTY) == null) { | ||
System.setProperty(LOG_FORMAT_PROPERTY, "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s: %5$s%6$s%n"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters