001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.metrics;
020
021import io.micrometer.core.instrument.Tags;
022
023/**
024 * Catalog of jPOS-defined Micrometer meters: a stable identifier, human-readable
025 * description, and optional default tags for each instrument.
026 */
027public enum MeterInfo {
028    /** TransactionManager active session count. */
029    TM_ACTIVE ("jpos.tm.active", "TransactionManager activeSessions"),
030    /** TransactionManager operation timer. */
031    TM_OPERATION("jpos.tm.op", "TransactionManager operation"),
032    /** TransactionManager arbitrary counter. */
033    TM_COUNTER("jpos.tm.cnt", "TransactionManager counter"),
034
035    /** Active inbound connections accepted by ISOServer. */
036    ISOSERVER_CONNECTION_COUNT("jpos.server.connections", "Incoming active connections"),
037    /** Active outbound connections opened by ISOChannel. */
038    ISOCHANNEL_CONNECTION_COUNT("jpos.channel.connections", "Outgoing active connections"),
039
040    /** Outbound ISO message counter, tagged {@code direction=out}. */
041    ISOMSG_OUT("jpos.isomsg", "Transmitted messages", Tags.of ("direction", "out")),
042    /** Inbound ISO message counter, tagged {@code direction=in}. */
043    ISOMSG_IN ("jpos.isomsg", "Received messages",    Tags.of ("direction", "in")),
044
045    /** Active outbound connections; alias kept for backward compatibility. */
046    CHANNEL_ACTIVE_CONNECTIONS("jpos.channel.connections", "Active outgoing connections"),
047    /** Per-channel up/down status gauge. */
048    CHANNEL_STATUS("jpos.channel.status", "Channel status"),
049
050    /** Per-MUX up/down status gauge. */
051    MUX_STATUS("jpos.mux.status", "MUX Status"),
052    /** Number of in-flight requests awaiting a response. */
053    MUX_RX_PENDING("jpos.mux.pending", "MUX rx pending"),
054    /** Response time timer for MUX request/response pairs. */
055    MUX_RESPONSE_TIMER("jpos.mux.timer", "MUX response"),
056    /** MUX transmit counter, tagged {@code type=tx}. */
057    MUX_TX("jpos.mux", "MUX tx", Tags.of("type", "tx")),
058    /** MUX receive counter, tagged {@code type=rx}. */
059    MUX_RX ("jpos.mux", "MUX rx", Tags.of("type", "rx")),
060    /** MUX matched-response counter, tagged {@code type=match}. */
061    MUX_MATCH ("jpos.mux", "MUX rx unhandled", Tags.of("type", "match")),
062    /** MUX unhandled-response counter, tagged {@code type=unhandled}. */
063    MUX_UNHANDLED ("jpos.mux", "MUX rx unhandled", Tags.of("type", "unhandled"));
064
065    final String id;
066    final String description;
067    final Tags tags;
068
069    MeterInfo(String id, String description) {
070        this (id, description, null);
071    }
072    MeterInfo(String id, String description, Tags tags) {
073        this.id = id;
074        this.description = description;
075        this.tags = tags;
076    }
077
078    /**
079     * Returns the meter identifier.
080     *
081     * @return the meter id (e.g. {@code jpos.mux.status})
082     */
083    public String id() {
084        return id;
085    }
086
087    /**
088     * Returns the human-readable meter description.
089     *
090     * @return the meter description
091     */
092    public String description() {
093        return description;
094    };
095
096    /**
097     * Combines the supplied tags with this meter's default tags.
098     *
099     * @param tags caller-supplied tags
100     * @return the combined tag set, or {@code tags} unchanged when this meter has no defaults
101     */
102    public Tags add (Tags tags) {
103        return this.tags != null ? tags.and(this.tags) : tags;
104    }
105}