Skip to content

Commit

Permalink
Merge pull request #208 from ahormazabal/dev/apigap
Browse files Browse the repository at this point in the history
CLI metrics commands
  • Loading branch information
gschueler authored Dec 17, 2018
2 parents 91c94d0 + fe86804 commit f20b69d
Show file tree
Hide file tree
Showing 9 changed files with 916 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -40,7 +43,7 @@
*/
public class RundeckClient {
public static final String USER_AGENT = Version.NAME + "/" + Version.VERSION;
public static final int API_VERS = 21;
public static final int API_VERS = 25;
public static final Pattern API_VERS_PATTERN = Pattern.compile("^(.*)(/api/(\\d+)/?)$");
public static final String ENV_BYPASS_URL = "RD_BYPASS_URL";
public static final String ENV_INSECURE_SSL = "RD_INSECURE_SSL";
Expand Down
39 changes: 39 additions & 0 deletions rd-api-client/src/main/java/org/rundeck/client/api/RundeckApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.rundeck.client.api.model.*;
import org.rundeck.client.api.model.metrics.EndpointListResult;
import org.rundeck.client.api.model.metrics.HealthCheckStatus;
import org.rundeck.client.api.model.metrics.MetricsData;
import org.rundeck.client.api.model.repository.ArtifactActionMessage;
import org.rundeck.client.api.model.repository.RepositoryArtifacts;
import org.rundeck.client.api.model.scheduler.ScheduledJobItem;
Expand Down Expand Up @@ -1155,4 +1158,40 @@ Call<BulkToggleJobScheduleResponse> bulkDisableJobSchedule(
);


// Metrics calls
/**
* @see <a href="https://rundeck.org/docs/api/#list-metrics">API</a>
*/
@Headers("Accept: application/json")
@GET("metrics")
Call<EndpointListResult> listMetricsEndpoints();

/**
* @see <a href="https://rundeck.org/docs/api/#metrics-healthcheck">API</a>
*/
@Headers("Accept: application/json")
@GET("metrics/healthcheck")
Call<Map<String, HealthCheckStatus>> getHealthCheckMetrics();

/**
* @see <a href="https://rundeck.org/docs/api/#metrics-threads">API</a>
*/
@Headers("Accept: application/json")
@GET("metrics/threads")
Call<ResponseBody> getThreadMetrics();

/**
* @see <a href="https://rundeck.org/docs/api/#metrics-ping">API</a>
*/
@Headers("Accept: application/json")
@GET("metrics/ping")
Call<ResponseBody> getPing();

/**
* @see <a href="https://rundeck.org/docs/api/#metrics-data">API</a>
*/
@Headers("Accept: application/json")
@GET("metrics/metrics")
Call<MetricsData> getMetricsData();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2017 Rundeck, Inc. (http://rundeck.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.rundeck.client.api.model.metrics;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.rundeck.client.api.model.sysinfo.Link;

import java.util.Map;


@JsonIgnoreProperties(ignoreUnknown = true)
public class EndpointListResult {

private Map<String, Link> endpointLinks;

public int size() {
return endpointLinks != null ? endpointLinks.size() : 0;
}

@JsonProperty("_links")
public Map<String, Link> getEndpointLinks() {
return endpointLinks;
}

@JsonProperty("_links")
public EndpointListResult setEndpointLinks(Map<String, Link> endpointLinks) {
this.endpointLinks = endpointLinks;
return this;
}

@Override
public String toString() {
return "EndpointListResult{" +
"endpointLinks=" + endpointLinks +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2017 Rundeck, Inc. (http://rundeck.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.rundeck.client.api.model.metrics;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;


@JsonIgnoreProperties(ignoreUnknown = true)
public class HealthCheckStatus {

private boolean healthy;
private String message;

public boolean isHealthy() {
return healthy;
}

public HealthCheckStatus setHealthy(boolean healthy) {
this.healthy = healthy;
return this;
}

public String getMessage() {
return message;
}

public HealthCheckStatus setMessage(String message) {
this.message = message;
return this;
}

@Override
public String toString() {
return "HealthCheckStatus{" +
"healthy=" + healthy +
", message='" + message + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.rundeck.client.api.model.metrics;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MetricsData {

private String version;
private Map<String, Map<String, Object>> gauges;
private Map<String, Map<String, Object>> counters;
private Map<String, Map<String, Object>> histograms;
private Map<String, Map<String, Object>> meters;
private Map<String, Map<String, Object>> timers;


public String getVersion() {
return version;
}

public MetricsData setVersion(String version) {
this.version = version;
return this;
}

public Map<String, Map<String, Object>> getGauges() {
return gauges;
}

public MetricsData setGauges(Map<String, Map<String, Object>> gauges) {
this.gauges = gauges;
return this;
}

public Map<String, Map<String, Object>> getCounters() {
return counters;
}

public MetricsData setCounters(Map<String, Map<String, Object>> counters) {
this.counters = counters;
return this;
}

public Map<String, Map<String, Object>> getHistograms() {
return histograms;
}

public MetricsData setHistograms(Map<String, Map<String, Object>> histograms) {
this.histograms = histograms;
return this;
}

public Map<String, Map<String, Object>> getMeters() {
return meters;
}

public MetricsData setMeters(Map<String, Map<String, Object>> meters) {
this.meters = meters;
return this;
}

public Map<String, Map<String, Object>> getTimers() {
return timers;
}

public MetricsData setTimers(Map<String, Map<String, Object>> timers) {
this.timers = timers;
return this;
}

@Override
public String toString() {
return "MetricsData{" +
"version='" + version + '\'' +
", gauges=" + gauges +
", counters=" + counters +
", histograms=" + histograms +
", meters=" + meters +
", timers=" + timers +
'}';
}
}
18 changes: 10 additions & 8 deletions src/main/java/org/rundeck/client/tool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@

package org.rundeck.client.tool;

import org.rundeck.client.RundeckClient;
import org.rundeck.client.api.RequestFailed;
import org.rundeck.client.api.RundeckApi;
import org.rundeck.client.api.model.DateInfo;
import org.rundeck.client.api.model.Execution;
import org.rundeck.client.api.model.JobItem;
import org.rundeck.client.api.model.scheduler.ScheduledJobItem;
import org.rundeck.client.tool.commands.*;
import org.rundeck.client.tool.commands.repository.Plugins;
import org.rundeck.client.util.*;
import org.rundeck.toolbelt.*;
import org.rundeck.toolbelt.format.json.jackson.JsonFormatter;
import org.rundeck.toolbelt.format.yaml.snakeyaml.YamlFormatter;
import org.rundeck.toolbelt.input.jewelcli.JewelInput;
import org.rundeck.client.RundeckClient;
import org.rundeck.client.api.RequestFailed;
import org.rundeck.client.api.RundeckApi;
import org.rundeck.client.api.model.*;
import org.rundeck.client.tool.commands.*;
import org.rundeck.client.util.*;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;
Expand Down Expand Up @@ -176,8 +178,8 @@ public static Tool tool(final Rd rd) {
new Nodes(rd),
new Users(rd),
new Something(),
new Retry(rd)

new Retry(rd),
new Metrics(rd)
)
.bannerResource("rd-banner.txt")
.commandInput(new JewelInput());
Expand Down
Loading

0 comments on commit f20b69d

Please sign in to comment.