mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-09 09:19:31 +02:00
More variable renaming
This commit is contained in:
parent
01b0317348
commit
9e478ba458
3 changed files with 45 additions and 45 deletions
|
@ -239,7 +239,7 @@ private:
|
||||||
DomainServerExporter _exporter;
|
DomainServerExporter _exporter;
|
||||||
|
|
||||||
HTTPManager _httpManager;
|
HTTPManager _httpManager;
|
||||||
HTTPManager *_httpExporterManager { nullptr };
|
HTTPManager* _httpExporterManager { nullptr };
|
||||||
std::unique_ptr<HTTPSManager> _httpsManager;
|
std::unique_ptr<HTTPSManager> _httpsManager;
|
||||||
|
|
||||||
QHash<QUuid, SharedAssignmentPointer> _allAssignments;
|
QHash<QUuid, SharedAssignmentPointer> _allAssignments;
|
||||||
|
|
|
@ -280,9 +280,9 @@ bool DomainServerExporter::handleHTTPRequest(HTTPConnection* connection, const Q
|
||||||
if (url.path() == URI_METRICS) {
|
if (url.path() == URI_METRICS) {
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
QString output = "";
|
QString output = "";
|
||||||
QTextStream out_stream(&output);
|
QTextStream outStream(&output);
|
||||||
|
|
||||||
nodeList->eachNode([this, &out_stream](const SharedNodePointer& node) { generateMetricsForNode(out_stream, node); });
|
nodeList->eachNode([this, &outStream](const SharedNodePointer& node) { generateMetricsForNode(outStream, node); });
|
||||||
|
|
||||||
connection->respond(HTTPConnection::StatusCode200, output.toUtf8(), qPrintable(EXPORTER_MIME_TYPE));
|
connection->respond(HTTPConnection::StatusCode200, output.toUtf8(), qPrintable(EXPORTER_MIME_TYPE));
|
||||||
return true;
|
return true;
|
||||||
|
@ -292,7 +292,7 @@ bool DomainServerExporter::handleHTTPRequest(HTTPConnection* connection, const Q
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DomainServerExporter::escapeName(const QString& name) {
|
QString DomainServerExporter::escapeName(const QString& name) {
|
||||||
QRegularExpression invalid_characters("[^A-Za-z0-9_]");
|
QRegularExpression invalidCharacters("[^A-Za-z0-9_]");
|
||||||
|
|
||||||
QString ret = name;
|
QString ret = name;
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ QString DomainServerExporter::escapeName(const QString& name) {
|
||||||
ret.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
|
ret.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
|
||||||
|
|
||||||
// Replace all invalid characters with a _
|
// Replace all invalid characters with a _
|
||||||
ret.replace(invalid_characters, "_");
|
ret.replace(invalidCharacters, "_");
|
||||||
|
|
||||||
// Remove any "_" characters at the beginning or end
|
// Remove any "_" characters at the beginning or end
|
||||||
ret.replace(QRegularExpression("^_+"), "");
|
ret.replace(QRegularExpression("^_+"), "");
|
||||||
|
@ -328,69 +328,69 @@ QString DomainServerExporter::escapeName(const QString& name) {
|
||||||
void DomainServerExporter::generateMetricsForNode(QTextStream& stream, const SharedNodePointer& node) {
|
void DomainServerExporter::generateMetricsForNode(QTextStream& stream, const SharedNodePointer& node) {
|
||||||
QString ret = "";
|
QString ret = "";
|
||||||
QJsonObject statsObject = static_cast<DomainServerNodeData*>(node->getLinkedData())->getStatsJSONObject();
|
QJsonObject statsObject = static_cast<DomainServerNodeData*>(node->getLinkedData())->getStatsJSONObject();
|
||||||
QString node_type = NodeType::getNodeTypeName(static_cast<NodeType_t>(node->getType()));
|
QString nodeType = NodeType::getNodeTypeName(static_cast<NodeType_t>(node->getType()));
|
||||||
|
|
||||||
stream << "\n\n\n";
|
stream << "\n\n\n";
|
||||||
stream << "###############################################################\n";
|
stream << "###############################################################\n";
|
||||||
stream << "# " << node_type << "\n";
|
stream << "# " << nodeType << "\n";
|
||||||
stream << "###############################################################\n";
|
stream << "###############################################################\n";
|
||||||
|
|
||||||
generateMetricsFromJson(stream, node_type, escapeName(node_type), QHash<QString, QString>(), statsObject);
|
generateMetricsFromJson(stream, nodeType, escapeName(nodeType), QHash<QString, QString>(), statsObject);
|
||||||
|
|
||||||
QJsonDocument doc(statsObject);
|
QJsonDocument doc(statsObject);
|
||||||
ret.append(doc.toJson());
|
ret.append(doc.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServerExporter::generateMetricsFromJson(QTextStream& stream,
|
void DomainServerExporter::generateMetricsFromJson(QTextStream& stream,
|
||||||
QString original_path,
|
QString originalPath,
|
||||||
QString path,
|
QString path,
|
||||||
QHash<QString, QString> labels,
|
QHash<QString, QString> labels,
|
||||||
const QJsonObject& obj) {
|
const QJsonObject& root) {
|
||||||
for (auto iter = obj.constBegin(); iter != obj.constEnd(); ++iter) {
|
for (auto iter = root.constBegin(); iter != root.constEnd(); ++iter) {
|
||||||
auto escaped_key = escapeName(iter.key());
|
auto escapedKey = escapeName(iter.key());
|
||||||
auto metric_value = iter.value();
|
auto metricValue = iter.value();
|
||||||
auto metric_name = path + "_" + escaped_key;
|
auto metricName = path + "_" + escapedKey;
|
||||||
auto orig_metric_name = original_path + " -> " + iter.key();
|
auto origMetricName = originalPath + " -> " + iter.key();
|
||||||
|
|
||||||
if (metric_value.isObject()) {
|
if (metricValue.isObject()) {
|
||||||
QUuid possible_uuid = QUuid::fromString(iter.key());
|
QUuid possible_uuid = QUuid::fromString(iter.key());
|
||||||
|
|
||||||
if (possible_uuid.isNull()) {
|
if (possible_uuid.isNull()) {
|
||||||
generateMetricsFromJson(stream, original_path + " -> " + iter.key(), path + "_" + escaped_key, labels,
|
generateMetricsFromJson(stream, originalPath + " -> " + iter.key(), path + "_" + escapedKey, labels,
|
||||||
iter.value().toObject());
|
iter.value().toObject());
|
||||||
} else {
|
} else {
|
||||||
labels.insert("uuid", possible_uuid.toString(QUuid::WithoutBraces));
|
labels.insert("uuid", possible_uuid.toString(QUuid::WithoutBraces));
|
||||||
generateMetricsFromJson(stream, original_path, path, labels, iter.value().toObject());
|
generateMetricsFromJson(stream, originalPath, path, labels, iter.value().toObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BLACKLIST.contains(metric_name)) {
|
if (BLACKLIST.contains(metricName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool conversion_ok = false;
|
bool conversionOk = false;
|
||||||
double converted = 0;
|
double converted = 0;
|
||||||
|
|
||||||
if (metric_value.isString()) {
|
if (metricValue.isString()) {
|
||||||
// Prometheus only deals with numeric values. See if this string contains a valid one
|
// Prometheus only deals with numeric values. See if this string contains a valid one
|
||||||
|
|
||||||
QString tmp = metric_value.toString();
|
QString tmp = metricValue.toString();
|
||||||
converted = tmp.toDouble(&conversion_ok);
|
converted = tmp.toDouble(&conversionOk);
|
||||||
|
|
||||||
if (!conversion_ok) {
|
if (!conversionOk) {
|
||||||
qCWarning(domain_server_exporter) << "Failed to convert value of " << orig_metric_name << " (" << metric_name
|
qCWarning(domain_server_exporter) << "Failed to convert value of " << origMetricName << " (" << metricName
|
||||||
<< ") to double: " << tmp << "'";
|
<< ") to double: " << tmp << "'";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << QString("\n# HELP %1 %2 -> %3\n").arg(metric_name).arg(original_path).arg(iter.key());
|
stream << QString("\n# HELP %1 %2 -> %3\n").arg(metricName).arg(originalPath).arg(iter.key());
|
||||||
|
|
||||||
if (TYPE_MAP.contains(metric_name)) {
|
if (TYPE_MAP.contains(metricName)) {
|
||||||
stream << "# TYPE " << metric_name << " ";
|
stream << "# TYPE " << metricName << " ";
|
||||||
switch (TYPE_MAP[metric_name]) {
|
switch (TYPE_MAP[metricName]) {
|
||||||
case DomainServerExporter::MetricType::Untyped:
|
case DomainServerExporter::MetricType::Untyped:
|
||||||
stream << "untyped";
|
stream << "untyped";
|
||||||
break;
|
break;
|
||||||
|
@ -410,47 +410,47 @@ void DomainServerExporter::generateMetricsFromJson(QTextStream& stream,
|
||||||
stream << "\n";
|
stream << "\n";
|
||||||
} else {
|
} else {
|
||||||
qCWarning(domain_server_exporter)
|
qCWarning(domain_server_exporter)
|
||||||
<< "Type for metric " << orig_metric_name << " (" << metric_name << ") not known.";
|
<< "Type for metric " << origMetricName << " (" << metricName << ") not known.";
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << path << "_" << escaped_key;
|
stream << path << "_" << escapedKey;
|
||||||
if (!labels.isEmpty()) {
|
if (!labels.isEmpty()) {
|
||||||
stream << "{";
|
stream << "{";
|
||||||
|
|
||||||
bool is_first = true;
|
bool isFirst = true;
|
||||||
QHashIterator<QString, QString> iter(labels);
|
QHashIterator<QString, QString> iter(labels);
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
iter.next();
|
iter.next();
|
||||||
|
|
||||||
if (!is_first) {
|
if (!isFirst) {
|
||||||
stream << ",";
|
stream << ",";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString escaped_value = iter.value();
|
QString escapedValue = iter.value();
|
||||||
escaped_value.replace("\\", "\\\\");
|
escapedValue.replace("\\", "\\\\");
|
||||||
escaped_value.replace("\"", "\\\"");
|
escapedValue.replace("\"", "\\\"");
|
||||||
escaped_value.replace("\n", "\\\n");
|
escapedValue.replace("\n", "\\\n");
|
||||||
|
|
||||||
stream << iter.key() << "=\"" << escaped_value << "\"";
|
stream << iter.key() << "=\"" << escapedValue << "\"";
|
||||||
|
|
||||||
is_first = false;
|
isFirst = false;
|
||||||
}
|
}
|
||||||
stream << "}";
|
stream << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << " ";
|
stream << " ";
|
||||||
|
|
||||||
if (metric_value.isBool()) {
|
if (metricValue.isBool()) {
|
||||||
stream << (iter.value().toBool() ? "1" : "0");
|
stream << (iter.value().toBool() ? "1" : "0");
|
||||||
} else if (metric_value.isDouble()) {
|
} else if (metricValue.isDouble()) {
|
||||||
stream << metric_value.toDouble();
|
stream << metricValue.toDouble();
|
||||||
} else if (metric_value.isString()) {
|
} else if (metricValue.isString()) {
|
||||||
// Converted above
|
// Converted above
|
||||||
stream << converted;
|
stream << converted;
|
||||||
} else {
|
} else {
|
||||||
qCWarning(domain_server_exporter)
|
qCWarning(domain_server_exporter)
|
||||||
<< "Can't convert metric " << orig_metric_name << "(" << metric_name << ") with value " << metric_value;
|
<< "Can't convert metric " << origMetricName << "(" << metricName << ") with value " << metricValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << "\n";
|
stream << "\n";
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString escapeName(const QString &name);
|
QString escapeName(const QString &name);
|
||||||
void generateMetricsForNode( QTextStream &stream, const SharedNodePointer &node );
|
void generateMetricsForNode(QTextStream &stream, const SharedNodePointer &node);
|
||||||
void generateMetricsFromJson(QTextStream &stream, QString original_path, QString path, QHash<QString,QString> labels, const QJsonObject &obj);
|
void generateMetricsFromJson(QTextStream &stream, QString original_path, QString path, QHash<QString,QString> labels, const QJsonObject &obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue