🚀 Feature: API for external dashboards? #467

Closed
opened 2025-10-09 16:48:38 +03:00 by OVERLORD · 4 comments
Owner

Originally created by @Node815 on GitHub.

Feature description

I use the Homepage dashboard from Benphelps and wondered if there are any plans to add API stats endpoints we can use for data aggregation such as Prometheus?

Pitch

I think for my use, it would be for my homepage which can shows items such as a Succesfull login count, failed login count, number of users etc.. So, at a glance, you can keep on the site to be react for anomalies which can happen, also it's fun to see this data for us data nerds. :)

Originally created by @Node815 on GitHub. ### Feature description I use the Homepage dashboard from [Benphelps](https://github.com/gethomepage/homepage) and wondered if there are any plans to add API stats endpoints we can use for data aggregation such as Prometheus? ### Pitch I think for my use, it would be for my homepage which can shows items such as a Succesfull login count, failed login count, number of users etc.. So, at a glance, you can keep on the site to be react for anomalies which can happen, also it's fun to see this data for us data nerds. :)
OVERLORD added the feature label 2025-10-09 16:48:38 +03:00
Author
Owner

@stonith404 commented on GitHub:

I think this feature is a bit too use case specific. I want to keep Pocket ID as simple as possible.

But you can actually implement this by your own very easily. Inside the the data folder is the Sqlite database of Pocket ID. You can create a simple API with your favourite programming language that queries the Sqlite database. ChatGPT could help you to create this in a few minutes :)

For example for the login count you can just filter the "Audit_Logs" table and for the user count you can just count the rows of the "Users" table. Failed login attempts don't get logged as you can't brute force or try to guess a passkey.

@stonith404 commented on GitHub: I think this feature is a bit too use case specific. I want to keep Pocket ID as simple as possible. But you can actually implement this by your own very easily. Inside the the data folder is the Sqlite database of Pocket ID. You can create a simple API with your favourite programming language that queries the Sqlite database. ChatGPT could help you to create this in a few minutes :) For example for the login count you can just filter the "Audit_Logs" table and for the user count you can just count the rows of the "Users" table. Failed login attempts don't get logged as you can't brute force or try to guess a passkey.
Author
Owner

@stonith404 commented on GitHub:

import express from 'express';
import sqlite3 from 'sqlite3';

// Initialize Express app
const app = express();
const PORT = 3000;

// Path to Pocket ID SQLite database
const dbPath = "./data/pocket-id.db";

// Initialize database connection
const db = new sqlite3.Database(dbPath, (err) => {
    if (err) {
        console.error('Error opening database:', err.message);
    } else {
        console.log('Connected to the Pocket ID SQLite database.');
    }
});


// Function to run query on the database
const runQuery = (query) => {
    return new Promise((resolve, reject) => {
        db.get(query, (err, row) => {
            if (err) {
                console.error(`Error running query: "${query}"`, err.message);
                reject(err);
            } else {
                resolve(row);
            }
        });
    });
};

// Endpoint to get all analytics data
app.get('/', async (req, res) => {
    try {
        const { login_count } = await runQuery("SELECT COUNT(*) AS login_count FROM Audit_Logs WHERE event = 'SIGN_IN'")
        const { user_count } = await runQuery("SELECT COUNT(*) AS user_count FROM Users")

        // Send combined analytics data as a response
        res.json({
            login_count,
            user_count
        });
    } catch (err) {
        res.status(500).json({ error: 'Database error' });
    }
});

// Close database connection on server shutdown
process.on('SIGINT', () => {
    db.close((err) => {
        if (err) {
            console.error('Error closing database:', err.message);
        }
        console.log('Database connection closed.');
        process.exit(0);
    });
});

// Start server
app.listen(PORT, () => {
    console.log(`Server running on http://localhost:${PORT}`);
});

Here is a working example with Node.js :)

@stonith404 commented on GitHub: ```js import express from 'express'; import sqlite3 from 'sqlite3'; // Initialize Express app const app = express(); const PORT = 3000; // Path to Pocket ID SQLite database const dbPath = "./data/pocket-id.db"; // Initialize database connection const db = new sqlite3.Database(dbPath, (err) => { if (err) { console.error('Error opening database:', err.message); } else { console.log('Connected to the Pocket ID SQLite database.'); } }); // Function to run query on the database const runQuery = (query) => { return new Promise((resolve, reject) => { db.get(query, (err, row) => { if (err) { console.error(`Error running query: "${query}"`, err.message); reject(err); } else { resolve(row); } }); }); }; // Endpoint to get all analytics data app.get('/', async (req, res) => { try { const { login_count } = await runQuery("SELECT COUNT(*) AS login_count FROM Audit_Logs WHERE event = 'SIGN_IN'") const { user_count } = await runQuery("SELECT COUNT(*) AS user_count FROM Users") // Send combined analytics data as a response res.json({ login_count, user_count }); } catch (err) { res.status(500).json({ error: 'Database error' }); } }); // Close database connection on server shutdown process.on('SIGINT', () => { db.close((err) => { if (err) { console.error('Error closing database:', err.message); } console.log('Database connection closed.'); process.exit(0); }); }); // Start server app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); }); ``` Here is a working example with Node.js :)
Author
Owner

@simono41 commented on GitHub:

Fair Enough, the idea came to me as I was removing one app from Homepage and replaced yours with it. (Authentik) I will see what I can do through GPT. But not sure how well it will work. Feel free to close this.

@stonith404 @Node815

I once rewritten your codes from the template and from AI the code to GO to use the data from Pocket-ID in my Grafana Prometheus environment.

https://code.brothertec.eu/simono41/pocket-id-exporter

@simono41 commented on GitHub: > Fair Enough, the idea came to me as I was removing one app from Homepage and replaced yours with it. (Authentik) I will see what I can do through GPT. But not sure how well it will work. Feel free to close this. @stonith404 @Node815 I once rewritten your codes from the template and from AI the code to GO to use the data from Pocket-ID in my Grafana Prometheus environment. https://code.brothertec.eu/simono41/pocket-id-exporter
Author
Owner

@Node815 commented on GitHub:

Fair Enough, the idea came to me as I was removing one app from Homepage and replaced yours with it. (Authentik) I will see what I can do through GPT. But not sure how well it will work. Feel free to close this.

@Node815 commented on GitHub: Fair Enough, the idea came to me as I was removing one app from Homepage and replaced yours with it. (Authentik) I will see what I can do through GPT. But not sure how well it will work. Feel free to close this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id-pocket-id-2#467