Search in sources :

Example 1 with Metrics

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));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) TestMetricsOutput(com.artipie.metrics.memory.TestMetricsOutput) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Example 2 with Metrics

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));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Metrics

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();
}
Also used : RepoConfig(com.artipie.repo.RepoConfig) Slice(com.artipie.http.Slice) Options(org.apache.commons.cli.Options) ArtipieRepositories(com.artipie.http.ArtipieRepositories) NopMetrics(com.artipie.metrics.nop.NopMetrics) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) BaseSlice(com.artipie.http.BaseSlice) Metrics(com.artipie.metrics.Metrics) Vertx(io.vertx.reactivex.core.Vertx) Storage(com.artipie.asto.Storage) ConfigFile(com.artipie.repo.ConfigFile) VertxSliceServer(com.artipie.vertx.VertxSliceServer) CommandLine(org.apache.commons.cli.CommandLine) MetricsFromConfig(com.artipie.metrics.MetricsFromConfig) Path(java.nio.file.Path) CommandLineParser(org.apache.commons.cli.CommandLineParser) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IOException(java.io.IOException) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) List(java.util.List) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) MainSlice(com.artipie.http.MainSlice) Optional(java.util.Optional) Logger(com.jcabi.log.Logger) ArtipieProperties(com.artipie.misc.ArtipieProperties) Storage(com.artipie.asto.Storage) RepoConfig(com.artipie.repo.RepoConfig) ConfigFile(com.artipie.repo.ConfigFile) ArtipieRepositories(com.artipie.http.ArtipieRepositories)

Example 4 with Metrics

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;
}
Also used : NopMetrics(com.artipie.metrics.nop.NopMetrics) Metrics(com.artipie.metrics.Metrics) MainSlice(com.artipie.http.MainSlice)

Example 5 with Metrics

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));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) MatchesPattern(org.hamcrest.text.MatchesPattern) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) AllOf(org.hamcrest.core.AllOf) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Metrics (com.artipie.metrics.Metrics)5 RequestLine (com.artipie.http.rq.RequestLine)3 InMemoryMetrics (com.artipie.metrics.memory.InMemoryMetrics)3 MainSlice (com.artipie.http.MainSlice)2 Header (com.artipie.http.headers.Header)2 RsHasBody (com.artipie.http.hm.RsHasBody)2 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)2 NopMetrics (com.artipie.metrics.nop.NopMetrics)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Key (com.artipie.asto.Key)1 Storage (com.artipie.asto.Storage)1 ArtipieRepositories (com.artipie.http.ArtipieRepositories)1 BaseSlice (com.artipie.http.BaseSlice)1 Slice (com.artipie.http.Slice)1 ClientSlices (com.artipie.http.client.ClientSlices)1 JettyClientSlices (com.artipie.http.client.jetty.JettyClientSlices)1 RsHasHeaders (com.artipie.http.hm.RsHasHeaders)1 RsHasStatus (com.artipie.http.hm.RsHasStatus)1 RsWithBody (com.artipie.http.rs.RsWithBody)1