Skip to content
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
68 changes: 68 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +131,10 @@ type Config struct {
Prometheus bool
Listen string
}

Version struct {
Installed int64
}
}

var (
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions opencast-ca-display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ metrics:
# Enable Prometheus metrics
prometheus: true
listen: 0.0.0.0:9100

version:
# Installation timestamp (unix epoch)
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