use of com.artipie.metrics.Metrics in project artipie by artipie.
the class TrafficMetricSliceTest method updatesMetrics.
@Test
void updatesMetrics() throws Exception {
final Metrics metrics = new InMemoryMetrics();
final int req = 100;
final int res = 50;
new TrafficMetricSlice((line, head, body) -> new RsWithBody(Flowable.fromPublisher(body).ignoreElements().andThen(Flowable.just(ByteBuffer.wrap(new byte[res])))), metrics).response(new RequestLine(RqMethod.GET, "/foo").toString(), Collections.emptyList(), Flowable.just(ByteBuffer.wrap(new byte[req]))).send((status, headers, body) -> Flowable.fromPublisher(body).ignoreElements().to(CompletableInterop.await())).toCompletableFuture().get();
final TestMetricsOutput out = new TestMetricsOutput();
metrics.publish(out);
MatcherAssert.assertThat("request body size wasn't updated", out.counters().get("request.body.size"), Matchers.equalTo((long) req));
MatcherAssert.assertThat("response body size wasn't updated", out.counters().get("response.body.size"), Matchers.equalTo((long) res));
}
use of com.artipie.metrics.Metrics in project artipie by artipie.
the class PromuSliceTest method returnsMetricsThatMatchNames.
@Test
void returnsMetricsThatMatchNames() {
final Metrics metrics = new InMemoryMetrics();
metrics.counter("http.response.count").inc();
metrics.gauge("http.response.content").set(5000L);
metrics.gauge("app.workload").set(300L);
MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new RsHasBody(new AnyOf<>(new IsEqual<>(String.join("\n", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "")), new IsEqual<>(String.join("\n", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", ""))), StandardCharsets.UTF_8), new RequestLine(RqMethod.GET, "/prometheus/metrics?name=http_response_content&name=app_workload"), new Headers.From(new Header(Accept.NAME, PromuSliceTest.PLAIN_TEXT)), Content.EMPTY));
}
use of com.artipie.metrics.Metrics in project artipie by artipie.
the class VertxMain method startRepos.
/**
* Start repository servers.
*
* @param settings Settings.
* @param metrics Metrics.
*/
private void startRepos(final Settings settings, final Metrics metrics) {
final Storage storage = settings.repoConfigsStorage();
final Collection<RepoConfig> configs = storage.list(Key.ROOT).thenApply(keys -> keys.stream().map(key -> new ConfigFile(key)).filter(Predicate.not(ConfigFile::isSystem).and(ConfigFile::isYamlOrYml)).map(ConfigFile::name).map(name -> new RepositoriesFromStorage(this.http, storage).config(name)).map(stage -> stage.toCompletableFuture().join()).collect(Collectors.toList())).toCompletableFuture().join();
for (final RepoConfig repo : configs) {
try {
repo.port().ifPresent(prt -> {
final String name = new ConfigFile(repo.name()).name();
this.listenOn(new ArtipieRepositories(this.http, settings).slice(new Key.From(name), true), metrics, prt);
Logger.info(VertxMain.class, "Artipie repo '%s' was started on port %d", name, prt);
});
} catch (final IllegalStateException err) {
Logger.error(this, "Invalid repo config file %s: %[exception]s", repo.name(), err);
}
}
new QuartzScheduler(configs).start();
}
use of com.artipie.metrics.Metrics in project artipie by artipie.
the class VertxMain method start.
/**
* Starts the server.
*
* @return Port the servers listening on.
* @throws IOException In case of error reading settings.
*/
public int start() throws IOException {
final Settings settings = new SettingsFromPath(this.config).find(this.port);
final Metrics metrics = metrics(settings);
final int main = this.listenOn(new MainSlice(this.http, settings, metrics), metrics, this.port);
Logger.info(VertxMain.class, "Artipie was started on port %d", main);
this.startRepos(settings, metrics);
return main;
}
use of com.artipie.metrics.Metrics in project artipie by artipie.
the class PromuSliceTest method producesMetrics.
@ParameterizedTest
@CsvSource({ "http.response.length,500,counter,text/plain", "http.response.length,500,counter,application/openmetrics-text", "app.used.memory,200,gauge,text/plain", "app.used.memory,200,gauge,application/openmetrics-text" })
void producesMetrics(final String name, final long value, final String type, final String mimetype) {
final Metrics metrics = new InMemoryMetrics();
collect(metrics, name, value, type);
MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new RsHasHeaders(new IsEqual<>(new Header(ContentType.NAME, mimetype)), new IsAnything<>()), new RsHasBody(new MatchesPattern(Pattern.compile(metricFormatted(name, value, type, mimetype))), StandardCharsets.UTF_8))), new RequestLine(RqMethod.GET, "/prometheus/metrics"), new Headers.From(Accept.NAME, mimetype), Content.EMPTY));
}
Aggregations