Update clairvoyant
This commit is contained in:
parent
e2b1fb58e9
commit
82d81b596e
@ -15,7 +15,9 @@ let package = Package(
|
|||||||
// https://github.com/Joannis/SMTPKitten <- No updates since 0ct 2020
|
// https://github.com/Joannis/SMTPKitten <- No updates since 0ct 2020
|
||||||
// https://github.com/Joannis/VaporSMTPKit <- No updates since 0ct. 2020, uses SMTPKitten
|
// https://github.com/Joannis/VaporSMTPKit <- No updates since 0ct. 2020, uses SMTPKitten
|
||||||
.package(url: "https://github.com/Kitura/Swift-SMTP", from: "6.0.0"),
|
.package(url: "https://github.com/Kitura/Swift-SMTP", from: "6.0.0"),
|
||||||
.package(url: "https://github.com/christophhagen/clairvoyant.git", from: "0.5.0"),
|
.package(url: "https://github.com/christophhagen/Clairvoyant", from: "0.9.0"),
|
||||||
|
.package(url: "https://github.com/christophhagen/ClairvoyantVapor", from: "0.2.0"),
|
||||||
|
.package(url: "https://github.com/christophhagen/ClairvoyantBinaryCodable", from: "0.3.1"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
@ -26,6 +28,8 @@ let package = Package(
|
|||||||
.product(name: "Vapor", package: "vapor"),
|
.product(name: "Vapor", package: "vapor"),
|
||||||
.product(name: "SwiftSMTP", package: "Swift-SMTP"),
|
.product(name: "SwiftSMTP", package: "Swift-SMTP"),
|
||||||
.product(name: "Clairvoyant", package: "Clairvoyant"),
|
.product(name: "Clairvoyant", package: "Clairvoyant"),
|
||||||
|
.product(name: "ClairvoyantVapor", package: "ClairvoyantVapor"),
|
||||||
|
.product(name: "ClairvoyantBinaryCodable", package: "ClairvoyantBinaryCodable"),
|
||||||
],
|
],
|
||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
// Enable better optimizations when building in Release configuration. Despite the use of
|
// Enable better optimizations when building in Release configuration. Despite the use of
|
||||||
|
@ -90,7 +90,7 @@ final class SQLiteDatabase {
|
|||||||
func updateRegisteredPlayerCount(from database: Database) async {
|
func updateRegisteredPlayerCount(from database: Database) async {
|
||||||
do {
|
do {
|
||||||
let count = try await User.query(on: database).count()
|
let count = try await User.query(on: database).count()
|
||||||
try? await registeredPlayerCountMetric.update(count)
|
_ = try? await registeredPlayerCountMetric.update(count)
|
||||||
} catch {
|
} catch {
|
||||||
log("Failed to update player count metric: \(error)")
|
log("Failed to update player count metric: \(error)")
|
||||||
}
|
}
|
||||||
|
@ -65,17 +65,17 @@ final class TableManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func logTableCount() async {
|
private func logTableCount() async {
|
||||||
try? await tableCountMetric.update(tables.count)
|
_ = try? await tableCountMetric.update(tables.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func logPlayingPlayerCount() async {
|
private func logPlayingPlayerCount() async {
|
||||||
let count = tables.values.sum { $0.playerCount }
|
let count = tables.values.sum { $0.playerCount }
|
||||||
try? await playingPlayerCountMetric.update(count)
|
_ = try? await playingPlayerCountMetric.update(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func logConnectedPlayerCount() async {
|
private func logConnectedPlayerCount() async {
|
||||||
let count = tables.values.sum { $0.numberOfConnectedPlayers }
|
let count = tables.values.sum { $0.numberOfConnectedPlayers }
|
||||||
try? await connectedPlayerCountMetric.update(count)
|
_ = try? await connectedPlayerCountMetric.update(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
import Vapor
|
import Vapor
|
||||||
import Fluent
|
import Fluent
|
||||||
import Clairvoyant
|
import Clairvoyant
|
||||||
|
import ClairvoyantBinaryCodable
|
||||||
|
import ClairvoyantVapor
|
||||||
|
|
||||||
var server: SQLiteDatabase!
|
var server: SQLiteDatabase!
|
||||||
|
|
||||||
|
private var provider: VaporMetricProvider! = nil
|
||||||
|
|
||||||
// configures your application
|
// configures your application
|
||||||
public func configure(_ app: Application) async throws {
|
public func configure(_ app: Application) async throws {
|
||||||
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
||||||
|
|
||||||
let logFolder = storageFolder.appendingPathComponent("logs")
|
let logFolder = storageFolder.appendingPathComponent("logs")
|
||||||
let accessManager = AccessTokenManager([])
|
let monitor = MetricObserver(
|
||||||
let monitor = await MetricObserver(
|
logFileFolder: logFolder,
|
||||||
logFolder: logFolder,
|
|
||||||
accessManager: accessManager,
|
|
||||||
logMetricId: "schafkopf.log")
|
logMetricId: "schafkopf.log")
|
||||||
MetricObserver.standard = monitor
|
MetricObserver.standard = monitor
|
||||||
|
|
||||||
@ -21,8 +23,7 @@ public func configure(_ app: Application) async throws {
|
|||||||
name: "Status",
|
name: "Status",
|
||||||
description: "The main status of the server")
|
description: "The main status of the server")
|
||||||
|
|
||||||
try? await status.update(.initializing)
|
_ = try? await status.update(.initializing)
|
||||||
await monitor.registerRoutes(app)
|
|
||||||
|
|
||||||
let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
||||||
.appendingPathComponent("config.json")
|
.appendingPathComponent("config.json")
|
||||||
@ -31,13 +32,12 @@ public func configure(_ app: Application) async throws {
|
|||||||
do {
|
do {
|
||||||
configuration = try Configuration(loadFromUrl: configPath)
|
configuration = try Configuration(loadFromUrl: configPath)
|
||||||
} catch {
|
} catch {
|
||||||
try? await status.update(.initializationFailure)
|
_ = try? await status.update(.initializationFailure)
|
||||||
await monitor.log("Failed to read configuration: \(error)")
|
monitor.log("Failed to read configuration: \(error)")
|
||||||
// Note: If configuration can't be loaded, then the server will run on the wrong port
|
// Note: If configuration can't be loaded, then the server will run on the wrong port
|
||||||
// and access to metrics is impossible, since no tokens are loaded
|
// and access to metrics is impossible, since no tokens are loaded
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configuration.monitoringTokens.map { $0.data(using: .utf8)! }.forEach(accessManager.add)
|
|
||||||
|
|
||||||
app.http.server.configuration.port = configuration.serverPort
|
app.http.server.configuration.port = configuration.serverPort
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ public func configure(_ app: Application) async throws {
|
|||||||
do {
|
do {
|
||||||
try await app.autoMigrate()
|
try await app.autoMigrate()
|
||||||
} catch {
|
} catch {
|
||||||
await monitor.log("Failed to migrate database: \(error)")
|
monitor.log("Failed to migrate database: \(error)")
|
||||||
try? await status.update(.initializationFailure)
|
_ = try? await status.update(.initializationFailure)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,11 @@ public func configure(_ app: Application) async throws {
|
|||||||
// register routes
|
// register routes
|
||||||
routes(app)
|
routes(app)
|
||||||
|
|
||||||
try? await status.update(.nominal)
|
// Expose metrics
|
||||||
|
provider = .init(observer: monitor, accessManager: configuration.monitoringTokens)
|
||||||
|
provider.registerRoutes(app)
|
||||||
|
|
||||||
|
_ = try? await status.update(.nominal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func log(_ message: String) {
|
func log(_ message: String) {
|
||||||
@ -89,7 +93,5 @@ func log(_ message: String) {
|
|||||||
print(message)
|
print(message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Task {
|
observer.log(message)
|
||||||
await observer.log(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user