System online LogHive Insight

Ensuring System Availability: How to use LogHive Insights to check system online state in Swift

As a provider of a own software solution, it’s important to ensure that your system is always online and available to your users. One way to do this is by periodically sending a “keep alive” signal to a server to monitor its online status. With LogHive Insights, you can easily set up this check and view the state of your system on a dashboard.

Set up the keep alive signal in Swift

First, you’ll need to set up a keep alive signal that sends a request to your server at regular intervals. This signal can be as simple as a small HTTP request that pings the server and checks if it’s up and running.

Here’s an example of how you could implement this in Swift:

Simply send an Insight with the value 0 or 1 to LogHive.

Code example for Swift

let url = URL(string: "https://api.loghive.app/v1/insight/add")!

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("YourPersonalApiKey", forHTTPHeaderField: "ApiKey")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

let json: [String: Any] = [
    "project": "MySaas",
    "insight": "system1-online",
    "value": 1
]

let jsonData = try! JSONSerialization.data(withJSONObject: json, options: [])

request.httpBody = jsonData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        print("Error: \(error)")
        return
    }

    guard let response = response as? HTTPURLResponse,
        (200...299).contains(response.statusCode) else {
            print("Server error")
            return
    }

    if let data = data,
        let jsonString = String(data: data, encoding: .utf8) {
        print("Response: \(jsonString)")
    }
}

task.resume()

You will receive the project and group name, as well as the ApiKey, in the following step when you create an account.

Check out code examples in other programming languages.: https://docs.loghive.app/code-examples/python

Set up a LogHive Account

Sign up for LogHive and create a free account. Navigate to the webapp at https://app.loghive.app/.

You can find your API key in your user profile.

Set up the the dashboard

Once you have the keep alive signal set up, you’ll need to create a dashboard in LogHive Insights to view the state of your system. To do this, log in to the LogHive web application.

Next, you’ll need to add a widget to the dashboard that displays the online state of your system.

LogHive has its own element type for this purpose where you can directly parameterize the Keep Alive signal

Now that you have the keep alive signal and dashboard set up, you can monitor the state of your system . If the server fails to respond to the keep alive signal, you’ll be notified in the LogHive dashboard, allowing you to quickly address any issues that may arise.

System Online State per Insight Event

In conclusion, monitoring the online state of your system is an important task that can be easily accomplished using LogHive Insights. By setting up a keep alive signal and monitoring it on the LogHive dashboard, you can ensure that your system is always online and available to your users.

Latest Posts