metrics: make 'prefix' a variable

This commit is contained in:
Alex Gleason 2025-02-16 11:45:08 -06:00
parent e1c1967a66
commit fbb5c63c33
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,149 +1,151 @@
import { Counter, Gauge, Histogram } from 'prom-client';
const prefix = 'ditto';
export const httpRequestsCounter = new Counter({
name: 'ditto_http_requests_total',
name: `${prefix}_http_requests_total`,
help: 'Total number of HTTP requests',
labelNames: ['method'],
});
export const httpResponsesCounter = new Counter({
name: 'ditto_http_responses_total',
name: `${prefix}_http_responses_total`,
help: 'Total number of HTTP responses',
labelNames: ['method', 'path', 'status'],
});
export const httpResponseDurationHistogram = new Histogram({
name: 'ditto_http_response_duration_seconds',
name: `${prefix}_http_response_duration_seconds`,
help: 'Histogram of HTTP response times in seconds',
labelNames: ['method', 'path', 'status'],
});
export const streamingConnectionsGauge = new Gauge({
name: 'ditto_streaming_connections',
name: `${prefix}_streaming_connections`,
help: 'Number of active connections to the streaming API',
});
export const streamingServerMessagesCounter = new Counter({
name: 'ditto_streaming_server_messages_total',
name: `${prefix}_streaming_server_messages_total`,
help: 'Total number of messages sent from the streaming API',
});
export const streamingClientMessagesCounter = new Counter({
name: 'ditto_streaming_client_messages_total',
name: `${prefix}_streaming_client_messages_total`,
help: 'Total number of messages received by the streaming API',
});
export const fetchResponsesCounter = new Counter({
name: 'ditto_fetch_responses_total',
name: `${prefix}_fetch_responses_total`,
help: 'Total number of fetch requests',
labelNames: ['method', 'status'],
});
export const firehoseEventsCounter = new Counter({
name: 'ditto_firehose_events_total',
name: `${prefix}_firehose_events_total`,
help: 'Total number of Nostr events processed by the firehose',
labelNames: ['kind'],
});
export const pipelineEventsCounter = new Counter({
name: 'ditto_pipeline_events_total',
name: `${prefix}_pipeline_events_total`,
help: 'Total number of Nostr events processed by the pipeline',
labelNames: ['kind'],
});
export const policyEventsCounter = new Counter({
name: 'ditto_policy_events_total',
name: `${prefix}_policy_events_total`,
help: 'Total number of policy OK responses',
labelNames: ['ok'],
});
export const relayEventsCounter = new Counter({
name: 'ditto_relay_events_total',
name: `${prefix}_relay_events_total`,
help: 'Total number of EVENT messages processed by the relay',
labelNames: ['kind'],
});
export const relayMessagesCounter = new Counter({
name: 'ditto_relay_messages_total',
name: `${prefix}_relay_messages_total`,
help: 'Total number of Nostr messages processed by the relay',
labelNames: ['verb'],
});
export const relayConnectionsGauge = new Gauge({
name: 'ditto_relay_connections',
name: `${prefix}_relay_connections`,
help: 'Number of active connections to the relay',
});
export const dbQueriesCounter = new Counter({
name: 'ditto_db_queries_total',
name: `${prefix}_db_queries_total`,
help: 'Total number of database queries',
labelNames: ['kind'],
});
export const dbEventsCounter = new Counter({
name: 'ditto_db_events_total',
name: `${prefix}_db_events_total`,
help: 'Total number of database inserts',
labelNames: ['kind'],
});
export const dbPoolSizeGauge = new Gauge({
name: 'ditto_db_pool_size',
name: `${prefix}_db_pool_size`,
help: 'Number of connections in the database pool',
});
export const dbAvailableConnectionsGauge = new Gauge({
name: 'ditto_db_available_connections',
name: `${prefix}_db_available_connections`,
help: 'Number of available connections in the database pool',
});
export const dbQueryDurationHistogram = new Histogram({
name: 'ditto_db_query_duration_seconds',
name: `${prefix}_db_query_duration_seconds`,
help: 'Duration of database queries',
});
export const cachedFaviconsSizeGauge = new Gauge({
name: 'ditto_cached_favicons_size',
name: `${prefix}_cached_favicons_size`,
help: 'Number of domain favicons in cache',
});
export const cachedLnurlsSizeGauge = new Gauge({
name: 'ditto_cached_lnurls_size',
name: `${prefix}_cached_lnurls_size`,
help: 'Number of LNURL details in cache',
});
export const cachedNip05sSizeGauge = new Gauge({
name: 'ditto_cached_nip05s_size',
name: `${prefix}_cached_nip05s_size`,
help: 'Number of NIP-05 results in cache',
});
export const cachedLinkPreviewSizeGauge = new Gauge({
name: 'ditto_cached_link_previews_size',
name: `${prefix}_cached_link_previews_size`,
help: 'Number of link previews in cache',
});
export const cachedTranslationsSizeGauge = new Gauge({
name: 'ditto_cached_translations_size',
name: `${prefix}_cached_translations_size`,
help: 'Number of translated statuses in cache',
});
export const internalSubscriptionsSizeGauge = new Gauge({
name: 'ditto_internal_subscriptions_size',
name: `${prefix}_internal_subscriptions_size`,
help: "Number of active subscriptions to Ditto's internal relay",
});
export const relayPoolRelaysSizeGauge = new Gauge({
name: 'ditto_relay_pool_relays_size',
name: `${prefix}_relay_pool_relays_size`,
help: 'Number of relays in the relay pool',
labelNames: ['ready_state'],
});
export const relayPoolSubscriptionsSizeGauge = new Gauge({
name: 'ditto_relay_pool_subscriptions_size',
name: `${prefix}_relay_pool_subscriptions_size`,
help: 'Number of active subscriptions to the relay pool',
});
export const webPushNotificationsCounter = new Counter({
name: 'ditto_web_push_notifications_total',
name: `${prefix}_web_push_notifications_total`,
help: 'Total number of Web Push notifications sent',
labelNames: ['type'],
});