Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ type Config struct {
Prometheus bool
Listen string
}

Version struct {
Version string
Installed int64
}
}

var (
Expand Down Expand Up @@ -170,6 +175,20 @@ var (
}, []string{"state"})
)

var (
versionCollector = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "version_info",
Help: "Version information of the software",
}, []string{"version"})

installedCollector = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "installed_timestamp",
Help: "Timestamp when the software was installed",
})
)



func loadConfig(configPath string) (*Config, error) {
// Open config file
yamlFile, err := os.ReadFile(configPath)
Expand Down Expand Up @@ -201,6 +220,18 @@ func loadConfig(configPath string) (*Config, error) {
config.Timeout = 500
}

if config.Version.Version == "" {
config.Version.Version = "unknown"
}

// Set version metric
versionCollector.WithLabelValues(config.Version.Version).Set(1)

// Set installed timestamp metric
if config.Version.Installed > 0 {
installedCollector.Set(float64(config.Version.Installed))
}

return &config, nil
}

Expand Down Expand Up @@ -396,6 +427,8 @@ func setupRouter() *gin.Engine {
func init() {
prometheus.MustRegister(stateCollector)
prometheus.MustRegister(timeCollector)
prometheus.MustRegister(versionCollector)
prometheus.MustRegister(installedCollector)
}

func setupMetricsRouter() *gin.Engine {
Expand Down
6 changes: 6 additions & 0 deletions opencast-ca-display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@ metrics:
# Enable Prometheus metrics
prometheus: true
listen: 0.0.0.0:9100

version:
# Application version
version: 0.1.13
# Installation timestamp (unix epoch). If left blank, it will be set on first run
installed: 1767962682
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn´t this be left blank then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the configuration file isn´t being modified on the displays themselves, the comment was wrong. I planned on doing it but thought that it wouldn´t be the best option. Now 0 is shown if no installation date is provided

Loading