Skip to content

Commit

Permalink
Merge pull request #10 from t-huebner/feature/AddVersionInfoToResult
Browse files Browse the repository at this point in the history
Add version info to metrics
  • Loading branch information
mkopinsky authored Feb 9, 2023
2 parents 2cead5a + da96919 commit fca3421
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ services:
```
## Exported Metrics
| Metric | Description | Labels |
| ------ | ------- | ------ |
| mirth_up | Was the last Mirth CLI query successful | |
| mirth_request_duration | Histogram for the runtime of the metric pull from Mirth | |
| mirth_channel_status | Status of all deployed channels | channel, status |
| mirth_messages_received_total | How many messages have been received | channel |
| mirth_messages_filtered_total | How many messages have been filtered | channel |
| mirth_messages_queued | How many messages are currently queued | channel |
| mirth_messages_sent_total | How many messages have been sent | channel |
| mirth_messages_errored_total | How many messages have errored | channel |
| mirth_undeployed_revisions | How many channel revisions have not been deployed | channel |
| Metric | Description | Labels |
|-------------------------------|---------------------------------------------------------|-----------------|
| mirth_up | Was the last Mirth CLI query successful | |
| mirth_info | Version information | version |
| mirth_request_duration | Histogram for the runtime of the metric pull from Mirth | |
| mirth_channel_status | Status of all deployed channels | channel, status |
| mirth_messages_received_total | How many messages have been received | channel |
| mirth_messages_filtered_total | How many messages have been filtered | channel |
| mirth_messages_queued | How many messages are currently queued | channel |
| mirth_messages_sent_total | How many messages have been sent | channel |
| mirth_messages_errored_total | How many messages have errored | channel |
| mirth_undeployed_revisions | How many channel revisions have not been deployed | channel |
```
# HELP mirth_channel_status
Expand Down Expand Up @@ -81,6 +82,10 @@ mirth_messages_sent_total{channel="bar"} 964
# TYPE mirth_up gauge
mirth_up 1

# HELP mirth_info Version information about this Mirth instance.
# TYPE mirth_info gauge
mirth_info{version="3.8.1"} 1

# HELP mirth_undeployed_revisions channel.DeployedRevisionDelta of all deployed channels
# TYPE mirth_undeployed_revisions gauge
mirth_undeployed_revisions{channel="foo"} 13
Expand Down
39 changes: 39 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

const namespace = "mirth"
const channelStatusesApi = "/api/channels/statuses"
const versionApi = "/api/server/version"

var (
tr = &http.Transport{
Expand Down Expand Up @@ -72,6 +73,11 @@ var (
Help: "Histogram for the runtime of the metric pull from Mirth.",
Buckets: prometheus.LinearBuckets(0.1, 0.1, 20),
})

mirthVersion = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "info"),
"Version information about this Mirth instance.", []string{"version"}, nil,
)
)

func (e *Exporter) LoadChannelStatuses() (*ChannelStatusMap, error) {
Expand Down Expand Up @@ -109,6 +115,33 @@ func (e *Exporter) LoadChannelStatuses() (*ChannelStatusMap, error) {
return &channelStatusMap, nil
}

func (e *Exporter) GetMirthVersion() string {
timer := prometheus.NewTimer(requestDuration)
defer timer.ObserveDuration()
req, err := http.NewRequest("GET", e.mirthEndpoint+versionApi, nil)
const errorString = "error"
if err != nil {
return errorString
}

req.Header.Add("X-Requested-With", "mirth_channel_exporter")
// This one line implements the authentication required for the task.
req.SetBasicAuth(e.mirthUsername, e.mirthPassword)
// Make request and show output.
resp, err := client.Do(req)
if err != nil {
return errorString
}

body, err := ioutil.ReadAll(resp.Body)
var result string = string(body)
resp.Body.Close()
if err != nil {
return errorString
}
return result
}

func pickMetric(status string) *prometheus.Desc {
switch status {
case "RECEIVED":
Expand Down Expand Up @@ -186,4 +219,10 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
)

e.AssembleMetrics(channelIdStatusMap, ch)

versionString := e.GetMirthVersion()
ch <- prometheus.MustNewConstMetric(
mirthVersion, prometheus.GaugeValue, 1, versionString,
)

}

0 comments on commit fca3421

Please sign in to comment.