FluxaORM v2: Code-Generation-Based Go ORM for MySQL, Redis, ClickHouse and NATS JetStream
Guide
GitHub
Guide
GitHub
    • Introduction
    • Registry
    • Data Pools
    • Entities
    • Entity Fields
    • MySQL Indexes
    • Code Generation
    • Engine
    • Context
    • Schema Update
    • CRUD Operations
    • Transactions
    • Search
    • Redis Search
    • MySQL Queries
    • ClickHouse Queries
    • ClickHouse Schema
    • NATS and JetStream
    • Entity Change Events (CDC)
    • Consumers
    • Tasks and Job Runs
    • Transactional Outbox
    • Context Cache
    • Redis Cache
    • Fake Delete
    • Lifecycle Callbacks
    • Metrics
    • Redis Operations
    • Distributed Lock
    • Queries Log
    • Testing

Metrics

FluxaORM exposes Prometheus metrics for MySQL queries, Redis commands, ClickHouse queries, NATS operations and stream consumers. Metrics are disabled by default and cost nothing until you enable them.

Enabling Metrics

Pass a promauto.Factory to the registry with EnableMetrics before calling Validate(). The metric vectors are created inside Validate(), so enabling metrics afterwards has no effect.

import (
    "net/http"

    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promauto"
    "github.com/prometheus/client_golang/prometheus/promhttp"

    "github.com/latolukasz/fluxaorm/v2"
)

func main() {
    registry := fluxaorm.NewRegistry()
    registry.RegisterMySQL("user:password@tcp(localhost:3306)/db", fluxaorm.DefaultPoolCode, &fluxaorm.MySQLOptions{})
    registry.RegisterRedis("localhost:6379", 0, fluxaorm.DefaultPoolCode, nil)

    factory := promauto.With(prometheus.DefaultRegisterer)
    registry.EnableMetrics(factory)

    engine, err := registry.Validate()
    if err != nil {
        panic(err)
    }

    // expose everything registered in prometheus.DefaultRegisterer
    http.Handle("/metrics", promhttp.Handler())
    _ = engine
}

The signature is:

EnableMetrics(factory promauto.Factory)

Use promauto.With(registerer) to target a custom registerer, e.g. prometheus.WrapRegistererWith(prometheus.Labels{"app": "api"}, prometheus.DefaultRegisterer) to add constant labels to every FluxaORM metric.

The source Label

Every metric except the consumer ones carries a source label. It defaults to "default" and is read from the context metadata key fluxaorm.MetricsMetaKey:

ctx.SetMetaData(fluxaorm.MetricsMetaKey, "checkout_api")

All queries executed through ctx (and through contexts created with ctx.Clone() / ctx.CloneWithContext(), which copy the metadata) are then tagged source="checkout_api".

Task consumers set the tag automatically: before a task handler runs, the consumer calls SetMetaData(MetricsMetaKey, taskName) on the handler's context, so every MySQL, Redis, ClickHouse and NATS metric emitted while handling a task carries source="<task name>". See Tasks.

MySQL Metrics

fluxaorm_db_queries_seconds (Histogram)

Help: Total number of DB queries executed. Default Prometheus buckets.

LabelValuesDescription
operationtransaction, exec, selecttransaction = START TRANSACTION, COMMIT, ROLLBACK; exec = DB.Exec (and every generated INSERT/UPDATE/DELETE); select = DB.QueryRow and DB.Query
poolMySQL pool codee.g. "default"
sourcesource tagsee above

fluxaorm_db_queries_errors (Counter)

Help: Total number of DB queries errors. Incremented when a MySQL query returns an error.

LabelDescription
poolMySQL pool code
sourcesource tag

Redis Metrics

fluxaorm_redis_queries_seconds (Histogram)

Help: Total number of Redis queries executed. Default Prometheus buckets. One observation per command executed through the FluxaORM Redis client, including commands issued by generated code (Redis cache, Redis Search) and by the distributed lock.

LabelValuesDescription
operationkey, list, hash, set, stream, search, lock, otherCommand category (see table below)
poolRedis pool codee.g. "default"
set0, 11 for write commands
miss0, 11 when a read did not find the key/field
pipeline0, 11 when the command was executed through ctx.RedisPipeLine()
sourcesource tagsee above

Operation categories and which methods report set="1":

operationMethodsset="1" for
keyGet, Set, SetNX, MSet, MGet, Del, Exists, Type, Expire, Incr, IncrBy, IncrWithExpireSet, SetNX, MSet, Del, Expire, Incr, IncrBy, IncrWithExpire
listLPush, RPush, LPop, RPop, LLen, LRange, LIndex, LSet, LRem, Ltrim, LMove, BLMoveLPush, RPush, LSet, LMove, BLMove
hashHSet, HSetNx, HDel, HGet, HMGet, HGetAll, HLen, HIncrByHSet, HSetNx, HDel, HIncrBy
setSAdd, SMembers, SIsMember, SCard, SPop, SPopN, ZAdd, ZCard, ZCount, ZScore, ZRevRange, ZRevRangeWithScores, ZRangeWithScores, ZRangeArgsWithScoresSAdd, ZAdd
streamXTrim, XRange, XRevRange, XRead, XReadGroup (only with Block < 0), XLen, XInfoStream, XInfoGroups, XPending, XPendingExt, XClaim, XClaimJustID, XAutoClaim, XGroupCreate, XGroupCreateMkStream, XGroupDestroy, XGroupDelConsumer, XDel, XAck, XAckDelXGroupCreate, XGroupCreateMkStream, XGroupDestroy, XGroupDelConsumer, XDel, XAck, XAckDel
searchFTList, FTSearch, FTInfo, FTCreate, FTDropFTCreate, FTDrop
lockLocker.Obtain, Lock.Release, Lock.TTL, Lock.Refreshalways 1
otherInfo, Eval, EvalSha, ScriptLoad, ScriptExists, Scan, FlushDB, FlushAllFlushDB, FlushAll

miss="1" is reported by Get when the key does not exist, by HGet when the field does not exist, and by MGet / HMGet when at least one requested value is nil. All other reads report miss="0".

Warning

For operation="lock" the miss label is inverted compared to the other categories: a successful Obtain, Release, TTL or Refresh is recorded with miss="1", and an Obtain that did not get the lock is recorded with miss="0". Take this into account when writing alerts on lock contention.

GetSet is recorded as a Get plus, on a miss, a Set. IncrWithExpire is recorded once as key / set="1". XReadGroup with Block >= 0 is not observed here at all (see fluxaorm_redis_queries_block).

Pipelines

When a Redis pipeline is executed, every command in it gets one observation with pipeline="1" and a duration equal to the whole Exec time divided by the number of commands. The category is derived from the command name:

Commandoperationset
getkey0 (miss="1" when the key was absent)
set, del, mset, expirekey1
lpush, rpushlist1
lrangelist0
sadd, sremset1
hset, hdel, hincrbyhash1
anything elsekey0

fluxaorm_redis_queries_block (Counter)

Help: Total number of Redis blocking queries executed. Incremented only by XReadGroup when XReadGroupArgs.Block >= 0 (note that the zero value of Block counts as blocking). Such calls are not timed and do not appear in fluxaorm_redis_queries_seconds.

LabelValues
operationalways stream
poolRedis pool code
sourcesource tag

fluxaorm_redis_queries_errors (Counter)

Help: Total number of Redis queries errors. Incremented when a Redis command (including a pipeline Exec or a lock operation) returns an error.

LabelDescription
poolRedis pool code
sourcesource tag

ClickHouse Metrics

fluxaorm_clickhouse_queries_seconds (Histogram)

Help: Total number of ClickHouse queries executed. Default Prometheus buckets.

LabelValuesDescription
operationexec, selectexec = Clickhouse.Exec; select = Clickhouse.QueryRow and Clickhouse.Query
poolClickHouse pool codee.g. "analytics"
sourcesource tagsee above

fluxaorm_clickhouse_queries_errors (Counter)

Help: Total number of ClickHouse queries errors.

LabelDescription
poolClickHouse pool code
sourcesource tag

NATS Metrics

See NATS for the publisher and consumer API.

fluxaorm_nats_operations_seconds (Histogram)

Help: Total number of NATS operations executed. Default Prometheus buckets.

LabelValuesDescription
operationpublish, publish_async, fetchpublish = Publish, PublishWithAck and PublishBatch (one observation per batch); publish_async = PublishAsync (observed when the ack arrives, or immediately on a publish error); fetch = consumer Fetch
poolNATS pool code
sourcesource tag
consumerdurable consumer name, or ""Empty for publish operations, the consumer name for fetch

fluxaorm_nats_operations_errors (Counter)

Help: Total number of NATS operation errors.

LabelDescription
poolNATS pool code
sourcesource tag
consumerdurable consumer name, "" for publish operations

fluxaorm_nats_publish_batch_size (Histogram)

Help: Number of messages per batched NATS publish. Buckets: prometheus.ExponentialBuckets(1, 2, 12) (1, 2, 4, ... 2048). Observed once per PublishBatch call with the number of messages in the batch. Use it to check whether batching actually amortises round trips.

LabelDescription
poolNATS pool code
sourcesource tag

Consumer Metrics

These are emitted by consumers reading entity events from JetStream. They have no source label.

fluxaorm_cdc_messages_total (Counter)

Help: Total number of entity change events fetched from JetStream. Incremented once per entity-change message fetched by a consumer, before the handler runs.

LabelValuesDescription
consumerConsumerDef.NameThe consumer that fetched the message
entityentity nameThe entity the change belongs to
opinsert, update, delete, unknownParsed from the message's dirty-op header; unknown when the header is missing or malformed

fluxaorm_stream_consume_lag_seconds (Histogram)

Help: Time from publish (JetStream broker timestamp) to consume, per consumer. Buckets: prometheus.ExponentialBuckets(0.001, 4, 10) (1ms to about 262s). Observed per fetched entity-change message as time.Since(msg.Timestamp), skipped when the broker timestamp is zero.

LabelDescription
consumerConsumerDef.Name

Summary

MetricTypeLabels
fluxaorm_db_queries_secondsHistogramoperation, pool, source
fluxaorm_db_queries_errorsCounterpool, source
fluxaorm_redis_queries_secondsHistogramoperation, pool, set, miss, pipeline, source
fluxaorm_redis_queries_blockCounteroperation, pool, source
fluxaorm_redis_queries_errorsCounterpool, source
fluxaorm_clickhouse_queries_secondsHistogramoperation, pool, source
fluxaorm_clickhouse_queries_errorsCounterpool, source
fluxaorm_nats_operations_secondsHistogramoperation, pool, source, consumer
fluxaorm_nats_operations_errorsCounterpool, source, consumer
fluxaorm_nats_publish_batch_sizeHistogrampool, source
fluxaorm_cdc_messages_totalCounterconsumer, entity, op
fluxaorm_stream_consume_lag_secondsHistogramconsumer
Edit this page
Last Updated: 9/21/26, 9:14 AM
Prev
Lifecycle Callbacks
Next
Redis Operations