NRQL help needed

Hi I am trying to write a NRQL for disk used percentage, Which should check for multiple environments, But it is not working.

SELECT latest(host.diskUsedPercent) FROM Metric WHERE (Environment LIKE ‘%Production%’ AND Environment LIKE ‘%STAGE%’) AND Geography LIKE ‘US’ FACET host.hostname

Hi, @sharad.nandkumar: I think you want to query the SystemSample event, not Metric. Also, how are you specifying Environment and Geography for each host? They are not default attributes.

This one works for me to get the details of Single environment.

SELECT latest(host.diskUsedPercent) FROM Metric WHERE Environment=‘Production’ AND Geography=‘ESHOP’ FACET host.hostname

But I want to check multiple environments

Oh, I see the problem: Environment cannot be both Production and Stage. Try using OR instead of AND. :slight_smile:

Okay Let me try it now quickly

I used OR, But it is taking only one environment hosts. Is there any other way to write the NRQL where I can mention multiple environments?

Can I write query one after another?

I mean Like below:

  1. SELECT latest(host.diskUsedPercent) FROM Metric WHERE Environment=‘Production’ AND Geography=‘ESHOP’ FACET host.hostname
  2. SELECT latest(host.diskUsedPercent) FROM Metric WHERE Environment=‘STAGE’ AND Geography=‘ESHOP’ FACET host.hostname

Like above how can i use. Please let me know

It looks like all of your hosts WHERE Geography = 'ESHOP' have Environment = 'Production'; that is why you are not seeing hosts in Stage. This seems to work:

SELECT latest(host.diskUsedPercent) 
FROM Metric 
WHERE Environment IN ('Production', 'Stage') 
FACET host.hostname, Environment 
SINCE 1 day ago 
LIMIT MAX

You can add AND Geography = 'ESHOP', but then you won‘t see any Stage hosts, because there are none in that geography.

3 Likes