Comments (4)
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.
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.
@harneksidhu Were you able to get it running? What was the issue?
from client_ruby.
@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)
- CPU usage growing over time with DirectFileStore HOT 1
- better path handling HOT 14
- Update README.md with changes to pushgateway client
- Update CHANGELOG.md for 3.0.0 release HOT 1
- `generate_path` yields incorrect values for Sinatra+Rack::Build apps HOT 6
- Exporter port option doesn't work HOT 2
- Counter metric is reset when it has no labels HOT 8
- ERROR: Permission to prometheus/client_ruby.git denied HOT 2
- The rack example does not work because of `Rack::Lint::LintError` HOT 1
- Aaup HOT 1
- How to metrify ActiveRecord sql queries and Redis jobs (sidekiq/resque)? HOT 1
- pushing metrics with instance grouping_key would result: instance is reserved HOT 6
- Fix `Rack` deprecation warning
- Improving DirectFileStore for performance and scalability HOT 18
- Implement native histograms support HOT 4
- cannot load such file -- prometheus/middleware/collector (LoadError) HOT 2
- Job name for pushgateway can't be a symbol HOT 1
- UTF-8: Implement support in Ruby client library HOT 5
- How can I change how paths are labelled? HOT 1
- undefined method `unpack1' for String (NoMethodError) when use in ruby < 2.4 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from client_ruby.