Git Product home page Git Product logo

Comments (4)

debanjandhar avatar debanjandhar commented on August 15, 2024 1

In case this ticket is open, I tried pushing metrics to push gateway using a collector and it worked for me. Below is the code for the same :

class PromCollector extends Collector implements Collector.Describable {

	@Override
	public List<MetricFamilySamples> describe() {
		List<MetricFamilySamples> sampleFamilies = new ArrayList<MetricFamilySamples>();
		sampleFamilies.add(new MetricFamilySamples("random_sample_1", Type.GAUGE, "Metis random sample no. 1",
				new ArrayList<MetricFamilySamples.Sample>()));
		sampleFamilies.add(new MetricFamilySamples("random_sample_2", Type.GAUGE, "Metis random sample no. 2",
				new ArrayList<MetricFamilySamples.Sample>()));
		return sampleFamilies;
	}

	@Override
	public List<MetricFamilySamples> collect() {
		List<MetricFamilySamples> mfsList = new ArrayList<MetricFamilySamples>();
		List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>();
		long start = System.nanoTime();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		samples.add(new MetricFamilySamples.Sample("random_sample_1", new ArrayList<String>(),
				new ArrayList<String>(), (System.nanoTime() - start) / 1.0E9));

		mfsList.add(new MetricFamilySamples("random_sample_1", Type.UNTYPED,
				"Metis random sample no. 1", samples));

		ArrayList<String> labelNames = new ArrayList<String>();
		labelNames.add("LN1");
		labelNames.add("LN2");

		ArrayList<String> labelValues = new ArrayList<String>();
		labelValues.add("LV 1");
		labelValues.add("LV 2");

		samples = new ArrayList<Collector.MetricFamilySamples.Sample>();
		
		samples.add(new MetricFamilySamples.Sample("random_sample_2", labelNames, labelValues, 1));
		mfsList.add(new MetricFamilySamples("random_sample_2", Type.UNTYPED,
				"Metis random sample no. 2", samples));

		System.out.println("Successfully added metrics from MetisPromCollector !!!");

		return mfsList;
	}

}

and I called this collector something like this :

void executeBatchJob() throws Exception {
		CollectorRegistry registry = new CollectorRegistry();

		MetisPromCollector mpc = new MetisPromCollector();
		mpc.register(registry);

		System.out.println("Job successfully completed");
		} finally {
			PushGateway pg = new PushGateway("localhost:9091");
			pg.pushAdd(registry, "job-name");
		}
	}

And I could see the PromCollector metrics in the pushgateway running in port 9091.

Hope it helps.

from client_ruby.

grobie avatar grobie commented on August 15, 2024

What problems are you running into when following all the code snippets from the README? All parts are described there actually. Prometheus::Client.registry will give you a reference to the default registry object which is also used by default in the rack middleware.

from client_ruby.

grobie avatar grobie commented on August 15, 2024

@harneksidhu Were you able to get it running? What was the issue?

from client_ruby.

harneksidhu avatar harneksidhu commented on August 15, 2024

@grobie Thanks for following up with me on this one! I actually tried to get it to work but I couldn't. I ended up closing this issue because I didn't need Pushgateway anymore for my implementation. Here is what I tried:

config.ru file

# config.ru

require ::File.expand_path('../config/environment',  __FILE__)
require 'rack'
require 'prometheus/client/rack/collector'
require 'prometheus/client/rack/exporter'

use Rack::Deflater
use Prometheus::Client::Rack::Collector
use Prometheus::Client::Rack::Exporter

require 'prometheus/client'
require 'prometheus/client/push'

prometheus = Prometheus::Client.registry

Prometheus::Client::Push.new(
  'my-job', 'instance-name', 'http://<pushgateway_ip>:9091').add(prometheus)

run Storybook::Application

My application successfully showed metrics on the app.com/metrics page. My pushgateway unfortunately was not showing anything.

from client_ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.