diff --git a/README.md b/README.md index d43b845..2ab00b0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/metrics.go b/metrics.go index e66d422..be9ec92 100644 --- a/metrics.go +++ b/metrics.go @@ -11,6 +11,7 @@ import ( const namespace = "mirth" const channelStatusesApi = "/api/channels/statuses" +const versionApi = "/api/server/version" var ( tr = &http.Transport{ @@ -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) { @@ -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": @@ -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, + ) + }