Skip to content

Commit

Permalink
chore: Add hostname to server monitor report
Browse files Browse the repository at this point in the history
This commit adds the hostname field to the server monitor report in order to include the hostname of the server in the collected metrics. This information is useful for identifying and distinguishing between different servers in the monitoring system.
  • Loading branch information
simlarsen committed Jul 2, 2024
1 parent 5f9a109 commit 0de8e2d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
38 changes: 30 additions & 8 deletions InfrastructureAgent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

The OneUptime Infrastructure Agent is a lightweight, open-source agent that collects system metrics and sends them to the OneUptime platform. It is designed to be easy to install and use, and to be extensible.

## Installation
### Installation

```
curl -s https://oneuptime.com/docs/static/scripts/infrastructure-agent/install.sh | bash
```

## Configure the agent
### Configure the agent

Configure the agent as a system service
- You can change the host to your own host if you're self hosting the OneUptime platform.
Expand All @@ -18,34 +18,56 @@ Configure the agent as a system service
oneuptime-infrastructure-agent configure --secret-key=YOUR_SECRET_KEY --oneuptime-url=https://oneuptime.com
```

## Starting the agent
### Starting the agent

```
oneuptime-infrastructure-agent start
```

Once its up and running you should see the metrics on the OneUptime Dashboard.

## Stopping the agent
### Stopping the agent

```
oneuptime-infrastructure-agent stop
```

## Restarting the agent
### Restarting the agent

```
oneuptime-infrastructure-agent restart
```

## Uninstalling the agent
### Uninstalling the agent

```
oneuptime-infrastructure-agent uninstall && rm -rf /usr/bin/oneuptime-infrastructure-agent
```

## Supported Platforms
### Supported Platforms

- Linux
- MacOS
- Windows
- Windows

## Development

This section is for developers who want to contribute to the agent. The agent is written in Go.

### Building the agent

```bash
go build
```

### Configure the agent

```bash
sudo ./oneuptime-infrastructure-agent configure --secret-key=YOUR_SECRET_KEY --oneuptime-url=https://localhost
```

### Starting the agent

```bash
sudo ./oneuptime-infrastructure-agent start
```
1 change: 1 addition & 0 deletions InfrastructureAgent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func collectMetricsJob(secretKey string, oneuptimeURL string) {
RequestReceivedAt: time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
OnlyCheckRequestReceivedAt: false,
Processes: servProcesses,
Hostname: utils.GetHostname(),
}

reqData := struct {
Expand Down
1 change: 1 addition & 0 deletions InfrastructureAgent/model/server_monitor_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type ServerMonitorReport struct {
RequestReceivedAt string `json:"requestReceivedAt"`
OnlyCheckRequestReceivedAt bool `json:"onlyCheckRequestReceivedAt"`
Processes []*ServerProcess `json:"processes"`
Hostname string `json:"hostname"`
}
16 changes: 16 additions & 0 deletions InfrastructureAgent/utils/hostname.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package utils

import (
"log/slog"
"os"
)

func GetHostname() string {
hostname, err := os.Hostname()
if err != nil {
slog.Error("Failed to fetch hostname", err)
return ""
}

return hostname
}

0 comments on commit 0de8e2d

Please sign in to comment.