diff --git a/README.md b/README.md index 417df8b..eaf05ec 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,11 @@ Next, go to the Opencast REST Docs → `/user-utils` and fill out the form for - roles: `["ROLE_CAPTURE_AGENT_CALENDAR"]` You should now be able to use this new user. + +## Creating a Release + +Creating a new release now involves multiple steps: + +1. Decide type of release => releases are named in the following form `v(majorVersion).(minorVersion).(patchVersion)`. +2. Set the new release number in the `main.go` file (variables named accordingly in lines 41-43). +3. Create the new release. \ No newline at end of file diff --git a/main.go b/main.go index 604a63f..b49a01a 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,12 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) +const ( + majorVersion = 0 + minorVersion = 1 + patchVersion = 3 +) + type AgentStateResult struct { Update struct { Name string @@ -125,6 +131,10 @@ type Config struct { Prometheus bool Listen string } + + Version struct { + Installed int64 + } } var ( @@ -152,6 +162,16 @@ func (c *myCollector) Collect(ch chan<- prometheus.Metric) { ch <- s } +type constCollector struct { + desc *prometheus.Desc + value float64 +} + +func (c constCollector) Describe(ch chan<- *prometheus.Desc) { ch <- c.desc } +func (c constCollector) Collect(ch chan<- prometheus.Metric) { + ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, c.value) +} + var ( timeCollector = &myCollector{ metric: prometheus.NewDesc( @@ -170,6 +190,45 @@ var ( }, []string{"state"}) ) +var ( + versionCollectorMajor = constCollector{ + desc: prometheus.NewDesc( + "version_info_major", + "Major Version number", + nil, + nil, + ), + value: float64(majorVersion), + } + + versionCollectorMinor = constCollector{ + desc: prometheus.NewDesc( + "version_info_minor", + "Minor Version number", + nil, + nil, + ), + value: float64(minorVersion), + } + + versionCollectorPatch = constCollector{ + desc: prometheus.NewDesc( + "version_info_patch", + "Patch Version number", + nil, + nil, + ), + value: float64(patchVersion), + } +) + +var ( + 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) @@ -201,6 +260,11 @@ func loadConfig(configPath string) (*Config, error) { config.Timeout = 500 } + // Set installed timestamp metric + if config.Version.Installed > 0 { + installedCollector.Set(float64(config.Version.Installed)) + } + return &config, nil } @@ -396,6 +460,10 @@ func setupRouter() *gin.Engine { func init() { prometheus.MustRegister(stateCollector) prometheus.MustRegister(timeCollector) + prometheus.MustRegister(versionCollectorMajor) + prometheus.MustRegister(versionCollectorMinor) + prometheus.MustRegister(versionCollectorPatch) + prometheus.MustRegister(installedCollector) } func setupMetricsRouter() *gin.Engine { diff --git a/opencast-ca-display.yml b/opencast-ca-display.yml index 62f1595..542826c 100644 --- a/opencast-ca-display.yml +++ b/opencast-ca-display.yml @@ -128,3 +128,7 @@ metrics: # Enable Prometheus metrics prometheus: true listen: 0.0.0.0:9100 + +version: + # Installation timestamp (unix epoch) + installed: 1767962682