@grafana/data APIs
- SelectableValue
- DataQuery
- DataSourceJsonData
- PanelProps
- PanelPlugin
- DataFrame
- DataSourcePluginOptionsEditorProps
- DataSourceInstanceSettings
- FieldType
- DataSourcePlugin
- DataSourceApi
- MetricFindValue
- PanelEditorProps
- GrafanaTheme
- getDisplayProcessor
- DataQueryError
- DataQueryRequest
- DataQueryResponse
- MutableDataFrame
- ArrayVector
- LoadingState
- KeyValue
- AppPluginMeta
- PluginMeta
- AppPlugin
- NavModelItem
- ThresholdsMode
- DisplayValue
- formattedValueToString
- FieldConfig
- FieldColorMode
- GraphSeriesValue
- FieldDisplayOptions
- GraphSeriesXY
- TimeZone
- MS_DATE_TIME_FORMAT
- DEFAULT_DATE_TIME_FORMAT
- ReducerID
- AppEvents
- DataSourceSelectItem
- NullValueMode
- getFlotPairs
- getValueFormat
- AbsoluteTimeRange
- AnnotationEvent
- PanelData
- getTimeField
- reduceField
- getSeriesTimeStep
- hasMsResolution
- FieldColor
- MutableField
- AppRootProps
- GrafanaThemeType
- PanelPluginMeta
- ScopedVars
- PluginBuildInfo
- PluginState
- VizOrientation
- Field
- TimeSeriesValue
- FormattedValue
- DisplayValueAlignmentFactors
- getColorFromHexRgbOrName
- getColorDefinitionByName
- getNamedColorPalette
- getColorName
- getColorForTheme
- deprecationWarning
- DataLink
- VariableSuggestion
- VariableOrigin
- LinkModelSupplier
- DataSourceSettings
- applyFieldOverrides
- FieldConfigSource
- InterpolateFunction
- FieldMatcherID
- toDataFrame
- standardFieldConfigEditorRegistry
- FieldOverrideContext
- FieldConfigEditorProps
- FieldOverrideEditorProps
- ValueMapping
- toIntegerOrUndefined
- toFloatOrUndefined
- FieldPropertyEditorItem
- ThresholdsConfig
- getActiveThreshold
- Threshold
- dateTime
- TimeRange
- DefaultTimeZone
- createDimension
- DateTimeInput
- FlotDataPoint
- getValueFromDimension
- getColumnFromDimension
- FieldCache
- LogRowModel
- LogLevel
- calculateFieldStats
- calculateLogsLabelStats
- calculateStats
- getParser
- LinkModel
- Labels
- findHighlightChunksInText
- LogsDedupStrategy
- fieldMatchers
- Registry
- stringToMs
- DEFAULT_FIELD_DISPLAY_VALUES_LIMIT
- toNumberString
- VAR_SERIES_NAME
- VAR_FIELD_NAME
- VAR_CALC
- VAR_CELL_PREFIX
- fieldReducers
- sortThresholds
- MappingType
- PanelModel
- ConfigOverrideRule
- validateFieldConfig
- readCSV
- DateTime
- dateTimeAsMoment
- TimeFragment
- isDateTime
- rangeUtil
- TIME_FORMAT
- TimeOption
- dateMath
- dateTimeForTimeZone
- getTimeZoneGroups
- RawTimeRange
- FilterFieldsByNameTransformerOptions
- DataTransformerID
- transformersRegistry
- FilterFramesByRefIdTransformerOptions
- ReduceTransformerOptions
- DataTransformerConfig
- transformDataFrame
- getValueFormats
- GrafanaThemeCommons
- setLocale
- setMarkdownOptions
- escapeStringForRegex
- unEscapeStringFromRegex
- UserOrgDTO
- NavModel
- NavModelBreadcrumb
- renderMarkdown
- LogsMetaKind
- findCommonLabels
- findUniqueLabels
- getLogLevel
- getLogLevelFromKey
- LogsModel
- LogsMetaItem
- toUtc
- FieldWithIndex
- NavIndex
- PanelEvents
- OrgRole
- eventFactory
- TableData
- Column
- ValueFormatter
- stringToJsRegex
- DecimalCount
- AppEvent
- ExploreMode
- CoreApp
- HistoryItem
- IntervalValues
- toCSV
- DynamicConfigValue
- FieldConfigEditorRegistry
- VariableSuggestionsScope
- DefaultTimeRange
- toDataFrameDTO
- PanelMenuItem
- PluginType
- toLegacyResponseData
- DataQueryResponseData
- guessFieldTypes
- DataSourcePluginMeta
- DataSourceConstructor
- PluginInclude
- PluginMetaInfo
- toDuration
- LogsDedupDescription
- QueryFixAction
- TimeSeries
- LegacyResponseData
- AngularPanelMenuItem
- FieldDisplay
- DataFrameView
- GrafanaPlugin
- PluginDependencies
- PluginIncludeType
- onUpdateDatasourceJsonDataOptionSelect
- onUpdateDatasourceOption
- onUpdateDatasourceResetOption
- onUpdateDatasourceJsonDataOption
- onUpdateDatasourceSecureJsonDataOption
- updateDatasourcePluginOption
- updateDatasourcePluginResetOption
- updateDatasourcePluginJsonDataOption
- updateDatasourcePluginSecureJsonDataOption
- ExploreStartPageProps
- DataFrameDTO
- AnnotationQueryRequest
- LanguageProvider
- formatLabels
- parseLabels
- CircularDataFrame
- QueryHint
- isDataFrame
- QueryFix
- CSVReader
- DurationUnit
- getFieldDisplayValues
- getDisplayValueAlignmentFactors
- getFlotPairsConstant
- CreatePlotOverlay
- isTableData
- stringStartsAsRegEx
- base64StringToArrowTable
- arrowTableToDataFrame
- FieldConfigProperty
Other Related APIs
- @grafana/data#FieldType
- @grafana/data#DataFrame
- @grafana/data#toDataFrame
- @grafana/data#dateTime
- @grafana/data#GraphSeriesXY
- @grafana/data#TimeZone
- @grafana/data#FieldCache
- @grafana/data#LogRowModel
- @grafana/data#LogLevel
- @grafana/data#Labels
- @grafana/data#LogsDedupStrategy
- @grafana/data#LogsMetaKind
- @grafana/data#findCommonLabels
- @grafana/data#findUniqueLabels
- @grafana/data#getLogLevelFromKey
- @grafana/data#LogsModel
- @grafana/data#LogsMetaItem
- @grafana/data#toUtc
- @grafana/data#NullValueMode
- @grafana/data#FieldWithIndex
- @grafana/data#getFlotPairs
@grafana/data#getLogLevel TypeScript Examples
The following examples show how to use
@grafana/data#getLogLevel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: logs_model.ts From grafana-chinese with Apache License 2.0 | 4 votes |
/**
* Converts dataFrames into LogsModel. This involves merging them into one list, sorting them and computing metadata
* like common labels.
*/
export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefined {
if (logSeries.length === 0) {
return undefined;
}
const allLabels: Labels[] = [];
// Find the fields we care about and collect all labels
const allSeries: LogFields[] = logSeries.map(series => {
const fieldCache = new FieldCache(series);
// Assume the first string field in the dataFrame is the message. This was right so far but probably needs some
// more explicit checks.
const stringField = fieldCache.getFirstFieldOfType(FieldType.string);
if (stringField.labels) {
allLabels.push(stringField.labels);
}
return {
series,
timeField: fieldCache.getFirstFieldOfType(FieldType.time),
stringField,
logLevelField: fieldCache.getFieldByName('level'),
idField: getIdField(fieldCache),
};
});
const commonLabels = allLabels.length > 0 ? findCommonLabels(allLabels) : {};
const rows: LogRowModel[] = [];
let hasUniqueLabels = false;
for (const info of allSeries) {
const { timeField, stringField, logLevelField, idField, series } = info;
const labels = stringField.labels;
const uniqueLabels = findUniqueLabels(labels, commonLabels);
if (Object.keys(uniqueLabels).length > 0) {
hasUniqueLabels = true;
}
let seriesLogLevel: LogLevel | undefined = undefined;
if (labels && Object.keys(labels).indexOf('level') !== -1) {
seriesLogLevel = getLogLevelFromKey(labels['level']);
}
for (let j = 0; j < series.length; j++) {
const ts = timeField.values.get(j);
const time = dateTime(ts);
const messageValue: unknown = stringField.values.get(j);
// This should be string but sometimes isn't (eg elastic) because the dataFrame is not strongly typed.
const message: string = typeof messageValue === 'string' ? messageValue : JSON.stringify(messageValue);
const hasAnsi = hasAnsiCodes(message);
const searchWords = series.meta && series.meta.searchWords ? series.meta.searchWords : [];
let logLevel = LogLevel.unknown;
if (logLevelField && logLevelField.values.get(j)) {
logLevel = getLogLevelFromKey(logLevelField.values.get(j));
} else if (seriesLogLevel) {
logLevel = seriesLogLevel;
} else {
logLevel = getLogLevel(message);
}
rows.push({
entryFieldIndex: stringField.index,
rowIndex: j,
dataFrame: series,
logLevel,
timeFromNow: time.fromNow(),
timeEpochMs: time.valueOf(),
timeLocal: time.format(logTimeFormat),
timeUtc: toUtc(time.valueOf()).format(logTimeFormat),
uniqueLabels,
hasAnsi,
searchWords,
entry: hasAnsi ? ansicolor.strip(message) : message,
raw: message,
labels: stringField.labels,
uid: idField ? idField.values.get(j) : j.toString(),
});
}
}
const deduplicatedLogRows = deduplicateLogRowsById(rows);
// Meta data to display in status
const meta: LogsMetaItem[] = [];
if (_.size(commonLabels) > 0) {
meta.push({
label: 'Common labels',
value: commonLabels,
kind: LogsMetaKind.LabelsMap,
});
}
const limits = logSeries.filter(series => series.meta && series.meta.limit);
const limitValue = Object.values(
limits.reduce((acc: any, elem: any) => {
acc[elem.refId] = elem.meta.limit;
return acc;
}, {})
).reduce((acc: number, elem: any) => (acc += elem), 0);
if (limits.length > 0) {
meta.push({
label: 'Limit',
value: `${limitValue} (${deduplicatedLogRows.length} returned)`,
kind: LogsMetaKind.String,
});
}
return {
hasUniqueLabels,
meta,
rows: deduplicatedLogRows,
};
}