-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8b1054
commit 0c3dd2c
Showing
11 changed files
with
441 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package exporter | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type DataSource struct { | ||
Name string | ||
VpnFilter string | ||
ItemFilter string | ||
Name string | ||
VpnFilter string | ||
ItemFilter string | ||
MetricFilter []string | ||
} | ||
|
||
func (dataSource DataSource) String() string { | ||
return fmt.Sprintf("%s=%s|%s", dataSource.Name, dataSource.VpnFilter, dataSource.ItemFilter) | ||
return fmt.Sprintf("%s=%s|%s|%s", dataSource.Name, dataSource.VpnFilter, dataSource.ItemFilter, strings.Join(dataSource.MetricFilter, ",")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package semp | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"strings" | ||
) | ||
|
||
// Get rates for each individual queue of all vpn's | ||
// This can result in heavy system load for lots of queues | ||
func (e *Semp) GetQueueStatsSemp2(ch chan<- prometheus.Metric, vpnName string, itemFilter string, metricFilter []string) (ok float64, err error) { | ||
type Response struct { | ||
Queue []struct { | ||
QueueName string `json:"queueName"` | ||
MsgVpnName string `json:""` | ||
TotalByteSpooled float64 `json:"spooledByteCount"` | ||
TotalMsgSpooled float64 `json:"spooledMsgCount"` | ||
MsgRedelivered float64 `json:"redeliveredMsgCount"` | ||
MsgRetransmit float64 `json:"transportRetransmitMsgCount"` | ||
SpoolUsageExceeded float64 `json:"maxMsgSpoolUsageExceededDiscardedMsgCount"` | ||
MsgSizeExceeded float64 `json:"maxMsgSizeExceededDiscardedMsgCount"` | ||
SpoolShutdownDiscard float64 `json:"disabledDiscardedMsgCount"` | ||
DestinationGroupError float64 `json:"destinationGroupErrorDiscardedMsgCount"` | ||
LowPrioMsgDiscard float64 `json:"lowPriorityMsgCongestionDiscardedMsgCount"` | ||
Deleted float64 `json:"deletedMsgCount"` | ||
TtlDiscarded float64 `json:"maxTtlExpiredDiscardedMsgCount"` | ||
TtlDmq float64 `json:"maxTtlExpiredToDmqMsgCount"` | ||
TtlDmqFailed float64 `json:"maxTtlExpiredToDmqFailedMsgCount"` | ||
MaxRedeliveryDiscarded float64 `json:"maxRedeliveryExceededDiscardedMsgCount"` | ||
MaxRedeliveryDmq float64 `json:"maxRedeliveryExceededToDmqMsgCount"` | ||
MaxRedeliveryDmqFailed float64 `json:"maxRedeliveryExceededToDmqFailedMsgCount"` | ||
TxUnackedMsg float64 `json:"txUnackedMsgCount"` | ||
TransactionNotSupportedDiscardedMsg float64 `json:"xaTransactionNotSupportedDiscardedMsgCount"` | ||
} `json:"data"` | ||
Meta struct { | ||
Count int64 `json:"count"` | ||
ResponseCode int `json:"responseCode"` | ||
Paging struct { | ||
CursorQuery string `json:"cursorQuery"` | ||
NextPageUri string `json:"nextPageUri"` | ||
} `json:",paging"` | ||
Error struct { | ||
Code int `json:"code"` | ||
Description string `json:"description"` | ||
Status string `json:"status"` | ||
} `json:",error"` | ||
} `json:"meta"` | ||
} | ||
|
||
var getParameter = "count=100" | ||
if len(strings.TrimSpace(itemFilter)) > 0 && itemFilter != "*" { | ||
if strings.Contains(itemFilter, "=") { | ||
getParameter += "&where=" + itemFilter | ||
} else { | ||
getParameter += "&where=queueName==" + itemFilter | ||
} | ||
} | ||
|
||
var fieldsToSelect []string | ||
if len(metricFilter) > 0 { | ||
fieldsToSelect, err = getSempV2FieldsToSelect( | ||
metricFilter, | ||
[]string{"queueName", "msgVpnName"}, | ||
QueueStatsSempV2, | ||
) | ||
|
||
if err != nil { | ||
_ = level.Error(e.logger).Log("msg", "Unable to map metric filter", "err", err, "broker", e.brokerURI) | ||
return 0, err | ||
} | ||
getParameter += "&select=" + strings.Join(fieldsToSelect, ",") | ||
} | ||
|
||
var lastQueueName = "" | ||
for nextUrl := e.brokerURI + "/SEMP/v2/monitor/msgVpns/" + vpnName + "/queues?" + getParameter; nextUrl != ""; { | ||
body, err := e.getHTTPbytes(nextUrl, "application/json ") | ||
if err != nil { | ||
_ = level.Error(e.logger).Log("msg", "Can't scrape QueueStatsSemp2", "command", nextUrl, "err", err, "broker", e.brokerURI) | ||
return 0, err | ||
} | ||
|
||
var response Response | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
_ = level.Error(e.logger).Log("msg", "Can't decode QueueStatsSemp2", "err", err, "broker", e.brokerURI) | ||
return 0, err | ||
} | ||
if response.Meta.ResponseCode != 200 { | ||
_ = level.Error(e.logger).Log("msg", "unexpected result", "command", nextUrl, "remoteError", response.Meta.Error.Description, "broker", e.brokerURI) | ||
return 0, errors.New("unexpected result: see log") | ||
} | ||
|
||
//fmt.Printf("Next request: %v\n", response.Meta.Paging.NextPageUri) | ||
nextUrl = response.Meta.Paging.NextPageUri | ||
for _, queue := range response.Queue { | ||
queueKey := queue.MsgVpnName + "___" + queue.QueueName | ||
if queueKey == lastQueueName { | ||
continue | ||
} | ||
lastQueueName = queueKey | ||
|
||
var values = []SempV2Result{ | ||
{v2Desc: QueueStatsSempV2["total_bytes_spooled"], value: queue.TotalByteSpooled}, | ||
{v2Desc: QueueStatsSempV2["messages_redelivered"], value: queue.MsgRedelivered}, | ||
{v2Desc: QueueStatsSempV2["messages_transport_retransmited"], value: queue.MsgRetransmit}, | ||
{v2Desc: QueueStatsSempV2["spool_usage_exceeded"], value: queue.SpoolUsageExceeded}, | ||
{v2Desc: QueueStatsSempV2["max_message_size_exceeded"], value: queue.MsgSizeExceeded}, | ||
{v2Desc: QueueStatsSempV2["total_deleted_messages"], value: queue.Deleted}, | ||
{v2Desc: QueueStatsSempV2["messages_shutdown_discarded"], value: queue.SpoolShutdownDiscard}, | ||
{v2Desc: QueueStatsSempV2["messages_ttl_discarded"], value: queue.TtlDiscarded}, | ||
{v2Desc: QueueStatsSempV2["messages_ttl_dmq"], value: queue.TtlDmq}, | ||
{v2Desc: QueueStatsSempV2["messages_ttl_dmq_failed"], value: queue.TtlDmqFailed}, | ||
{v2Desc: QueueStatsSempV2["messages_max_redelivered_discarded"], value: queue.MaxRedeliveryDiscarded}, | ||
{v2Desc: QueueStatsSempV2["messages_max_redelivered_dmq"], value: queue.MaxRedeliveryDmq}, | ||
{v2Desc: QueueStatsSempV2["messages_max_redelivered_dmq_failed"], value: queue.MaxRedeliveryDmqFailed}, | ||
} | ||
|
||
for _, v := range values { | ||
if v.v2Desc.isSelected(fieldsToSelect) { | ||
ch <- prometheus.MustNewConstMetric(v.v2Desc.NewPrometheusDesc(), prometheus.GaugeValue, v.value, queue.MsgVpnName, queue.QueueName) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 1, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package semp | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func mapItems(items []string, translateMap map[string]string) ([]string, error) { | ||
validRawItems := make(map[string]bool, len(translateMap)) | ||
translated := make([]string, 0, len(items)) | ||
validItems := make([]string, 0, len(translateMap)*2) | ||
|
||
for key, validRawItem := range translateMap { | ||
validRawItems[validRawItem] = true | ||
|
||
validItems = append(validItems, key) | ||
validItems = append(validItems, validRawItem) | ||
} | ||
|
||
for _, item := range items { | ||
if translatedItem, ok := translateMap[item]; ok { | ||
translated = append(translated, translatedItem) | ||
} else if _, ok := validRawItems[item]; ok { | ||
translated = append(translated, item) | ||
} else { | ||
return nil, fmt.Errorf( | ||
"Item \"%s\" is not valid. Pleaee choose from: %s", | ||
item, | ||
strings.Join(validItems, ","), | ||
) | ||
} | ||
} | ||
|
||
return translated, nil | ||
} | ||
|
||
func sliceContains(slice []string, lookUp string) bool { | ||
for _, selectedField := range slice { | ||
if selectedField == lookUp { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.