Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configure telemetry #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var Cmd = &cobra.Command{

func init() {
Cmd.AddCommand(serviceCmd)
Cmd.AddCommand(telemetryCmd)
}

const RunningErrorMsg = "algorand is currently running. Please stop the node with *node stop* before configuring"
Expand Down
76 changes: 76 additions & 0 deletions cmd/configure/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package configure

import (
"github.com/algorandfoundation/nodekit/cmd/utils"
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
"github.com/algorandfoundation/nodekit/internal/algod"
"github.com/algorandfoundation/nodekit/internal/system"
"github.com/algorandfoundation/nodekit/ui/style"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)

var dataDir = ""
var telemetryEndpoint string
var telemetryName string

var telemetryShort = "Configure telemetry for the Algorand daemon"
var NodelyTelemetryWarning = "The default telemetry provider is Nodely."
var telemetryLong = lipgloss.JoinVertical(
lipgloss.Left,
style.Purple(style.BANNER),
"",
style.Bold(telemetryShort),
"",
style.BoldUnderline("Overview:"),
"When a node is run using the algod command, before the script starts the server,",
"it configures its telemetry based on the appropriate logging.config file.",
"When a node’s telemetry is enabled, a telemetry state is added to the node’s logger",
"reflecting the fields contained within the appropriate config file",
"",
style.Yellow.Render(NodelyTelemetryWarning),
)

var telemetryCmd = utils.WithAlgodFlags(&cobra.Command{
Use: "telemetry",
Short: telemetryShort,
Long: telemetryLong,
Run: func(cmd *cobra.Command, args []string) {
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))
sudoExists := system.CmdExists("sudo")
if !sudoExists {
log.Fatal("sudo is not installed, ensure it is available on your system in the PATH.")
}
diagExists := system.CmdExists("diagcfg")
if !diagExists {
log.Fatal("diagcfg is not installed, ensure it is available on your system in the PATH.")
}

dataDir, err := algod.GetDataDir(dataDir)

err = system.RunAll(system.CmdsList{
{"sudo", "diagcfg", "-d", dataDir, "telemetry", "endpoint", "-e", telemetryEndpoint},
{"sudo", "diagcfg", "-d", dataDir, "telemetry", "name", "-n", telemetryName},
{"sudo", "diagcfg", "-d", dataDir, "telemetry", "enable"},
})
if err != nil {
log.Fatal(err)
}
log.Debug("Restarting node...")
err = algod.Stop()
if err != nil {
log.Fatal(err)
}
err = algod.Start()
if err != nil {
log.Fatal(err)
}
log.Debug("Node restarted successfully.")
},
}, &dataDir)

func init() {
telemetryCmd.Flags().StringVarP(&telemetryEndpoint, "endpoint", "e", "https://tel.4160.nodely.io", "Sets the \"URI\" property")
telemetryCmd.Flags().StringVarP(&telemetryName, "name", "n", "anon", "Enable Algorand remote logging with specified node name")
}
3 changes: 2 additions & 1 deletion docs/src/content/docs/reference/nodekit_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Note: This is still a work in progress. Expect bugs and rough edges.

* [nodekit](/reference/nodekit) - Manage Algorand nodes from the command line
* [nodekit configure service](/reference/nodekit/configure/service) - Install service files for the Algorand daemon.
* [nodekit configure telemetry](/reference/nodekit/configure/telemetry) - Configure telemetry for the Algorand daemon

###### Auto generated by spf13/cobra on 7-Jan-2025
###### Auto generated by spf13/cobra on 16-Jan-2025
35 changes: 35 additions & 0 deletions docs/src/content/docs/reference/nodekit_configure_telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "nodekit configure telemetry"
slug: "reference/nodekit/configure/telemetry"
---
## Synopsis


Configure telemetry for the Algorand daemon

Overview:
When a node is run using the algod command, before the script starts the server,
it configures its telemetry based on the appropriate logging.config file.
When a node’s telemetry is enabled, a telemetry state is added to the node’s logger
reflecting the fields contained within the appropriate config file

The default telemetry provider is Nodely.

```
nodekit configure telemetry [flags]
```

### Options

```
-d, --datadir string Data directory for the node
-e, --endpoint string Sets the "URI" property (default "https://tel.4160.nodely.io")
-h, --help help for telemetry
-n, --name string Enable Algorand remote logging with specified node name (default "anon")
```

### SEE ALSO

* [nodekit configure](/reference/nodekit/configure) - Change settings on the system (WIP)

###### Auto generated by spf13/cobra on 16-Jan-2025
3 changes: 2 additions & 1 deletion man/nodekit_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ Note: This is still a work in progress. Expect bugs and rough edges.

* [nodekit](/README.md) - Manage Algorand nodes from the command line
* [nodekit configure service](/man/nodekit_configure_service.md) - Install service files for the Algorand daemon.
* [nodekit configure telemetry](/man/nodekit_configure_telemetry.md) - Configure telemetry for the Algorand daemon

###### Auto generated by spf13/cobra on 7-Jan-2025
###### Auto generated by spf13/cobra on 16-Jan-2025
38 changes: 38 additions & 0 deletions man/nodekit_configure_telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## nodekit configure telemetry

Configure telemetry for the Algorand daemon

### Synopsis


<img alt="Terminal Render" src="/assets/nodekit.png" width="65%">


Configure telemetry for the Algorand daemon

Overview:
When a node is run using the algod command, before the script starts the server,
it configures its telemetry based on the appropriate logging.config file.
When a node’s telemetry is enabled, a telemetry state is added to the node’s logger
reflecting the fields contained within the appropriate config file

The default telemetry provider is Nodely.

```
nodekit configure telemetry [flags]
```

### Options

```
-d, --datadir string Data directory for the node
-e, --endpoint string Sets the "URI" property (default "https://tel.4160.nodely.io")
-h, --help help for telemetry
-n, --name string Enable Algorand remote logging with specified node name (default "anon")
```

### SEE ALSO

* [nodekit configure](/man/nodekit_configure.md) - Change settings on the system (WIP)

###### Auto generated by spf13/cobra on 16-Jan-2025
Loading