prom-client#Registry TypeScript Examples

The following examples show how to use prom-client#Registry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: metrics.ts    From covid_exporter with MIT License 6 votes vote down vote up
private static initRegistry = _.once(() => {
    if (MetricsProvider.registry != null) {
      return MetricsProvider.registry
    }

    const registry = new Registry()
    registry.setDefaultLabels({ country: 'USA' })

    for (const key in keyNameMapping) {
      const metric = keyNameMapping[key]
      const gauge: Gauge<string> = new Gauge({
        name: `covid_${metric}`,
        help: key,
        labelNames: ['country', 'state'],
      })
      registry.registerMetric(gauge)
    }

    return registry
  })
Example #2
Source File: handler.ts    From eosio-contract-api with GNU Affero General Public License v3.0 6 votes vote down vote up
async getMetrics(registry: Registry): Promise<string> {
        this.registerMetrics(registry);

        await Promise.all([
            this.collectPSQlState(),
            this.collectPoolClientsCount(),
            this.collectRedisState(),
            this.collectReadersState()
        ]);

        return registry.metrics();
    }
Example #3
Source File: metrics.service.ts    From wise-old-man with MIT License 6 votes vote down vote up
constructor() {
    this.registry = new prometheus.Registry();
    this.registry.setDefaultLabels({ app: 'wise-old-man', threadIndex: getThreadIndex() });

    prometheus.collectDefaultMetrics({ register: this.registry });

    this.setupReactionHistogram();
    this.setupHttpHistogram();
    this.setupJobHistogram();
  }
Example #4
Source File: metrics.ts    From discord with GNU General Public License v3.0 5 votes vote down vote up
private static register = new Registry()
Example #5
Source File: Registry.ts    From Asena with MIT License 5 votes vote down vote up
registry = new Registry()
Example #6
Source File: index.test.ts    From common-ts with MIT License 5 votes vote down vote up
describe('Metrics', () => {
  test('Create metrics', () => {
    const metrics = createMetrics()
    expect(metrics.client).toBeDefined()
    expect(metrics.registry).toBeInstanceOf(Registry)
    metrics.registry.clear()
  })

  test('Serve metrics', async () => {
    const { client, registry } = createMetrics()
    const logger = createLogger({ name: 'test' })
    const server = createMetricsServer({ logger, registry, port: 51235 })

    try {
      // Create two metrics for testing
      const counter = new client.Counter({
        name: 'counter',
        help: 'counter help',
        registers: [registry],
      })
      const gauge = new client.Gauge({
        name: 'gauge',
        help: 'gauge help',
        registers: [registry],
      })

      counter.inc()
      counter.inc()
      gauge.set(100)

      // Verify that the registered metrics are served at `/`
      const response = await request(server).get('/metrics').send()
      expect(response.status).toEqual(200)
      expect(response.text).toMatch(/counter 2/)
      expect(response.text).toMatch(/gauge 100/)
    } finally {
      server.close()
      registry.clear()
    }
  })
})
Example #7
Source File: metrics.ts    From covid_exporter with MIT License 5 votes vote down vote up
static registry: Registry = MetricsProvider.initRegistry()
Example #8
Source File: handler.test.ts    From eosio-contract-api with GNU Affero General Public License v3.0 5 votes vote down vote up
describe('FillerMetricCollector', () => {
    const connections = new ConnectionManager({
        ...connectionConfig,
        postgres: {
            ...connectionConfig.postgres,
            database: `${connectionConfig.postgres.database}-test`,
        }
    });


    before(async () => {
        await connections.connect();
    });

    it('returns the metrics', async () => {
        const handler = new MetricsCollectorHandler(connections, 'filler', os.hostname());

        const metrics = [
            'eos_contract_api_sql_live',
            'eos_contract_api_pool_clients_count',
            'eos_contract_api_waiting_pool_clients_count',
            'eos_contract_api_idle_pool_clients_count',
            'eos_contract_api_readers_blocks_behind_count',
            'eos_contract_api_readers_time_behind_chain_sec',
            'eos_contract_api_redis_live',
        ];
        const res = await handler.getMetrics(new Registry());

        expect(metrics.every(s => res.includes(s))).to.be.true;
    });

    it('skips the metrics using the collect from option', async () => {
        const handler = new MetricsCollectorHandler(connections, 'filler', os.hostname(), {
            readers: false,
            redis_connection: false,
            psql_pool: false
        });

        const metrics = [
            'eos_contract_api_pool_clients_count',
            'eos_contract_api_waiting_pool_clients_count',
            'eos_contract_api_idle_pool_clients_count',
            'eos_contract_api_readers_blocks_behind_count',
            'eos_contract_api_readers_time_behind_chain_sec',
            'eos_contract_api_redis_live',
        ];
        const res = await handler.getMetrics(new Registry());

        expect(metrics.every(s => !res.includes(s))).to.be.true;
        expect(res.includes('eos_contract_api_sql_live')).to.be.true;
    });

    after(async () => {
        await connections.disconnect();
    });
});
Example #9
Source File: handler.ts    From eosio-contract-api with GNU Affero General Public License v3.0 5 votes vote down vote up
private registerMetrics(registry: Registry): void {
        this.metrics = {};

        if (this.collectFrom.psql_connection !== false) {
            this.metrics.psql_connection = new Gauge({
                name: 'eos_contract_api_sql_live',
                registers: [registry],
                labelNames: ['process', 'hostname'],
                help: 'Indicates if the sql connection is alive, 1 = Alive, 0 = Dead'
            });
        }

        if (this.collectFrom.psql_pool !== false) {
            this.metrics.psql_pool_clients_total_count = new Gauge({
                name: 'eos_contract_api_pool_clients_count',
                registers: [registry],
                labelNames: ['process', 'hostname'],
                help: 'Indicates how many client connections has spawn'
            });
            this.metrics.psql_pool_clients_waiting_count = new Gauge({
                name: 'eos_contract_api_waiting_pool_clients_count',
                registers: [registry],
                labelNames: ['process', 'hostname'],
                help: 'Indicates how many sql client connections are waiting'
            });
            this.metrics.psql_pool_clients_idle_count = new Gauge({
                name: 'eos_contract_api_idle_pool_clients_count',
                registers: [registry],
                labelNames: ['process', 'hostname'],
                help: 'Indicates how many sql client connections are idle'
            });
        }

        if (this.collectFrom.readers !== false) {
            this.metrics.readers_blocks_behind_count = new Gauge({
                name: 'eos_contract_api_readers_blocks_behind_count',
                registers: [registry],
                labelNames: ['process', 'hostname', 'filler_name'],
                help: 'Indicates how many blocks is the filler behind the chain'
            });
            this.metrics.readers_time_behind_chain_sec = new Gauge({
                name: 'eos_contract_api_readers_time_behind_chain_sec',
                registers: [registry],
                labelNames: ['process', 'hostname', 'filler_name'],
                help: 'Indicates how much time in seconds, is the filler behind the chain'
            });
        }

        if (this.collectFrom.redis_connection !== false) {
            this.metrics.redis_connection = new Gauge({
                name: 'eos_contract_api_redis_live',
                registers: [registry],
                labelNames: ['process', 'hostname'],
                help: 'Indicates if the redis connection is alive, 1 = Alive, 0 = Dead'
            });
        }

    }
Example #10
Source File: server.ts    From eosio-contract-api with GNU Affero General Public License v3.0 5 votes vote down vote up
serve(): void {
        this.server.all('/metrics', async (_req, res) => {
            res.send(await this.metricsCollector.getMetrics(new Registry()));
        });


        this.server.listen(this.port, () => logger.info(`Serving metrics on http://localhost:${this.port}/metrics`));
    }
Example #11
Source File: prometheus.ts    From squid with GNU General Public License v3.0 5 votes vote down vote up
private registry = new Registry()
Example #12
Source File: metrics.service.ts    From wise-old-man with MIT License 5 votes vote down vote up
private registry: Registry;