Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INSTA-18639 Aggregate LLM metrics by application #76

Merged
merged 8 commits into from
Jan 12, 2025
28 changes: 28 additions & 0 deletions llm/src/main/java/com/instana/dc/llm/LLMDcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,32 @@ public class LLMDcUtil {
public static final String LLM_REQ_COUNT_NAME = "llm.request.count";
public static final String LLM_REQ_COUNT_DESC = "The total count of watsonx calls by interval";
public static final String LLM_REQ_COUNT_UNIT = "{count}";

public static final String LLM_SERVICE_COST_NAME = "llm.service.usage.cost";
public static final String LLM_SERVICE_COST_DESC = "The total cost of watsonx calls by interval";
public static final String LLM_SERVICE_COST_UNIT = "{cost}";

public static final String LLM_SERVICE_INPUT_COST_NAME = "llm.service.usage.input_cost";
public static final String LLM_SERVICE_INPUT_COST_DESC = "The input cost of watsonx calls by interval";
public static final String LLM_SERVICE_INPUT_COST_UNIT = "{cost}";

public static final String LLM_SERVICE_OUTPUT_COST_NAME = "llm.service.usage.output_cost";
public static final String LLM_SERVICE_OUTPUT_COST_DESC = "The output cost of watsonx calls by interval";
public static final String LLM_SERVICE_OUTPUT_COST_UNIT = "{cost}";

public static final String LLM_SERVICE_TOKEN_NAME = "llm.service.usage.total_tokens";
public static final String LLM_SERVICE_TOKEN_DESC = "The total tokens of watsonx calls by interval";
public static final String LLM_SERVICE_TOKEN_UNIT = "{token}";

public static final String LLM_SERVICE_INPUT_TOKEN_NAME = "llm.service.usage.input_tokens";
public static final String LLM_SERVICE_INPUT_TOKEN_DESC = "The input tokens of watsonx calls by interval";
public static final String LLM_SERVICE_INPUT_TOKEN_UNIT = "{token}";

public static final String LLM_SERVICE_OUTPUT_TOKEN_NAME = "llm.service.usage.output_tokens";
public static final String LLM_SERVICE_OUTPUT_TOKEN_DESC = "The output tokens of watsonx calls by interval";
public static final String LLM_SERVICE_OUTPUT_TOKEN_UNIT = "{token}";

public static final String LLM_SERVICE_REQ_COUNT_NAME = "llm.service.request.count";
public static final String LLM_SERVICE_REQ_COUNT_DESC = "The total count of watsonx calls by interval";
public static final String LLM_SERVICE_REQ_COUNT_UNIT = "{count}";
}
31 changes: 30 additions & 1 deletion llm/src/main/java/com/instana/dc/llm/LLMRawMetricRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@
import static com.instana.dc.llm.LLMDcUtil.LLM_REQ_COUNT_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_REQ_COUNT_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_REQ_COUNT_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_COST_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_COST_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_COST_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_INPUT_COST_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_INPUT_COST_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_INPUT_COST_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_INPUT_TOKEN_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_INPUT_TOKEN_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_INPUT_TOKEN_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_OUTPUT_COST_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_OUTPUT_COST_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_OUTPUT_COST_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_OUTPUT_TOKEN_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_OUTPUT_TOKEN_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_OUTPUT_TOKEN_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_REQ_COUNT_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_REQ_COUNT_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_REQ_COUNT_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_TOKEN_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_TOKEN_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_SERVICE_TOKEN_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_STATUS_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_STATUS_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_STATUS_UNIT;
Expand All @@ -43,7 +64,7 @@
import com.instana.dc.RawMetric;

public class LLMRawMetricRegistry {
private final Map<String, RawMetric> map = new ConcurrentHashMap<String, RawMetric>() {{
private final Map<String, RawMetric> map = new ConcurrentHashMap<>() {{
put(LLM_STATUS_NAME, new RawMetric(GAUGE, LLM_STATUS_NAME, LLM_STATUS_DESC, LLM_STATUS_UNIT, true, null));
put(LLM_DURATION_NAME, new RawMetric(GAUGE, LLM_DURATION_NAME, LLM_DURATION_DESC, LLM_DURATION_UNIT, true, "model_id"));
put(LLM_DURATION_MAX_NAME, new RawMetric(GAUGE, LLM_DURATION_MAX_NAME, LLM_DURATION_MAX_DESC, LLM_DURATION_MAX_UNIT, true, "model_id"));
Expand All @@ -54,6 +75,14 @@ public class LLMRawMetricRegistry {
put(LLM_INPUT_TOKEN_NAME, new RawMetric(GAUGE, LLM_INPUT_TOKEN_NAME, LLM_INPUT_TOKEN_DESC, LLM_INPUT_TOKEN_UNIT, false, "model_id"));
put(LLM_OUTPUT_TOKEN_NAME, new RawMetric(GAUGE, LLM_OUTPUT_TOKEN_NAME, LLM_OUTPUT_TOKEN_DESC, LLM_OUTPUT_TOKEN_UNIT, false, "model_id"));
put(LLM_REQ_COUNT_NAME, new RawMetric(UPDOWN_COUNTER, LLM_REQ_COUNT_NAME, LLM_REQ_COUNT_DESC, LLM_REQ_COUNT_UNIT, false, "model_id"));

put(LLM_SERVICE_COST_NAME, new RawMetric(GAUGE, LLM_SERVICE_COST_NAME, LLM_SERVICE_COST_DESC, LLM_SERVICE_COST_UNIT, false, "model_id"));
put(LLM_SERVICE_INPUT_COST_NAME, new RawMetric(GAUGE, LLM_SERVICE_INPUT_COST_NAME, LLM_SERVICE_INPUT_COST_DESC, LLM_SERVICE_INPUT_COST_UNIT, false, "model_id"));
put(LLM_SERVICE_OUTPUT_COST_NAME, new RawMetric(GAUGE, LLM_SERVICE_OUTPUT_COST_NAME, LLM_SERVICE_OUTPUT_COST_DESC, LLM_SERVICE_OUTPUT_COST_UNIT, false, "model_id"));
put(LLM_SERVICE_TOKEN_NAME, new RawMetric(GAUGE, LLM_SERVICE_TOKEN_NAME, LLM_SERVICE_TOKEN_DESC, LLM_SERVICE_TOKEN_UNIT, false, "model_id"));
put(LLM_SERVICE_INPUT_TOKEN_NAME, new RawMetric(GAUGE, LLM_SERVICE_INPUT_TOKEN_NAME, LLM_SERVICE_INPUT_TOKEN_DESC, LLM_SERVICE_INPUT_TOKEN_UNIT, false, "model_id"));
put(LLM_SERVICE_OUTPUT_TOKEN_NAME, new RawMetric(GAUGE, LLM_SERVICE_OUTPUT_TOKEN_NAME, LLM_SERVICE_OUTPUT_TOKEN_DESC, LLM_SERVICE_OUTPUT_TOKEN_UNIT, false, "model_id"));
put(LLM_SERVICE_REQ_COUNT_NAME, new RawMetric(UPDOWN_COUNTER, LLM_SERVICE_REQ_COUNT_NAME, LLM_SERVICE_REQ_COUNT_DESC, LLM_SERVICE_REQ_COUNT_UNIT, false, "model_id"));
}};

public Map<String, RawMetric> getMap() {
Expand Down
Loading