Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heartbeatList different on page load #4035

Open
2 tasks done
stephenpapierski opened this issue Nov 15, 2023 · 3 comments · May be fixed by #4005
Open
2 tasks done

heartbeatList different on page load #4035

stephenpapierski opened this issue Nov 15, 2023 · 3 comments · May be fixed by #4005
Labels
area:core issues describing changes to the core of uptime kuma area:monitor Everything related to monitors bug Something isn't working

Comments

@stephenpapierski
Copy link

⚠️ Please verify that this bug has NOT been raised before.

  • I checked and didn't find similar issue

🛡️ Security Policy

📝 Describe your problem

If I log the last item in this.$root.heartbeatList, I get something different when the page loads versus every time after when a new heartbeat happens. It seems that the first one is just a raw dump of the database entries, whereas subsequent heartbeats appear to have called toJSON().

As an example, I added a console.log() to chartData() in PingChart.vue (see below).

     chartData() {
            let pingData = [];  // Ping Data for Line Chart, y-axis contains ping time
            let downData = [];  // Down Data for Bar Chart, y-axis is 1 if target is down (red color), under maintenance (blue color) or pending (orange color), 0 if target is up
            let colorData = []; // Color Data for Bar Chart

            let heartbeatList = this.heartbeatList ||
             (this.monitorId in this.$root.heartbeatList && this.$root.heartbeatList[this.monitorId]) ||
             [];

            console.log(heartbeatList.at(-1); // This is the added line

The result on page load is...

down_count: 0
duration: 0
end_time: "2023-11-15 04:04:35.634"
id: 50
important: 0
monitor_id: 1
msg: "200 - OK"
ping: 244
status: 1
time: "2023-11-15 04:04:35.367"

But after the next heartbeat...

important: false
monitorID: 1
msg: "200 - OK"
ping: 262
status: 1
time: "2023-11-15 04:04:55.368"

This doesn't end up causing any issues for single word variable names, but does cause issues if you're trying to access variables like monitorID instead of monitor_id. I'm running into this issue while trying to add some slow response monitoring information to the GUI. As an example, I added a ping_threshold to the database, but the toJSON() returns pingThreshold. I can get around the first one being different with the code below, but it feels a little hacky. Seems to me like something is going wrong with the first call, but I'm having trouble tracking it down. Any ideas? Or am I going about this incorrectly?

            let lastBeat = heartbeatList.at(-1);
            // TODO: Simplify? When page loads, lastBeat contains ping_threshold,
            // but after the following heartbeat it has pingThreshold.
            if (lastBeat?.hasOwnProperty("pingThreshold")) {
                return lastBeat.pingThreshold;
            } else if (lastBeat?.hasOwnProperty("ping_threshold")) {
                return lastBeat.ping_threshold;
            } else {
                return undefined;
            }

📝 Error Message(s) or Log

No response

🐻 Uptime-Kuma Version

1.23.4

💻 Operating System and Arch

Linux Mint 21.2

🌐 Browser

Google Chrome 119.0.6045.105

🐋 Docker Version

No response

🟩 NodeJS Version

18.18.2

@stephenpapierski
Copy link
Author

It seems like the function sending the most recent 100 heartbeats in the "wrong" format is sendHeartbeatList() in server/client.js.

@stephenpapierski
Copy link
Author

stephenpapierski commented Nov 15, 2023

This did the trick.

async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
    let list = await R.getAll(`
        SELECT * FROM heartbeat
        WHERE monitor_id = ?
        ORDER BY time DESC
        LIMIT 100
    `, [
        monitorID,
    ]);

-    let result = list.reverse();
+    let result = R.convertToBeans("heartbeat", list.reverse());

    if (toUser) {
        io.to(socket.userID).emit("heartbeatList", monitorID, result, overwrite);
    } else {
        socket.emit("heartbeatList", monitorID, result, overwrite);
    }
}

Copy link

We are clearing up our old help-issues and your issue has been open for 60 days with no activity.
If no comment is made and the stale label is not removed, this issue will be closed in 7 days.

@github-actions github-actions bot added the Stale label Feb 14, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
@chakflying chakflying added bug Something isn't working area:monitor Everything related to monitors area:core issues describing changes to the core of uptime kuma and removed help Stale labels Feb 21, 2024
@chakflying chakflying reopened this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core issues describing changes to the core of uptime kuma area:monitor Everything related to monitors bug Something isn't working
Projects
None yet
2 participants