I am unable to retrieve the most recent data from the query in influxdb

I've been working with an influxql query to retrieve CPU, memory, load, and disk values using a WHERE clause to specify only data from 1 minute ago. The challenge I'm facing is that the query consistently returns the same date as specified in the WHERE clause. What I really need is to fetch the most recent dates, i.e., the latest timestamps when the server sent data to the InfluxDB database.

My main goal is to identify machines that haven't been sending data lately. To achieve this, I want to determine the last timestamp recorded within the past hour using the condition:

 time> = now () - 1h

Currently, my query example specifies the following static date range:

02/02/2019, 19:33:35
02/02/2019, 19:33:35
02/02/2019, 19:33:35
02/02/2019, 19:33:35
02/02/2019, 19:33:35

What I actually require is a dynamic approach to get the latest timestamps within the one-hour window so that I can compare them against the currently fetched records' timestamps:

02/02/2019, 19:33:35
02/02/2019, 19:35:12
02/02/2019, 19:43:30
02/02/2019, 19:40:25
02/02/2019, 19:36:32

Your assistance in understanding this issue would be greatly appreciated. Thank you!

This is the SQL code snippet I am using:

SELECT 
  LAST(cpu_used) AS cpu, 
  LAST(mem_used) AS mem, 
  LAST(load) AS load, 
  LAST(disk_await) AS disk_await 
FROM custom  
WHERE time >= now() - 1m 
GROUP BY hostname

Here's a sample output from the query:

name: custom tags: hostname=linux7 time cpu mem load disk ---- --- --- ---- ---- 2019-02-02T18:46:00.42366206Z 1 43 0 0

name: custom tags: hostname=linux24 time cpu mem load disk ---- --- --- ---- ---- 2019-02-02T18:46:00.42366206Z 11 34 0 0

name: custom tags: hostname=linux4 time cpu mem load disk ---- --- --- ---- ---- 2019-02-02T18:46:00.42366206Z 11 42 0 0

name: custom tags: hostname=linux3 time cpu mem load disk ---- --- --- ---- ---- 2019-02-02T18:46:00.42366206Z 73 32 1 0

name: custom tags: hostname=linux20 time cpu mem load disk ---- --- --- ---- ---- 2019-02-02T18:46:00.42366206Z 1 41 0 0

name: custom tags: hostname=linux1 time cpu mem load disk ---- --- --- ---- ---- 2019-02-02T18:46:00.42366206Z 36 55 0 0

Answer №1

Avoid using the WHERE condition and instead utilize the LAST() function within InfluxDB selectors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In order to display the new component upon the first click in React, my button requires a double click

I have a project that utilizes the open Trivia API to fetch data. I've completed the development and everything appears to be working well so far. However, there's a bug where upon initially rendering the app, the first time I click the button to ...

What is the best way to add an additional selected option after the page has been loaded?

I'm currently having trouble adding an extra option to a Chosen after the page has loaded completely. It works fine when I add values before the page loads, but once it's fully loaded, I can't seem to add values to the chosen component, as s ...

Adding 7 days to a JavaScript date

Can you spot the bug in this script? I noticed that when I set my clock to 29/04/2011, it displays 36/4/2011 in the week input field! The correct date should actually be 6/5/2011 var d = new Date(); var curr_date = d.getDate(); var tomo_date = d.getDate( ...

Explore the functionality of the Enter key and search button with JavaScript

I have the following code that works perfectly when I click on the search button. However, I would like to know how I can also initiate a search using the enter key. Here is the code snippet: <script> function mySearch() { var text = document.g ...

highlight the selected option in the ng-repeat list of items

Looking for some assistance with a coding problem I'm having. I keep running into an error when trying to make a selected item in an ng-repeat list highlight. The CSS style is only applied on the second click, not the first. Additionally, I need to en ...

Combining two-digit values

As a newcomer to JavaScript, I've been working on creating a basic calculator to practice my skills. However, I've run into an issue. When entering a double-digit number, the calculator is adding the digits together instead of treating them as se ...

Exploring the capabilities of Angular 2 and delving into inquiries regarding IIS

I'm diving into the world of Angular 2 as a beginner. Previously, I used to include JavaScript (like jQuery.js) in my HTML and then upload the finished page to my IIS website. Now that I'm learning Angular 2, I've had to install Node.js, NP ...

Efficiently clear input field values by clicking the remove button

Hey there, I'm currently facing an issue with my WordPress database. I have a file named add_field.php and scripts.js where I dynamically add input fields upon clicking the add more button and save the data into the database. However, I'm struggl ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

Issue with updating patch version using NPM standard-version

I have integrated standard-version into my javascript project. I made sure to include the release script in my package.json: "scripts": { ... "release": "standard-version" } However, after adding a commit with the mes ...

Accessing a PDF document from a local directory through an HTML interface for offline viewing

As I work on developing an offline interface, I'm encountering an issue with displaying a PDF file when clicking on an image. Unfortunately, the code I have in place isn't working as intended. Can someone please assist me with this problem? Below ...

I'm having trouble with my TextGeometry not displaying on screen. Can someone help me figure

Here is the code I am using for Three.js: <html> <head> <title>My first Three.js app</title> <style> body { margin: 0; } canvas { width: 100%; height: 100% } </style> ...

Preventing Event Loop Blocking in Node.js: The Key to Streamlining Performance

I am currently working on developing two APIs using Express.js. The tasks for both APIs are quite straightforward. The first API involves running a for loop from 1 to 3,000,000, while the second API simply prints a string in the console. All the necessary ...

Transferring a JavaScript Value to a PHP Variable (Under Certain Constraints)

Although I have reviewed existing questions and answers related to this issue, I found that the solutions provided do not suit my specific situation. Discussing the differences between client-side JavaScript and server-side PHP, two common solutions are: ...

How can I extract a specific value from an array in a JSON object by sorting it?

As someone who is relatively new to JSON and APIs, I am currently working on a project involving an API that returns values in an array structure. Here is an example of the data: { id: 0, text: "one" } { id: 1, text: "two" } ...

Three.js - Exploring the Significance of "THREE" within the THREE.scene Framework

Just starting out in JavaScript and experimenting with animations using three.js library. I'm trying to grasp the meaning behind: const scene = new THREE.Scene(); Why is the "THREE" necessary in THREE.Scene? Could we not simply write const scene = n ...

What is the process for calling CSS from a separate directory?

I am looking to start building a website. Can someone advise on how to organize html, css, and javascript into separate folders? One folder will house files specifically for writing HTML and JavaScript, while the other folder will be dedicated solely to ...

The functionality of a Jquery ajax call is not operational within the Firefox browser

I have implemented an ajax call in my code $('.updatecom .registercomplaint').click(function(){ updatecomplaints(); }); This initiates the function called updatecomplaints() function updatecomplaints() { var tno = $(".updatecom #tno").val( ...

Use Entity Objects instead of Strings in your Ajax requests for improved data handling

As I work on developing a web portal with Freemarker(FTL) as the front end technology, my project revolves around a single FTL page that utilizes a wizard to manage various user requests. The back end is structured using the Spring MVC pattern, where contr ...

Issue encountered in transmitting information from JSP to servlet

I am facing an issue with receiving data from JSP to servlet. I understand that I need to serialize this data using JSON. In my JSP, I have written the following JavaScript code: var myJSONText = JSON.stringify(items); document.getElementById('test&a ...