# flattenObject

Canonical: https://docs.shumoku.dev/ja/library/api/flattenObject
Language: ja

@shumoku/core · 0.4.0 · function

# flattenObject

[ソース](https://github.com/konoe-akitoshi/shumoku/blob/main/libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts#L24)

APIの説明は英語のcanonical sourceを表示しています。

Flatten an arbitrary upstream record into \`DiscoveredMetric\[\]\` for the plugin "All metrics" passthrough panel. This is the generic dumper every \`HostsCapable\` plugin should use instead of hand-enumerating fields (which is how zabbix ended up coercing every value to a number and dropping categorical attributes). Walk the object: - object children join into the metric name with \`\_\` (\`{ a: { b: 1 } }\` with prefix \`p\` → \`p\_a\_b\`), - array-of-primitives emits a \`<name>\_count\`, - array-of-objects emits a \`<name>\_count\` then expands each element with a \`<key>\_index\` label, - null / undefined / empty-string / non-finite leaves are skipped as noise. Lifted verbatim (behavior-preserving) from the aruba-instant-on plugin, which had the only correct generic implementation.

```
flattenObject(obj: unknown, prefix: string, labels?: Record<string, string>): DiscoveredMetric[]
```

## パラメーター

| 名前 | 型 | 説明 | 既定値 |
| --- | --- | --- | --- |
| `obj` | `unknown` | 追加説明はありません。 | `—` |
| `prefix` | `string` | 追加説明はありません。 | `—` |
| `labels` | `Record<string, string>` | 追加説明はありません。 | `{}` |

## 戻り値

```
DiscoveredMetric[]
```

[`libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts:24`](https://github.com/konoe-akitoshi/shumoku/blob/main/libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts#L24)
