You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by deniz <de...@gmail.com> on 2018/10/03 07:03:24 UTC

Metrics API via Solrj

Are there anyway to get the metrics via solrj ? all of the examples seem like
using plain curl or http reqs with json response. I have found
org.apache.solr.client.solrj.io.stream.metrics package, but couldnt figure
out how to send the requests via solrj... 

could anyone help me to figure out how to deal with metrics api on solrj? 



-----
Zeki ama calismiyor... Calissa yapar...
--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html

Re: Metrics API via Solrj

Posted by deniz <de...@gmail.com>.
Thanks a lot Jason and Shawn, it is quite smooth although there is no built
in stuff like collection or schema request objects for metrics :) 



-----
Zeki ama calismiyor... Calissa yapar...
--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html

Re: Metrics API via Solrj

Posted by Shawn Heisey <ap...@elyograg.org>.
On 10/3/2018 6:17 AM, Jason Gerlowski wrote:
>          NamedList<Object> respNL = response.getResponse();
>          NamedList<Object> metrics = (NamedList<Object>)respNL.get("metrics");
>          NamedList<Object> jvmMetrics = (NamedList<Object>)
> metrics.get("solr.jvm");
>          Long numClassesLoaded = (Long) jvmMetrics.get("classes.loaded");

If you're running a new enough SolrJ version, which you probably are 
because findRecursive was added more than five years ago, all of these 
code lines can be replaced with one code line:

   Long numClassesLoaded = (Long) response.getResponse().findRecursive(
"metrics", "solr.jvm", "classes.loaded");

I don't think it'll run any faster, or even use any less memory, but I 
think it is much easier to read and understand.

Thanks,
Shawn


Re: Metrics API via Solrj

Posted by Jason Gerlowski <ge...@gmail.com>.
Hi Deniz,

I don't think there are any classes that simplify accessing the
metrics API like there are for other APIs (e.g.
CollectionAdminRequest, CoreAdminRequest, ..).  But sending metrics
requests in SolrJ is still possible; it's just a little bit more
complicated.

Anytime you want to make an API call that doesn't have specific
objects for it, you can use one of the general-purpose SolrRequest
objects.  I've included an example below that reads the
"classes.loaded" JVM metric:

        final SolrClient client = new
HttpSolrClient.Builder("http://localhost:8983/solr").build();

        final ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("group", "jvm");
        final GenericSolrRequest req = new
GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/metrics", params);

        SimpleSolrResponse response = req.process(client);
        NamedList<Object> respNL = response.getResponse();
        NamedList<Object> metrics = (NamedList<Object>)respNL.get("metrics");
        NamedList<Object> jvmMetrics = (NamedList<Object>)
metrics.get("solr.jvm");
        Long numClassesLoaded = (Long) jvmMetrics.get("classes.loaded");
        System.out.println("Num classes loaded was: " + numClassesLoaded);

It's a little more painful to have to dig through the NamedList
yourself, but it's still very do-able.  Hope that helps.

Best,

Jason
On Wed, Oct 3, 2018 at 3:03 AM deniz <de...@gmail.com> wrote:
>
> Are there anyway to get the metrics via solrj ? all of the examples seem like
> using plain curl or http reqs with json response. I have found
> org.apache.solr.client.solrj.io.stream.metrics package, but couldnt figure
> out how to send the requests via solrj...
>
> could anyone help me to figure out how to deal with metrics api on solrj?
>
>
>
> -----
> Zeki ama calismiyor... Calissa yapar...
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html