Hello. I am using Grafana v10.0.0 and am trying to make a time series to graph hosts and their CPU usage. But I think Grafana is combining the results of the two hosts I’m querying for into a single line, instead of creating two lines for two hosts.
Here is my SQLite data source. “timestamp” is a unix epoch integer (e.g.1710210340)
CREATE TABLE stats (
hostname TEXT NOT NULL,
timestamp INTEGER NOT NULL,
kbytes_received INTEGER NOT NULL,
kbytes_sent INTEGER NOT NULL,
nessus_cpu INTEGER NOT NULL,
cpu_load_avg INTEGER NOT NULL,
num_tcp_sessions INTEGER NOT NULL,
nessus_vmem INTEGER NOT NULL,
nessus_mem INTEGER NOT NULL,
sys_cores INTEGER NOT NULL,
num_hosts INTEGER NOT NULL,
num_scans INTEGER NOT NULL,
PRIMARY KEY (hostname, timestamp)
);
CREATE INDEX "hostname_idx" ON "stats" (
"hostname"
);
and some sample data:
INSERT INTO stats VALUES('myhost1',1710210940,0,0,0,0,0,16511,6643,16,0,0);
INSERT INTO stats VALUES('myhost1',1710210970,0,0,0,0,0,16511,6643,16,0,0);
INSERT INTO stats VALUES('myhost1',1710211000,1,0,0,0,0,16511,6643,16,0,0);
INSERT INTO stats VALUES('myhost2',1708545833,39,21,1,0,29,30135,7683,16,6,2);
INSERT INTO stats VALUES('myhost2',1708545863,19,14,1,0,30,30135,7684,16,6,2);
INSERT INTO stats VALUES('myhost2',1708545893,7,8,1,0,29,30135,7683,16,6,2);
...
The table holds about 3.5 million records, with about 71 distinct hostnames.
My query is: SELECT hostname as metric, timestamp, cpu_load_avg as value FROM stats WHERE hostname='myhost1' OR hostname='myhost2' ORDER BY timestamp
The result looks like this:
This appears to be either the CPU usage one of my two hosts (I’m not sure which), or both hosts plotted together on the same line (which I think is more likely). Flipping the switch to get “Table view” shows this, where there is no value listed for “metric”.
How can I get a graph that will allow me to plot 2, or 5, or 10 hosts on the same graph, but each with its own line and color?
Thanks to anyone who can help!