Skip to content

Commit

Permalink
Add db.serverStatus
Browse files Browse the repository at this point in the history
Fixes #811.
  • Loading branch information
pluma4345 committed Nov 22, 2024
1 parent 58dfdcc commit 5bfee25
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ This driver uses semantic versioning:

### Added

- Added `database.serverStatus` method ([#811](https://github.com/arangodb/arangojs/issues/811))

This method fetches information about the server status.

- Added `onError` option to `Config` (DE-955)

This option can be used to specify a callback function that will be invoked
Expand Down
177 changes: 177 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,164 @@ export type DatabaseInfo = {
writeConcern?: number;
};

/**
* Information about the server status.
*/
export type ServerStatusInformation = {
/**
* (Cluster Coordinators and DB-Servers only.) The address of the server.
*/
address?: string;
/**
* (Cluster Coordinators and DB-Servers only.) Information about the Agency.
*/
agency?: {
/**
* Information about the communication with the Agency.
*/
agencyComm: {
/**
* A list of possible Agency endpoints.
*/
endpoints: string[];
};
};
/**
* (Cluster Agents only.) Information about the Agents.
*/
agent?: {
/**
* The endpoint of the queried Agent.
*/
endpoint: string;
/**
* Server ID of the queried Agent.
*/
id: string;
/**
* Server ID of the leading Agent.
*/
leaderId: string;
/**
* Whether the queried Agent is the leader.
*/
leading: boolean;
/**
* The current term number.
*/
term: number;
};
/**
* (Cluster Coordinators only.) Information about the Coordinators.
*/
coordinator?: {
/**
* The server ID of the Coordinator that is the Foxx master.
*/
foxxmaster: string[];
/**
* Whether the queried Coordinator is the Foxx master.
*/
isFoxxmaster: boolean[];
};
/**
* Whether the Foxx API is enabled.
*/
foxxApi: boolean;
/**
* A host identifier defined by the HOST or NODE_NAME environment variable,
* or a fallback value using a machine identifier or the cluster/Agency address.
*/
host: string;
/**
* A hostname defined by the HOSTNAME environment variable.
*/
hostname?: string;
/**
* ArangoDB Edition.
*/
license: "community" | "enterprise";
/**
* Server operation mode.
*
* @deprecated use `operationMode` instead
*/
mode: "server" | "console";
/**
* Server operation mode.
*/
operationMode: "server" | "console";
/**
* The process ID of arangod.
*/
pid: number;
/**
* Server type.
*/
server: "arango";
/**
* Information about the server status.
*/
serverInfo: {
/**
* Whether the maintenance mode is enabled.
*/
maintenance: boolean;
/**
* (Cluster only.) The persisted ID.
*/
persistedId?: string;
/**
* Startup and recovery information.
*/
progress: {
/**
* Internal name of the feature that is currently being prepared, started, stopped or unprepared.
*/
feature: string;
/**
* Name of the lifecycle phase the instance is currently in.
*/
phase: string;
/**
* Current recovery sequence number value.
*/
recoveryTick: number;
};
/**
* Whether writes are disabled.
*/
readOnly: boolean;
/**
* (Cluster only.) The reboot ID. Changes on every restart.
*/
rebootId?: number;
/**
* Either "SINGLE", "COORDINATOR", "PRIMARY" (DB-Server), or "AGENT"
*/
role: "SINGLE" | "COORDINATOR" | "PRIMARY" | "AGENT";
/**
* (Cluster Coordinators and DB-Servers only.) The server ID.
*/
serverId?: string;
/**
* (Cluster Coordinators and DB-Servers only.) Either "STARTUP", "SERVING",
* or "SHUTDOWN".
*/
state?: "STARTUP" | "SERVING" | "SHUTDOWN";
/**
* The server version string.
*/
version: string;
/**
* Whether writes are enabled.
*
* @deprecated Use `readOnly` instead.
*/
writeOpsEnabled: boolean;
};
};

/**
* Result of retrieving database version information.
*/
Expand Down Expand Up @@ -1865,6 +2023,25 @@ export class Database {
return this._name;
}

/**
* Fetches information about the server status.
*
* @example
* ```js
* const status = await db.status();
* // the status object contains the ArangoDB status information, e.g.
* // version: ArangoDB version number
* // host: host identifier of the server
* // serverInfo: detailed information about the server
* ```
*/
serverStatus(): Promise<ServerStatusInformation> {
return this.request({
method: "GET",
path: "/_admin/status",
});
}

/**
* Fetches version information from the ArangoDB server.
*
Expand Down

0 comments on commit 5bfee25

Please sign in to comment.